Files
hldrCenter/server/internal/course_activity/handler/course_activity/deletecourseactivityhandler.go
2025-11-01 23:51:51 +08:00

50 lines
1.4 KiB
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_activity
import (
"fmt"
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/config"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_activity/internal/logic/course_activity"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_activity/internal/model"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_activity/internal/types"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/rest/httpx"
)
func DeleteCourseActivityHandler(cfg *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteCourseActivityReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
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)
ActivityModel := model.NewCourseActivityModel(conn)
l := course_activity.NewDeleteCourseActivityLogic(r.Context(), cfg, ActivityModel)
resp, err := l.DeleteCourseActivity(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}