Add user other api logic
All checks were successful
Client CMS Check Build (NixCN CMS) TeamCity build finished
Backend Check Build (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-02-01 09:54:39 +08:00
parent 7536fdc1ac
commit a2eb882398
3 changed files with 70 additions and 7 deletions

View File

@@ -25,9 +25,9 @@ import (
// @Security ApiKeyAuth
// @Router /user/info/{user_id} [get]
func (self *UserHandler) Other(c *gin.Context) {
userIdOrig := c.Param("user_id")
userIdFromUrlOrig := c.Param("user_id")
userId, err := uuid.Parse(userIdOrig)
userIdFromUrl, err := uuid.Parse(userIdFromUrlOrig)
if err != nil {
errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
@@ -42,12 +42,51 @@ func (self *UserHandler) Other(c *gin.Context) {
return
}
UserInfoPayload := &service_user.UserInfoPayload{
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: userId,
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)

View File

@@ -34,3 +34,5 @@ event:
record_not_found: "00001"
list:
database_failed: "00001"
join:
event_invalid: "00001"

View File

@@ -5,6 +5,7 @@ import (
"nixcn-cms/data"
"nixcn-cms/internal/exception"
"nixcn-cms/service/shared"
"time"
"github.com/google/uuid"
)
@@ -29,6 +30,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
var err error
attendenceData := new(data.Attendance)
eventData := new(data.Event)
eventId, err := uuid.Parse(payload.Data.EventId)
if err != nil {
@@ -51,6 +53,26 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
return
}
if !eventData.EndTime.Before(time.Now()) {
exception := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeSpecific).
SetOriginal(exception.EventJoinEventInvalid).
SetError(err).
Throw(payload.Context)
result = &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 403,
Exception: exception,
},
}
return
}
userId, err := uuid.Parse(payload.Data.UserId)
if err != nil {
exception := new(exception.Builder).