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.
This commit is contained in:
parent
4733677334
commit
4c427672a3
@ -1,16 +1,19 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CancelPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CancelPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := order.NewCancelPurchaseOrderLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := order.NewCancelPurchaseOrderLogic(ctx, svcCtx)
|
||||||
err := l.CancelPurchaseOrder()
|
err := l.CancelPurchaseOrder()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfirmPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func ConfirmPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := order.NewConfirmPurchaseOrderLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := order.NewConfirmPurchaseOrderLogic(ctx, svcCtx)
|
||||||
err := l.ConfirmPurchaseOrder()
|
err := l.ConfirmPurchaseOrder()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetPurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := order.NewGetPurchaseOrderLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := order.NewGetPurchaseOrderLogic(ctx, svcCtx)
|
||||||
resp, err := l.GetPurchaseOrder()
|
resp, err := l.GetPurchaseOrder()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
"muyu-apiserver/gateway/internal/logic/purchase/order"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
"muyu-apiserver/gateway/internal/types"
|
"muyu-apiserver/gateway/internal/types"
|
||||||
@ -17,7 +19,8 @@ func UpdatePurchaseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewUpdatePurchaseOrderLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := order.NewUpdatePurchaseOrderLogic(ctx, svcCtx)
|
||||||
err := l.UpdatePurchaseOrder(&req)
|
err := l.UpdatePurchaseOrder(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package receipt
|
package receipt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/receipt"
|
"muyu-apiserver/gateway/internal/logic/purchase/receipt"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfirmPurchaseReceiptHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func ConfirmPurchaseReceiptHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := receipt.NewConfirmPurchaseReceiptLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := receipt.NewConfirmPurchaseReceiptLogic(ctx, svcCtx)
|
||||||
err := l.ConfirmPurchaseReceipt()
|
err := l.ConfirmPurchaseReceipt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package receipt
|
package receipt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||||
"muyu-apiserver/gateway/internal/logic/purchase/receipt"
|
"muyu-apiserver/gateway/internal/logic/purchase/receipt"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPurchaseReceiptHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetPurchaseReceiptHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := receipt.NewGetPurchaseReceiptLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := receipt.NewGetPurchaseReceiptLogic(ctx, svcCtx)
|
||||||
resp, err := l.GetPurchaseReceipt()
|
resp, err := l.GetPurchaseReceipt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package supplier
|
package supplier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/purchase/supplier"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DeleteSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := supplier.NewDeleteSupplierLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := supplier.NewDeleteSupplierLogic(ctx, svcCtx)
|
||||||
err := l.DeleteSupplier()
|
err := l.DeleteSupplier()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package supplier
|
package supplier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/purchase/supplier"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := supplier.NewGetSupplierLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := supplier.NewGetSupplierLogic(ctx, svcCtx)
|
||||||
resp, err := l.GetSupplier()
|
resp, err := l.GetSupplier()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package supplier
|
package supplier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/purchase/supplier"
|
||||||
"muyu-apiserver/gateway/internal/svc"
|
"muyu-apiserver/gateway/internal/svc"
|
||||||
"muyu-apiserver/gateway/internal/types"
|
"muyu-apiserver/gateway/internal/types"
|
||||||
@ -17,7 +19,8 @@ func UpdateSupplierHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := supplier.NewUpdateSupplierLogic(r.Context(), svcCtx)
|
ctx := context.WithValue(r.Context(), "pathId", pathvar.Vars(r)["id"])
|
||||||
|
l := supplier.NewUpdateSupplierLogic(ctx, svcCtx)
|
||||||
err := l.UpdateSupplier(&req)
|
err := l.UpdateSupplier(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user