Files
hldrCenter/server/internal/social_service_governmentprogram/handler/socialServiceGovernmentProgram/createsocialservicegovernmentprogramhandler.go

50 lines
1.6 KiB
Go
Raw Normal View History

// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package socialServiceGovernmentProgram
import (
"fmt"
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/config"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service_governmentprogram/internal/logic/socialServiceGovernmentProgram"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service_governmentprogram/internal/model"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service_governmentprogram/internal/types"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/rest/httpx"
)
2025-10-30 10:05:35 +08:00
func CreateSocialServiceGovernmentProgramHandler(cfg *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateSocialServiceGovernmentProgramReq
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)
socialGovernmentProgramModel := model.NewSocialServiceGovernmentprogramModel(conn)
l := socialServiceGovernmentProgram.NewCreateSocialServiceGovernmentProgramLogic(r.Context(), cfg, socialGovernmentProgramModel)
resp, err := l.CreateSocialServiceGovernmentProgram(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}