完成教学案例和视频案例后端

This commit is contained in:
2025-10-31 15:46:08 +08:00
parent 261ae0da58
commit fc97cf65d5
6 changed files with 54 additions and 9 deletions

View File

@@ -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(

View File

@@ -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(

View File

@@ -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,
}

View File

@@ -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 {