kae 4c427672a3 fix: inject path param into context for all purchase handlers
Nine gateway handlers for purchase orders, receipts, and suppliers were
passing r.Context() directly to their logic constructors without first
extracting the URL path segment via pathvar.Vars(r)["id"]. This caused
ctxdata.GetPathId to always return an empty string, making GET/PUT/DELETE
operations on individual resources silently return "not found" even when
the record existed in the database.
2026-06-23 00:05:42 +08:00

25 lines
637 B
Go

package supplier
import (
"context"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"github.com/zeromicro/go-zero/rest/pathvar"
"muyu-apiserver/gateway/internal/logic/purchase/supplier"
"muyu-apiserver/gateway/internal/svc"
)
func GetSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
l := supplier.NewGetSupplierLogic(ctx, svcCtx)
resp, err := l.GetSupplier()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}