62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
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"
|
|
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/model"
|
|
"github.com/JACKYMYPERSON/hldrCenter/internal/video_case/internal/types"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
)
|
|
|
|
func GetVideoCaseHandler(cfg *config.Config) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req types.GetVideoCaseReq
|
|
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(
|
|
"%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=true&loc=Local",
|
|
mysqlCfg.Username,
|
|
mysqlCfg.Password,
|
|
mysqlCfg.Host,
|
|
mysqlCfg.Port,
|
|
mysqlCfg.Database,
|
|
mysqlCfg.Charset,
|
|
)
|
|
fmt.Println("接收到articlePost请求")
|
|
|
|
conn := sqlx.NewSqlConn("mysql", dsn)
|
|
|
|
video_caseModel := model.NewVideoCaseModel(conn)
|
|
|
|
l := video_case.NewGetVideoCaseLogic(r.Context(), cfg, video_caseModel)
|
|
resp, err := l.GetVideoCase(&req)
|
|
if err != nil {
|
|
httpx.ErrorCtx(r.Context(), w, err)
|
|
} else {
|
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
}
|
|
}
|
|
}
|