profile.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package admin_common
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. "sghgogs.com/sghblog/authorization-client/model/base"
  6. "sghgogs.com/sghblog/authorization-client/model/response/common"
  7. "sghgogs.com/sghblog/authorization-client/response"
  8. "sghgogs.com/sghblog/authorization-client/utils"
  9. pb "sghgogs.com/sghblog/authorization-service/proto"
  10. )
  11. // Profile
  12. // @summary 获取个人信息
  13. // @Description 查询个人信息
  14. // @Tags Common
  15. // @Accept json
  16. // @Produce json
  17. // @Param Authorization header string true "Bearer 用户令牌"
  18. // @Success 200 {object} response.ApiResponse{data=common.UserInfo} "成功"
  19. // @Failure 400 {object} response.ApiResponse "请求错误"
  20. // @Failure 500 {object} response.ApiResponse "内部错误"
  21. // @Router /v1/api/admin/profile [get]
  22. func (svc *ApiAdminCommon) Profile(c *gin.Context) {
  23. ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "CommonService.AdminProfile")
  24. profile, err := svc.Service.AdminProfile(ctx, &pb.AdminProfileRequest{})
  25. if err != nil {
  26. code, mgs := response.MicroErrorRequest(err)
  27. c.JSON(http.StatusBadRequest, response.ErrorResponse(code, mgs))
  28. return
  29. }
  30. user := profile.User
  31. c.JSON(http.StatusOK, response.SuccessResponse(common.UserInfo{
  32. Id: user.Id,
  33. Username: user.Username,
  34. PhoneNumber: user.PhoneNumber,
  35. Email: user.Email,
  36. Avatar: user.Avatar,
  37. Roles: base.RolesToResponse(user.Roles),
  38. Teams: base.TeamsToResponse(user.Teams),
  39. }))
  40. }