完成课程文件handler

This commit is contained in:
2025-11-01 23:01:31 +08:00
parent 7ef870fe24
commit 847763738a
23 changed files with 241 additions and 175 deletions

View File

@@ -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()
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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"
@@ -14,15 +15,17 @@ import (
type CreateAdminLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
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,
}
}

View File

@@ -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"
@@ -14,15 +15,17 @@ import (
type DeleteAdminLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
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,
}
}

View File

@@ -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"
@@ -14,15 +15,17 @@ import (
type GetAdminLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
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,
}
}

View File

@@ -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"
@@ -14,15 +15,17 @@ import (
type ListAdminLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
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,
}
}

View File

@@ -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"
@@ -14,15 +15,17 @@ import (
type UpdateAdminLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
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,
}
}

View File

@@ -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"` // 操作结果信息
}