添加课程资源和课程教室的Handler

This commit is contained in:
2025-11-02 00:22:09 +08:00
parent 64a19fccef
commit af533b16f1
32 changed files with 997 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package main
import (
"flag"
"fmt"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/config"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/handler"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/courseresourceapi.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

@@ -0,0 +1,3 @@
Name: course_resource_api
Host: 0.0.0.0
Port: 8888

View File

@@ -0,0 +1,10 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
}

View File

@@ -0,0 +1,31 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func CreateCourseResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateCourseResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := course_resource.NewCreateCourseResourceLogic(r.Context(), svcCtx)
resp, err := l.CreateCourseResource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,31 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func DeleteCourseResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteCourseResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := course_resource.NewDeleteCourseResourceLogic(r.Context(), svcCtx)
resp, err := l.DeleteCourseResource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,31 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func GetCourseResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetCourseResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := course_resource.NewGetCourseResourceLogic(r.Context(), svcCtx)
resp, err := l.GetCourseResource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,31 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func ListCourseResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListCourseResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := course_resource.NewListCourseResourceLogic(r.Context(), svcCtx)
resp, err := l.ListCourseResource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,31 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/logic/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func UpdateCourseResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UpdateCourseResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := course_resource.NewUpdateCourseResourceLogic(r.Context(), svcCtx)
resp, err := l.UpdateCourseResource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,46 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.1
package handler
import (
"net/http"
course_resource "github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/handler/course_resource"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/",
Handler: course_resource.CreateCourseResourceHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/",
Handler: course_resource.UpdateCourseResourceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/:id",
Handler: course_resource.GetCourseResourceHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/:id",
Handler: course_resource.DeleteCourseResourceHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/list",
Handler: course_resource.ListCourseResourceHandler(serverCtx),
},
},
rest.WithPrefix("/api/course-resource"),
)
}

View File

@@ -0,0 +1,33 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"context"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateCourseResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateCourseResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCourseResourceLogic {
return &CreateCourseResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateCourseResourceLogic) CreateCourseResource(req *types.CreateCourseResourceReq) (resp *types.CreateCourseResourceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,33 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"context"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteCourseResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteCourseResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCourseResourceLogic {
return &DeleteCourseResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteCourseResourceLogic) DeleteCourseResource(req *types.DeleteCourseResourceReq) (resp *types.DeleteCourseResourceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,33 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"context"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetCourseResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetCourseResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCourseResourceLogic {
return &GetCourseResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetCourseResourceLogic) GetCourseResource(req *types.GetCourseResourceReq) (resp *types.GetCourseResourceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,33 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"context"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListCourseResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListCourseResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCourseResourceLogic {
return &ListCourseResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListCourseResourceLogic) ListCourseResource(req *types.ListCourseResourceReq) (resp *types.ListCourseResourceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,33 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package course_resource
import (
"context"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/svc"
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateCourseResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateCourseResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCourseResourceLogic {
return &UpdateCourseResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateCourseResourceLogic) UpdateCourseResource(req *types.UpdateCourseResourceReq) (resp *types.UpdateCourseResourceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,18 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package svc
import (
"github.com/JACKYMYPERSON/hldrCenter/internal/course_resource/internal/config"
)
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

View File

@@ -0,0 +1,64 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.1
package types
type CreateCourseResourceReq struct {
CourseId int `json:"course_id" form:"course_id" validate:"required"`
Title string `json:"title" form:"title" validate:"required,max=255"`
ResourceUrl string `json:"resource_url" form:"resource_url" validate:"required,max=512"`
Size int `json:"size" form:"size" validate:"omitempty,min=0"`
Sort int `json:"sort" form:"sort" validate:"omitempty,min=0"`
}
type CreateCourseResourceResp struct {
Id int `json:"id"`
Message string `json:"message"`
}
type DeleteCourseResourceReq struct {
Id int `path:"id" validate:"required"`
}
type DeleteCourseResourceResp struct {
Message string `json:"message"`
}
type GetCourseResourceReq struct {
Id int `path:"id" validate:"required"`
}
type GetCourseResourceResp struct {
Id int `json:"id"`
CourseId int `json:"course_id"`
Title string `json:"title"`
ResourceUrl string `json:"resource_url"`
Size int `json:"size"`
Sort int `json:"sort"`
}
type ListCourseResourceReq struct {
CourseId int `form:"course_id" validate:"omitempty"`
Page int `form:"page" validate:"required,min=1"`
PageSize int `form:"page_size" validate:"required,min=1,max=100"`
}
type ListCourseResourceResp struct {
Total int `json:"total"`
List []GetCourseResourceResp `json:"list"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
type UpdateCourseResourceReq struct {
Id int `json:"id" validate:"required"`
CourseId int `json:"course_id" validate:"omitempty"`
Title string `json:"title" validate:"omitempty,max=255"`
ResourceUrl string `json:"resource_url" validate:"omitempty,max=512"`
Size int `json:"size" validate:"omitempty,min=0"`
Sort int `json:"sort" validate:"omitempty,min=0"`
}
type UpdateCourseResourceResp struct {
Message string `json:"message"`
}