feat: 🎸 课程列表&课程详情
This commit is contained in:
parent
56da25dc81
commit
f574831f15
16
server/api/api/lesson/lesson.go
Normal file
16
server/api/api/lesson/lesson.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"hotgo/api/api/lesson/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ILessonV1 interface {
|
||||||
|
LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error)
|
||||||
|
LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error)
|
||||||
|
}
|
29
server/api/api/lesson/v1/lesson.go
Normal file
29
server/api/api/lesson/v1/lesson.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hotgo/internal/model/entity"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取课程列表请求
|
||||||
|
type LessonListReq struct {
|
||||||
|
g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取课程列表响应
|
||||||
|
type LessonListRes struct {
|
||||||
|
List []*entity.Lesson `json:"list" dc:"课程列表"`
|
||||||
|
Total int `json:"total" dc:"总数"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看课程详情请求
|
||||||
|
type LessonDetailReq struct {
|
||||||
|
g.Meta `path:"/lesson/detail" method:"get" tags:"课程" summary:"查看课程详情"`
|
||||||
|
Id int64 `json:"id" v:"required#课程ID必填" dc:"课程ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看课程详情响应
|
||||||
|
type LessonDetailRes struct {
|
||||||
|
Lesson *entity.Lesson `json:"lesson" dc:"课程"`
|
||||||
|
}
|
5
server/internal/controller/api/lesson/lesson.go
Normal file
5
server/internal/controller/api/lesson/lesson.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package lesson
|
15
server/internal/controller/api/lesson/lesson_new.go
Normal file
15
server/internal/controller/api/lesson/lesson_new.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hotgo/api/api/lesson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ControllerV1 struct{}
|
||||||
|
|
||||||
|
func NewV1() lesson.ILessonV1 {
|
||||||
|
return &ControllerV1{}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gcode"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
|
||||||
|
v1 "hotgo/api/api/lesson/v1"
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"hotgo/internal/model/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *ControllerV1) LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error) {
|
||||||
|
lesson := new(entity.Lesson)
|
||||||
|
err = dao.Lesson.Ctx(ctx).Where("id = ?", req.Id).Scan(lesson)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||||
|
}
|
||||||
|
if lesson.Id == 0 {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeNotFound, "课程不存在")
|
||||||
|
}
|
||||||
|
res = &v1.LessonDetailRes{
|
||||||
|
Lesson: lesson,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
v1 "hotgo/api/api/lesson/v1"
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"hotgo/internal/model/entity"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gcode"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *ControllerV1) LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) {
|
||||||
|
// 查询课程列表
|
||||||
|
var list []*entity.Lesson
|
||||||
|
err = dao.Lesson.Ctx(ctx).Scan(&list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||||
|
}
|
||||||
|
// 统计总数
|
||||||
|
total, err := dao.Lesson.Ctx(ctx).Count()
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
||||||
|
}
|
||||||
|
res = &v1.LessonListRes{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -8,6 +8,7 @@ package router
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"hotgo/internal/consts"
|
"hotgo/internal/consts"
|
||||||
|
"hotgo/internal/controller/api/lesson"
|
||||||
"hotgo/internal/controller/api/member"
|
"hotgo/internal/controller/api/member"
|
||||||
"hotgo/internal/controller/api/pay"
|
"hotgo/internal/controller/api/pay"
|
||||||
"hotgo/internal/controller/api/users"
|
"hotgo/internal/controller/api/users"
|
||||||
@ -31,7 +32,8 @@ func Api(ctx context.Context, group *ghttp.RouterGroup) {
|
|||||||
|
|
||||||
group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) {
|
group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) {
|
||||||
group.Bind(
|
group.Bind(
|
||||||
users.NewV1(), // 前台用户
|
users.NewV1(), // 前台用户
|
||||||
|
lesson.NewV1(), // 课程
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user