51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
|
|
"36wisdom/biz/model/dto"
|
|
"36wisdom/biz/service"
|
|
)
|
|
|
|
type lifeTask struct{}
|
|
|
|
var LifeTask = &lifeTask{}
|
|
|
|
func (c *lifeTask) Get(ctx context.Context, req *dto.LifeTaskGetReq) (*dto.LifeTaskGetRes, error) {
|
|
rec, err := service.LifeTask.GetByPk(ctx, req.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.LifeTaskGetRes{}
|
|
if !rec.IsEmpty() {
|
|
res.LifeTask = lifeTaskItem(rec)
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *lifeTask) List(ctx context.Context, req *dto.LifeTaskListReq) (*dto.LifeTaskListRes, error) {
|
|
recs, err := service.LifeTask.ListEnabled(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.LifeTaskListRes{List: make([]dto.LifeTaskItem, 0, len(recs))}
|
|
for _, r := range recs {
|
|
res.List = append(res.List, lifeTaskItem(r))
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func lifeTaskItem(r gdb.Record) dto.LifeTaskItem {
|
|
return dto.LifeTaskItem{
|
|
Id: r["id"].Int64(),
|
|
StrategyId: r["strategy_id"].Int64(),
|
|
Title: r["title"].String(),
|
|
Description: r["description"].String(),
|
|
Guide: r["guide"].String(),
|
|
RewardPoints: r["reward_points"].Int(),
|
|
Status: r["status"].Int(),
|
|
}
|
|
}
|