61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package socialServiceGovernmentProgram
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"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"
|
|
)
|
|
|
|
func DeleteSocialServiceGovernmentProgramHandler(cfg *config.Config) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req types.DeleteSocialServiceGovernmentProgramReq
|
|
pathParts := strings.Split(r.URL.Path, "/")
|
|
if len(pathParts) < 4 { // 确保路径格式正确
|
|
httpx.ErrorCtx(r.Context(), w, fmt.Errorf("invalid path format"))
|
|
return
|
|
}
|
|
idStr := pathParts[4]
|
|
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 = 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)
|
|
|
|
socialGovernmentProgramModel := model.NewSocialServiceGovernmentprogramModel(conn)
|
|
|
|
l := socialServiceGovernmentProgram.NewDeleteSocialServiceGovernmentProgramLogic(r.Context(), cfg, socialGovernmentProgramModel)
|
|
resp, err := l.DeleteSocialServiceGovernmentProgram(&req)
|
|
if err != nil {
|
|
httpx.ErrorCtx(r.Context(), w, err)
|
|
} else {
|
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
}
|
|
}
|
|
}
|