iloom/purchaser-service/internal/handler/accounts_payable.go
Chever John 9c39c8cbd7
init: iloom WMS monorepo with K8s deployment manifests
Go workspace (go.work) with 5 microservices + shared library:
- gateway (8080), auth-service (8081), purchaser-service (8082)
- textile-service (8083), washing-service (8084)
- shared: proto definitions, common packages

Infrastructure: docker-compose for local dev, K8s manifests for
K3s cluster deployment (mysql/redis/etcd + traefik ingress).

Frontend (iloom-flatten) added as git submodule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 11:33:31 +08:00

63 lines
1.3 KiB
Go

package handler
import (
"log"
"github.com/gin-gonic/gin"
"github.com/muyuqingfeng/iloom/purchaser-service/internal/service"
"github.com/muyuqingfeng/iloom/shared/pkg/response"
)
type APHandler struct {
svc *service.APService
}
func NewAPHandler(svc *service.APService) *APHandler {
return &APHandler{svc: svc}
}
type PayRequest struct {
Amount float64 `json:"amount" binding:"required,gt=0"`
}
func (h *APHandler) List(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
list, err := h.svc.List(c.Request.Context(), companyID)
if err != nil {
log.Printf("list accounts payable error: %v", err)
response.InternalError(c, "failed to list accounts payable")
return
}
response.OK(c, list)
}
func (h *APHandler) Pay(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
apID := c.Param("id")
var req PayRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, err.Error())
return
}
if err := h.svc.Pay(c.Request.Context(), apID, companyID, req.Amount); err != nil {
log.Printf("pay error: %v", err)
response.InternalError(c, "failed to process payment")
return
}
response.OK(c, nil)
}