123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package admin_common
- import (
- "github.com/gin-gonic/gin"
- "net/http"
- "sghgogs.com/sghblog/authorization-client/model/base"
- "sghgogs.com/sghblog/authorization-client/model/response/common"
- "sghgogs.com/sghblog/authorization-client/response"
- "sghgogs.com/sghblog/authorization-client/utils"
- pb "sghgogs.com/sghblog/authorization-service/proto"
- )
- // Profile
- // @summary 获取个人信息
- // @Description 查询个人信息
- // @Tags Common
- // @Accept json
- // @Produce json
- // @Param Authorization header string true "Bearer 用户令牌"
- // @Success 200 {object} response.ApiResponse{data=common.UserInfo} "成功"
- // @Failure 400 {object} response.ApiResponse "请求错误"
- // @Failure 500 {object} response.ApiResponse "内部错误"
- // @Router /v1/api/admin/profile [get]
- func (svc *ApiAdminCommon) Profile(c *gin.Context) {
- ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "CommonService.AdminProfile")
- profile, err := svc.Service.AdminProfile(ctx, &pb.AdminProfileRequest{})
- if err != nil {
- code, mgs := response.MicroErrorRequest(err)
- c.JSON(http.StatusBadRequest, response.ErrorResponse(code, mgs))
- return
- }
- user := profile.User
- c.JSON(http.StatusOK, response.SuccessResponse(common.UserInfo{
- Id: user.Id,
- Username: user.Username,
- PhoneNumber: user.PhoneNumber,
- Email: user.Email,
- Avatar: user.Avatar,
- Roles: base.RolesToResponse(user.Roles),
- Teams: base.TeamsToResponse(user.Teams),
- }))
- }
|