注册/登录签发 JWT(bcrypt 校验),孩子档案增改查带归属校验, 列表汇总完美关卡数并派生成长等级。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"36wisdom/biz/model/dto"
|
|
"36wisdom/biz/service"
|
|
"36wisdom/common/auth"
|
|
)
|
|
|
|
type child struct{}
|
|
|
|
var Child = &child{}
|
|
|
|
func (c *child) Create(ctx context.Context, req *dto.ChildCreateReq) (*dto.ChildCreateRes, error) {
|
|
childId, err := service.Child.Create(ctx, auth.GetUid(ctx), req.Nickname, req.AgeGroup)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dto.ChildCreateRes{ChildId: childId}, nil
|
|
}
|
|
|
|
func (c *child) Update(ctx context.Context, req *dto.ChildUpdateReq) (*dto.ChildUpdateRes, error) {
|
|
data := g.Map{}
|
|
if req.Nickname != "" {
|
|
data["nickname"] = req.Nickname
|
|
}
|
|
if req.Avatar != "" {
|
|
data["avatar"] = req.Avatar
|
|
}
|
|
if req.AgeGroup != "" {
|
|
data["age_group"] = req.AgeGroup
|
|
}
|
|
if req.DailyLimitMinutes > 0 {
|
|
data["daily_limit_minutes"] = req.DailyLimitMinutes
|
|
}
|
|
if len(data) == 0 {
|
|
return &dto.ChildUpdateRes{}, nil
|
|
}
|
|
if err := service.Child.Update(ctx, auth.GetUid(ctx), req.ChildId, data); err != nil {
|
|
return nil, err
|
|
}
|
|
return &dto.ChildUpdateRes{}, nil
|
|
}
|
|
|
|
func (c *child) List(ctx context.Context, req *dto.ChildListReq) (*dto.ChildListRes, error) {
|
|
items, err := service.Child.List(ctx, auth.GetUid(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.ChildListRes{List: make([]dto.ChildListItem, 0, len(items))}
|
|
for _, it := range items {
|
|
res.List = append(res.List, dto.ChildListItem{
|
|
ChildId: it.ChildId,
|
|
Nickname: it.Nickname,
|
|
Avatar: it.Avatar,
|
|
AgeGroup: it.AgeGroup,
|
|
Points: it.Points,
|
|
Level: it.Level,
|
|
LevelTitle: it.LevelTitle,
|
|
PerfectCount: it.PerfectCount,
|
|
DailyLimitMinutes: it.DailyLimitMinutes,
|
|
})
|
|
}
|
|
return res, nil
|
|
}
|