@@ -17,6 +17,7 @@ func ApiHandler(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
r.Use(middleware.ApiVersionCheck(), middleware.JWTAuth(), middleware.Permission(5))
|
r.Use(middleware.ApiVersionCheck(), middleware.JWTAuth(), middleware.Permission(5))
|
||||||
r.GET("/info", userHandler.Info)
|
r.GET("/info", userHandler.Info)
|
||||||
|
r.GET("/info/*user_id", userHandler.Other)
|
||||||
r.PATCH("/update", userHandler.Update)
|
r.PATCH("/update", userHandler.Update)
|
||||||
r.GET("/list", middleware.Permission(20), userHandler.List)
|
r.GET("/list", middleware.Permission(20), userHandler.List)
|
||||||
r.POST("/create", middleware.Permission(50), userHandler.Create)
|
r.POST("/create", middleware.Permission(50), userHandler.Create)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func (self *UserHandler) Info(c *gin.Context) {
|
|||||||
UserInfoPayload := &service_user.UserInfoPayload{
|
UserInfoPayload := &service_user.UserInfoPayload{
|
||||||
Context: c,
|
Context: c,
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
|
IsOther: false,
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
58
api/user/other.go
Normal file
58
api/user/other.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
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
|
||||||
|
// @Success 200 {object} utils.RespStatus{data=service_user.UserInfoData} "Successful profile retrieval"
|
||||||
|
// @Failure 403 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized"
|
||||||
|
// @Failure 404 {object} utils.RespStatus{data=nil} "User Not Found"
|
||||||
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error (UUID Parse Failed)"
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @Router /user/info [get]
|
||||||
|
func (self *UserHandler) Other(c *gin.Context) {
|
||||||
|
userIdOrig := c.Param("user_id")
|
||||||
|
|
||||||
|
userId, err := uuid.Parse(userIdOrig)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
UserInfoPayload := &service_user.UserInfoPayload{
|
||||||
|
Context: c,
|
||||||
|
UserId: userId,
|
||||||
|
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)
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ type UserInfoData struct {
|
|||||||
type UserInfoPayload struct {
|
type UserInfoPayload struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
UserId uuid.UUID
|
UserId uuid.UUID
|
||||||
|
IsOther bool
|
||||||
Data *UserInfoData
|
Data *UserInfoData
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +64,29 @@ func (self *UserServiceImpl) GetUserInfo(payload *UserInfoPayload) (result *User
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if payload.IsOther {
|
||||||
|
if !userData.AllowPublic {
|
||||||
|
exception := new(exception.Builder).
|
||||||
|
SetStatus(exception.StatusUser).
|
||||||
|
SetService(exception.ServiceUser).
|
||||||
|
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||||
|
SetType(exception.TypeCommon).
|
||||||
|
SetOriginal(exception.CommonErrorUserNotFound).
|
||||||
|
SetError(err).
|
||||||
|
Throw(payload.Context)
|
||||||
|
|
||||||
|
result = &UserInfoResult{
|
||||||
|
Common: shared.CommonResult{
|
||||||
|
HttpCode: 404,
|
||||||
|
Exception: exception,
|
||||||
|
},
|
||||||
|
Data: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exception := new(exception.Builder).
|
exception := new(exception.Builder).
|
||||||
SetStatus(exception.StatusUser).
|
SetStatus(exception.StatusUser).
|
||||||
SetService(exception.ServiceUser).
|
SetService(exception.ServiceUser).
|
||||||
|
|||||||
Reference in New Issue
Block a user