You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.7 KiB

package memory
import (
"yunyan/comm"
"yunyan/pb"
)
// List 按日期范围/分类拉取记忆项
// @Summary 拉取记忆项
// @Description 按日期范围与分类查询拾忆条目
// @Tags Memory
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param data body pb.MemoryListReq true "请求数据"
// @Success 200 {object} comm.HttpResult{data=pb.MemoryListResp} "响应数据"
// @Router /api/home/memory_list [post]
func (this *apiComp) List(session comm.IUserSession, req *pb.MemoryListReq) (resp *pb.MemoryListResp, errdata *pb.ErrorData) {
uid, errdata := requireUID(session)
if errdata != nil {
return
}
if req.StartDate != "" {
if _, ok := comm.ParseMemoryDate(req.StartDate); !ok {
errdata = &pb.ErrorData{Code: pb.ErrorCode_MemoryParamInvalid, Message: "start_date 格式应为 YYYY-MM-DD"}
return
}
}
if req.EndDate != "" {
if _, ok := comm.ParseMemoryDate(req.EndDate); !ok {
errdata = &pb.ErrorData{Code: pb.ErrorCode_MemoryParamInvalid, Message: "end_date 格式应为 YYYY-MM-DD"}
return
}
}
for _, c := range req.Categories {
if !comm.IsValidMemoryCategory(c) {
errdata = &pb.ErrorData{Code: pb.ErrorCode_MemoryCategoryInvalid, Message: "不支持的分类: " + c}
return
}
}
items, total, err := this.module.model.listItems(&itemQuery{
uid: uid,
startDate: req.StartDate,
endDate: req.EndDate,
categories: req.Categories,
states: req.States,
page: req.Page,
size: clampListSize(req.Size),
})
if err != nil {
this.module.Errorf("memory_list uid:%s err:%v", uid, err)
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: "查询失败"}
return
}
resp = &pb.MemoryListResp{Items: items, Total: total}
return
}