完成课程文件handler
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/handler"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/admin-api.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
@@ -6,13 +6,13 @@ package admin
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/logic/admin"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func CreateAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func CreateAdminHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateAdminReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -6,13 +6,13 @@ package admin
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/logic/admin"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func DeleteAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func DeleteAdminHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeleteAdminReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -6,13 +6,13 @@ package admin
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/logic/admin"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func GetAdminHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetAdminReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -6,13 +6,13 @@ package admin
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/logic/admin"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func ListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func ListAdminHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ListAdminReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -6,13 +6,13 @@ package admin
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/logic/admin"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UpdateAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func UpdateAdminHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateAdminReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
||||
@@ -6,7 +6,8 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type CreateAdminLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.AdminModel
|
||||
}
|
||||
|
||||
func NewCreateAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAdminLogic {
|
||||
func NewCreateAdminLogic(ctx context.Context, cfg *config.Config, model model.AdminModel) *CreateAdminLogic {
|
||||
return &CreateAdminLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type DeleteAdminLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.AdminModel
|
||||
}
|
||||
|
||||
func NewDeleteAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAdminLogic {
|
||||
func NewDeleteAdminLogic(ctx context.Context, cfg *config.Config, model model.AdminModel) *DeleteAdminLogic {
|
||||
return &DeleteAdminLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type GetAdminLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.AdminModel
|
||||
}
|
||||
|
||||
func NewGetAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdminLogic {
|
||||
func NewGetAdminLogic(ctx context.Context, cfg *config.Config, model model.AdminModel) *GetAdminLogic {
|
||||
return &GetAdminLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type ListAdminLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.AdminModel
|
||||
}
|
||||
|
||||
func NewListAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAdminLogic {
|
||||
func NewListAdminLogic(ctx context.Context, cfg *config.Config, model model.AdminModel) *ListAdminLogic {
|
||||
return &ListAdminLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package admin
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type UpdateAdminLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.AdminModel
|
||||
}
|
||||
|
||||
func NewUpdateAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAdminLogic {
|
||||
func NewUpdateAdminLogic(ctx context.Context, cfg *config.Config, model model.AdminModel) *UpdateAdminLogic {
|
||||
return &UpdateAdminLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,85 +3,48 @@
|
||||
|
||||
package types
|
||||
|
||||
type AdminInfo struct {
|
||||
Id int64 `json:"id"` // 用户ID
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码(仅创建/更新时传递)
|
||||
CoverUrl string `json:"cover_url"` // 封面URL
|
||||
Intro string `json:"intro"` // 简介
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
Role string `json:"role"` // 角色(super_admin/normal_admin)
|
||||
Status int32 `json:"status"` // 1启用,0禁用
|
||||
type CreateCourseFileReq struct {
|
||||
ContentId int `json:"content_id" form:"content_id" validate:"required"` // 关联的内容ID(必填)
|
||||
Title string `json:"title" form:"title" validate:"required,max=255"` // 文件标题(必填,最长255字符)
|
||||
FileType string `json:"file_type" form:"file_type" validate:"required,max=30"` // 文件类型(必填,最长30字符)
|
||||
FileUrl string `json:"file_url" form:"file_url" validate:"required,max=255"` // 文件URL(必填,最长255字符)
|
||||
}
|
||||
|
||||
type BaseResp struct {
|
||||
Code int32 `json:"code"` // 0成功,非0失败
|
||||
Message string `json:"message"` // 提示信息
|
||||
type CreateCourseFileResp struct {
|
||||
Id int `json:"id"` // 新增文件的ID
|
||||
Message string `json:"message"` // 操作结果信息
|
||||
}
|
||||
|
||||
type CreateAdminData struct {
|
||||
Id int64 `json:"id"` // 新增的管理员ID
|
||||
type DeleteCourseFileReq struct {
|
||||
Id int `json:"id" form:"id" param:"id" validate:"required"` // 文件ID(必填,从路径参数获取)
|
||||
}
|
||||
|
||||
type CreateAdminReq struct {
|
||||
Username string `json:"username" form:"username"` // 用户名(必填)
|
||||
Password string `json:"password" form:"password"` // 密码(必填,需加密)
|
||||
CoverUrl string `json:"cover_url,optional" form:"cover_url"` // 封面URL(可选)
|
||||
Intro string `json:"intro,optional" form:"intro"` // 简介(可选)
|
||||
Role string `json:"role,optional" form:"role"` // 角色(默认normal_admin)
|
||||
Status int32 `json:"status,optional" form:"status"` // 状态(默认1)
|
||||
type DeleteCourseFileResp struct {
|
||||
Message string `json:"message"` // 操作结果信息
|
||||
}
|
||||
|
||||
type CreateAdminResp struct {
|
||||
BaseResp
|
||||
Data CreateAdminData `json:"data,optional"` // 业务数据(可选)
|
||||
type GetCourseFileReq struct {
|
||||
Id int `json:"id" form:"id" param:"id" validate:"required"` // 文件ID(必填,从路径参数获取)
|
||||
}
|
||||
|
||||
type DeleteAdminReq struct {
|
||||
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||
type GetCourseFileResp struct {
|
||||
Id int `json:"id"` // 文件ID
|
||||
ContentId int `json:"content_id"` // 关联的内容ID
|
||||
Title string `json:"title"` // 文件标题
|
||||
FileType string `json:"file_type"` // 文件类型
|
||||
FileUrl string `json:"file_url"` // 文件URL
|
||||
CreateTime string `json:"create_time"` // 创建时间(格式化字符串)
|
||||
UpdateTime string `json:"update_time"` // 更新时间(格式化字符串)
|
||||
}
|
||||
|
||||
type DeleteAdminResp struct {
|
||||
BaseResp
|
||||
type UpdateCourseFileReq struct {
|
||||
Id int `json:"id" form:"id" validate:"required"` // 文件ID(必填)
|
||||
ContentId int `json:"content_id" form:"content_id"` // 可选:更新关联的内容ID
|
||||
Title string `json:"title" form:"title" validate:"omitempty,max=255"` // 可选:更新标题
|
||||
FileType string `json:"file_type" form:"file_type" validate:"omitempty,max=30"` // 可选:更新文件类型
|
||||
FileUrl string `json:"file_url" form:"file_url" validate:"omitempty,max=255"` // 可选:更新文件URL
|
||||
}
|
||||
|
||||
type GetAdminReq struct {
|
||||
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||
}
|
||||
|
||||
type GetAdminResp struct {
|
||||
BaseResp
|
||||
Data AdminInfo `json:"data"` // 管理员详情数据
|
||||
}
|
||||
|
||||
type ListAdminData struct {
|
||||
Total int64 `json:"total"` // 总条数
|
||||
List []AdminInfo `json:"list"` // 管理员列表
|
||||
}
|
||||
|
||||
type ListAdminReq struct {
|
||||
Page int32 `json:"page,optional" form:"page"` // 页码,默认1
|
||||
Size int32 `json:"size,optional" form:"size"` // 每页条数,默认10
|
||||
Role string `json:"role,optional" form:"role"` // 按角色筛选
|
||||
Status int32 `json:"status,optional" form:"status"` // 按状态筛选
|
||||
}
|
||||
|
||||
type ListAdminResp struct {
|
||||
BaseResp
|
||||
Data ListAdminData `json:"data"` // 业务数据
|
||||
}
|
||||
|
||||
type UpdateAdminReq struct {
|
||||
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||
Username string `json:"username,optional" form:"username"` // 用户名(可选)
|
||||
Password string `json:"password,optional" form:"password"` // 密码(可选)
|
||||
CoverUrl string `json:"cover_url,optional" form:"cover_url"` // 封面URL(可选)
|
||||
Intro string `json:"intro,optional" form:"intro"` // 简介(可选)
|
||||
Role string `json:"role,optional" form:"role"` // 角色(可选)
|
||||
Status int32 `json:"status,optional" form:"status"` // 状态(可选)
|
||||
}
|
||||
|
||||
type UpdateAdminResp struct {
|
||||
BaseResp
|
||||
type UpdateCourseFileResp struct {
|
||||
Message string `json:"message"` // 操作结果信息
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
package course_content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/logic/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func AddContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func AddContentHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AddContentReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
@@ -20,7 +23,22 @@ func AddContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
l := course_content.NewAddContentLogic(r.Context(), svcCtx)
|
||||
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)
|
||||
ContentModel := model.NewCourseContentModel(conn)
|
||||
|
||||
l := course_content.NewAddContentLogic(r.Context(), cfg, ContentModel)
|
||||
resp, err := l.AddContent(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,23 +4,40 @@
|
||||
package course_content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/logic/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func DeleteContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func DeleteContentHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeleteContentReq
|
||||
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请求")
|
||||
|
||||
l := course_content.NewDeleteContentLogic(r.Context(), svcCtx)
|
||||
conn := sqlx.NewSqlConn("mysql", dsn)
|
||||
ContentModel := model.NewCourseContentModel(conn)
|
||||
|
||||
l := course_content.NewDeleteContentLogic(r.Context(), cfg, ContentModel)
|
||||
resp, err := l.DeleteContent(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
package course_content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/logic/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func GetContentHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetContentReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
@@ -20,7 +23,22 @@ func GetContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
l := course_content.NewGetContentLogic(r.Context(), svcCtx)
|
||||
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)
|
||||
ContentModel := model.NewCourseContentModel(conn)
|
||||
|
||||
l := course_content.NewGetContentLogic(r.Context(), cfg, ContentModel)
|
||||
resp, err := l.GetContent(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,23 +4,40 @@
|
||||
package course_content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/logic/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetContentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func GetContentListHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetContentListReq
|
||||
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请求")
|
||||
|
||||
l := course_content.NewGetContentListLogic(r.Context(), svcCtx)
|
||||
conn := sqlx.NewSqlConn("mysql", dsn)
|
||||
ContentModel := model.NewCourseContentModel(conn)
|
||||
|
||||
l := course_content.NewGetContentListLogic(r.Context(), cfg, ContentModel)
|
||||
resp, err := l.GetContentList(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
package course_content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/logic/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UpdateContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func UpdateContentHandler(cfg *config.Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateContentReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
@@ -20,7 +23,22 @@ func UpdateContentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
l := course_content.NewUpdateContentLogic(r.Context(), svcCtx)
|
||||
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)
|
||||
ContentModel := model.NewCourseContentModel(conn)
|
||||
|
||||
l := course_content.NewUpdateContentLogic(r.Context(), cfg, ContentModel)
|
||||
resp, err := l.UpdateContent(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -6,7 +6,8 @@ package course_content
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,10 +16,11 @@ import (
|
||||
type AddContentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.CourseContentModel
|
||||
}
|
||||
|
||||
func NewAddContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddContentLogic {
|
||||
func NewAddContentLogic(ctx context.Context, cfg *config.Config, model model.CourseContentModel) *AddContentLogic {
|
||||
return &AddContentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
|
||||
@@ -6,7 +6,8 @@ package course_content
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type DeleteContentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.CourseContentModel
|
||||
}
|
||||
|
||||
func NewDeleteContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteContentLogic {
|
||||
func NewDeleteContentLogic(ctx context.Context, cfg *config.Config, model model.CourseContentModel) *DeleteContentLogic {
|
||||
return &DeleteContentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package course_content
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type GetContentListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.CourseContentModel
|
||||
}
|
||||
|
||||
func NewGetContentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContentListLogic {
|
||||
func NewGetContentListLogic(ctx context.Context, cfg *config.Config, model model.CourseContentModel) *GetContentListLogic {
|
||||
return &GetContentListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package course_content
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type GetContentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.CourseContentModel
|
||||
}
|
||||
|
||||
func NewGetContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContentLogic {
|
||||
func NewGetContentLogic(ctx context.Context, cfg *config.Config, model model.CourseContentModel) *GetContentLogic {
|
||||
return &GetContentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ package course_content
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/config"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/model"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -15,14 +16,16 @@ import (
|
||||
type UpdateContentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
cfg *config.Config
|
||||
model model.CourseContentModel
|
||||
}
|
||||
|
||||
func NewUpdateContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateContentLogic {
|
||||
func NewUpdateContentLogic(ctx context.Context, cfg *config.Config, model model.CourseContentModel) *UpdateContentLogic {
|
||||
return &UpdateContentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
cfg: cfg,
|
||||
model: model,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/article/handler/article"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/baseoverview/handler/baseOverview"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course/handler/course"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/course_content/handler/course_content"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/devproject/handler/devproject"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/file/handler/fileupload"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/meeting/handler/meeting"
|
||||
@@ -205,6 +206,25 @@ func SetupRouter(cfg *config.Config) *gin.Engine {
|
||||
videoCases.DELETE("/:id", gin.WrapH(video_case.DeleteVideoCaseHandler(cfg)))
|
||||
}
|
||||
|
||||
// ------------ 课程内容模块 ------------
|
||||
courseContents := api.Group("/course-content")
|
||||
{
|
||||
// 新增课程内容(POST /api/course-content)
|
||||
courseContents.POST("", gin.WrapH(course_content.AddContentHandler(cfg)))
|
||||
|
||||
// 课程内容列表(POST /api/course-content/list)- 与视频案例列表接口风格统一(用POST传参便于分页/筛选)
|
||||
courseContents.POST("/list", gin.WrapH(course_content.GetContentListHandler(cfg)))
|
||||
|
||||
// 获取单个课程内容详情(GET /api/course-content/:id)
|
||||
courseContents.GET("/:id", gin.WrapH(course_content.GetContentHandler(cfg)))
|
||||
|
||||
// 更新课程内容(PUT /api/course-content)
|
||||
courseContents.PUT("", gin.WrapH(course_content.UpdateContentHandler(cfg)))
|
||||
|
||||
// 删除课程内容(DELETE /api/course-content/:id)
|
||||
courseContents.DELETE("/:id", gin.WrapH(course_content.DeleteContentHandler(cfg)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user