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

115 lines
2.5 KiB
Go

package handler
import (
"log"
"github.com/gin-gonic/gin"
"github.com/muyuqingfeng/iloom/shared/pkg/response"
"github.com/muyuqingfeng/iloom/washing-service/internal/service"
)
type PlanHandler struct {
svc *service.PlanService
}
func NewPlanHandler(svc *service.PlanService) *PlanHandler {
return &PlanHandler{svc: svc}
}
func (h *PlanHandler) List(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
plans, err := h.svc.List(c.Request.Context(), companyID)
if err != nil {
log.Printf("list washing plans error: %v", err)
response.InternalError(c, "failed to list washing plans")
return
}
response.OK(c, plans)
}
func (h *PlanHandler) Get(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
id := c.Param("id")
plan, err := h.svc.GetByID(c.Request.Context(), id, companyID)
if err != nil {
log.Printf("get washing plan error: %v", err)
response.NotFound(c, "washing plan not found")
return
}
response.OK(c, plan)
}
type UpdateStatusReq struct {
Status string `json:"status" binding:"required"`
}
func (h *PlanHandler) UpdateStatus(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
id := c.Param("id")
var req UpdateStatusReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, err.Error())
return
}
if err := h.svc.UpdateStatus(c.Request.Context(), id, companyID, req.Status); err != nil {
log.Printf("update washing plan status error: %v", err)
response.InternalError(c, "failed to update status")
return
}
response.OK(c, nil)
}
func (h *PlanHandler) Pending(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
plans, err := h.svc.Pending(c.Request.Context(), companyID)
if err != nil {
log.Printf("list pending plans error: %v", err)
response.InternalError(c, "failed to list pending plans")
return
}
response.OK(c, plans)
}
func (h *PlanHandler) Completed(c *gin.Context) {
companyID := c.GetHeader("X-Company-ID")
if companyID == "" {
response.BadRequest(c, "missing company id")
return
}
plans, err := h.svc.Completed(c.Request.Context(), companyID)
if err != nil {
log.Printf("list completed plans error: %v", err)
response.InternalError(c, "failed to list completed plans")
return
}
response.OK(c, plans)
}