100 lines
3.0 KiB
Go
100 lines
3.0 KiB
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service/service_user"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Info retrieves the profile information of the other user.
|
|
//
|
|
// @Summary Get Other User Information
|
|
// @Description Fetches the complete profile data for the user associated with the provided session/token.
|
|
// @Tags User
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user_id path string true "Other user id"
|
|
// @Success 200 {object} utils.RespStatus{data=service_user.UserInfoData} "Successful profile retrieval"
|
|
// @Failure 401 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized"
|
|
// @Failure 404 {object} utils.RespStatus{data=nil} "User Not Found"
|
|
// @Failure 403 {object} utils.RespStatus{data=nil} "User Not Public"
|
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error (UUID Parse Failed)"
|
|
// @Security ApiKeyAuth
|
|
// @Router /user/info/{user_id} [get]
|
|
func (self *UserHandler) Other(c *gin.Context) {
|
|
userIdFromUrlOrig := c.Param("user_id")
|
|
|
|
userIdFromUrl, err := uuid.Parse(userIdFromUrlOrig)
|
|
if err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceInfo).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorUuidParseFailed).
|
|
SetError(err).
|
|
Throw(c).
|
|
String()
|
|
utils.HttpResponse(c, 500, errorCode)
|
|
return
|
|
}
|
|
|
|
userIdFromHeaderOrig, ok := c.Get("user_id")
|
|
if !ok {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusUser).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceInfo).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorMissingUserId).
|
|
Throw(c).
|
|
String()
|
|
utils.HttpResponse(c, 403, errorCode)
|
|
return
|
|
}
|
|
|
|
userIdFromHeader, err := uuid.Parse(userIdFromHeaderOrig.(string))
|
|
if err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceInfo).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorUuidParseFailed).
|
|
SetError(err).
|
|
Throw(c).
|
|
String()
|
|
utils.HttpResponse(c, 500, errorCode)
|
|
return
|
|
}
|
|
|
|
var UserInfoPayload = &service_user.UserInfoPayload{}
|
|
if userIdFromUrl == userIdFromHeader {
|
|
UserInfoPayload = &service_user.UserInfoPayload{
|
|
Context: c,
|
|
UserId: userIdFromHeader,
|
|
IsOther: false,
|
|
Data: nil,
|
|
}
|
|
} else if userIdFromUrl != userIdFromHeader {
|
|
UserInfoPayload = &service_user.UserInfoPayload{
|
|
Context: c,
|
|
UserId: userIdFromHeader,
|
|
IsOther: true,
|
|
Data: nil,
|
|
}
|
|
}
|
|
|
|
result := self.svc.GetUserInfo(UserInfoPayload)
|
|
|
|
if result.Common.Exception.Original != exception.CommonSuccess {
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
|
return
|
|
}
|
|
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
|
}
|