wx-server/internal/server/role/query_list.go

60 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package role
import (
"mini_server/internal/dao"
"mini_server/internal/server/help"
"mini_server/internal/server/httpreply"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
type QueryListReply struct {
RoleList []*RoleInfo `json:"role_list"`
}
// 角色列表查询接口根据用户ID查询
func QueryList(c *gin.Context) {
reply := httpreply.NewDefaultReplyData()
defer httpreply.Reply(c, reply)
userId, ok := help.GetUserId(c)
if !ok {
reply.Status = http.StatusNotFound
reply.Message = "无法获取用户信息"
return
}
// 1. 需要去表user_character中查询关联的角色ID
list, err := dao.UserCharacter_QueryList(userId)
if err != nil {
logrus.Errorf("查询用户关联角色列表失败,err:%v", err)
reply.Status = http.StatusInternalServerError
reply.Message = "查询用户关联角色列表失败"
return
}
// 2. 根据角色ID列表查询角色详情
roleIds := make([]int32, len(list))
for i, data := range list {
roleIds[i] = data.CharacterId
}
roleList, err := dao.Character_QueryList(roleIds)
if err != nil {
logrus.Errorf("查询角色列表失败,userId:%v,roleIds:%v,err:%v", userId, roleIds, err)
reply.Status = http.StatusInternalServerError
reply.Message = "查询角色列表失败"
return
}
replyroleList := make([]*RoleInfo, len(list))
for i, data := range roleList {
var detail RoleInfo
Copy_mysql_data(data, &detail)
replyroleList[i] = &detail
}
reply.Data = roleList
}