diff --git a/server/internal/teaching_case/handler/teaching_case/deleteteachingcasehandler.go b/server/internal/teaching_case/handler/teaching_case/deleteteachingcasehandler.go index adec2d59..e9fd9afc 100644 --- a/server/internal/teaching_case/handler/teaching_case/deleteteachingcasehandler.go +++ b/server/internal/teaching_case/handler/teaching_case/deleteteachingcasehandler.go @@ -6,6 +6,8 @@ package teaching_case import ( "fmt" "net/http" + "strconv" + "strings" "github.com/JACKYMYPERSON/hldrCenter/config" "github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case" @@ -18,10 +20,19 @@ import ( func DeleteTeachingCaseHandler(cfg *config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.DeleteTeachingCaseReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + pathParts := strings.Split(r.URL.Path, "/") + if len(pathParts) < 3 { // 确保路径格式正确 + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format")) return } + idStr := pathParts[3] + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID")) + return + } + fmt.Println("idStr:", idStr) + req.Id = int(id) mysqlCfg := cfg.MySQL dsn := fmt.Sprintf( diff --git a/server/internal/teaching_case/handler/teaching_case/getteachingcasehandler.go b/server/internal/teaching_case/handler/teaching_case/getteachingcasehandler.go index f81b4fe5..a3759dd7 100644 --- a/server/internal/teaching_case/handler/teaching_case/getteachingcasehandler.go +++ b/server/internal/teaching_case/handler/teaching_case/getteachingcasehandler.go @@ -6,6 +6,8 @@ package teaching_case import ( "fmt" "net/http" + "strconv" + "strings" "github.com/JACKYMYPERSON/hldrCenter/config" "github.com/JACKYMYPERSON/hldrCenter/internal/teaching_case/internal/logic/teaching_case" @@ -18,10 +20,19 @@ import ( func GetTeachingCaseHandler(cfg *config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetTeachingCaseReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + pathParts := strings.Split(r.URL.Path, "/") + if len(pathParts) < 3 { // 确保路径格式正确 + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format")) return } + idStr := pathParts[3] + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID")) + return + } + fmt.Println("idStr:", idStr) + req.Id = int(id) mysqlCfg := cfg.MySQL dsn := fmt.Sprintf( diff --git a/server/internal/teaching_case/internal/logic/teaching_case/updateteachingcaselogic.go b/server/internal/teaching_case/internal/logic/teaching_case/updateteachingcaselogic.go index 09329bb4..bfbabe82 100644 --- a/server/internal/teaching_case/internal/logic/teaching_case/updateteachingcaselogic.go +++ b/server/internal/teaching_case/internal/logic/teaching_case/updateteachingcaselogic.go @@ -24,6 +24,7 @@ type UpdateTeachingCaseLogic struct { func NewUpdateTeachingCaseLogic(ctx context.Context, cfg *config.Config, model model.TeachingCaseModel) *UpdateTeachingCaseLogic { return &UpdateTeachingCaseLogic{ Logger: logx.WithContext(ctx), + ctx: ctx, cfg: cfg, model: model, } diff --git a/server/internal/teaching_case/internal/types/types.go b/server/internal/teaching_case/internal/types/types.go index 1ab4e61c..7f574b77 100644 --- a/server/internal/teaching_case/internal/types/types.go +++ b/server/internal/teaching_case/internal/types/types.go @@ -23,7 +23,7 @@ type DeleteTeachingCaseReq struct { } type GetTeachingCaseReq struct { - Id int `json:"id" validate:"required" uri:"id"` // 案例ID + Id int `json:"id" path:"id" validate:"required" uri:"id"` // 案例ID } type ListTeachingCaseReq struct { diff --git a/server/internal/video_case/handler/video_case/deletevideocasehandler.go b/server/internal/video_case/handler/video_case/deletevideocasehandler.go index 8bc8a3dd..f020f0da 100644 --- a/server/internal/video_case/handler/video_case/deletevideocasehandler.go +++ b/server/internal/video_case/handler/video_case/deletevideocasehandler.go @@ -6,6 +6,8 @@ package video_case import ( "fmt" "net/http" + "strconv" + "strings" "github.com/JACKYMYPERSON/hldrCenter/config" "github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case" @@ -18,10 +20,19 @@ import ( func DeleteVideoCaseHandler(cfg *config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.DeleteVideoCaseReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + pathParts := strings.Split(r.URL.Path, "/") + if len(pathParts) < 3 { // 确保路径格式正确 + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format")) return } + idStr := pathParts[3] + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID")) + return + } + fmt.Println("idStr:", idStr) + req.Id = int(id) mysqlCfg := cfg.MySQL dsn := fmt.Sprintf( diff --git a/server/internal/video_case/handler/video_case/getvideocasehandler.go b/server/internal/video_case/handler/video_case/getvideocasehandler.go index 79d4609f..d9bdf21d 100644 --- a/server/internal/video_case/handler/video_case/getvideocasehandler.go +++ b/server/internal/video_case/handler/video_case/getvideocasehandler.go @@ -6,6 +6,8 @@ package video_case import ( "fmt" "net/http" + "strconv" + "strings" "github.com/JACKYMYPERSON/hldrCenter/config" "github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/logic/video_case" @@ -18,10 +20,19 @@ import ( func GetVideoCaseHandler(cfg *config.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetVideoCaseReq - if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + pathParts := strings.Split(r.URL.Path, "/") + if len(pathParts) < 3 { // 确保路径格式正确 + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format")) return } + idStr := pathParts[3] + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid meeting ID")) + return + } + fmt.Println("idStr:", idStr) + req.Id = int(id) mysqlCfg := cfg.MySQL dsn := fmt.Sprintf(