go_dreamfactory/modules/mline/api_getlist.go
2023-06-06 09:52:44 +08:00

66 lines
1.8 KiB
Go

package mline
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
)
//参数校验
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) {
if req.CType == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
///获取主线关卡信息
func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) {
rsp := &pb.MlineGetListResp{}
code = this.GetListCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelMline.getMainlineList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
for _, v := range list {
if v.CType == req.CType {
rsp.Data = append(rsp.Data, v)
}
}
if len(rsp.Data) == 0 { // 什么数据都没有 创建一条
if chapterConf, err := this.module.configure.GetFirstChapterIDByType(req.CType); err == nil { // 配置文件校验
if stageConf := this.module.configure.GetFirstStageIDByChapter(chapterConf.Id); stageConf != nil {
newData := &pb.DBMline{
Id: primitive.NewObjectID().Hex(),
Uid: session.GetUserId(),
CType: stageConf.Episodetype,
ChapterId: stageConf.Chapterid,
StageId: stageConf.Id,
Star: map[int32]int32{},
Award: map[int32]bool{},
Ps: map[int32]int32{},
}
rsp.Data = append(rsp.Data, newData)
this.module.modelMline.addNewChapter(session.GetUserId(), newData)
}
} else {
code = pb.ErrorCode_ConfigNoFound
data = &pb.ErrorData{
Title: pb.GetErrorCodeMsg(code),
Message: err.Error(),
}
return
}
}
session.SendMsg(string(this.module.GetType()), MlineGetListResp, rsp)
return
}