Fix Join Event service_event
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-02 19:30:40 +08:00
parent f5a7fa3551
commit 9c945d69a9
21 changed files with 1733 additions and 274 deletions

View File

@@ -2,12 +2,13 @@ package service_event
import (
"context"
"errors"
"nixcn-cms/data"
"nixcn-cms/internal/exception"
"nixcn-cms/service/shared"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type EventJoinData struct {
@@ -116,90 +117,38 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
return
}
if eventData.EnableKYC == true && payload.Data.KycId != "" {
kycId, err := uuid.Parse(payload.Data.KycId)
if err != nil {
exception := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUuidParseFailed).
SetError(err).
Throw(payload.Context)
attendenceSearch, err := new(data.Attendance).GetAttendanceByEventIdAndUserId(payload.Context, eventId, userId)
result = &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 400,
Exception: exception,
},
}
return
}
kycData, err := new(data.Kyc).GetByKycId(payload.Context, &kycId)
if err != nil {
exception := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorDatabase).
SetError(err).
Throw(payload.Context)
result = &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 500,
Exception: exception,
},
}
return
}
if kycData.UserId != userId {
exception := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Throw(payload.Context)
result = &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 400,
Exception: exception,
},
}
return
}
attendenceData.SetKycId(kycData.KycId)
}
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{
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 403,
Exception: exception,
HttpCode: 500,
Exception: new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorDatabase).
SetError(err).
Throw(payload.Context),
},
}
}
return
if err == nil && attendenceSearch != nil && attendenceSearch.AttendanceId != uuid.Nil {
return &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 403,
Exception: new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeSpecific).
SetOriginal(exception.EventJoinEventInvalid).
SetError(errors.New("user already joined this event")).
Throw(payload.Context),
},
}
}
attendenceData.SetUserId(userId)
@@ -209,23 +158,19 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
err = attendenceData.Create(payload.Context)
if err != nil {
exception := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorDatabase).
SetError(err).
Throw(payload.Context)
result = &EventJoinResult{
return &EventJoinResult{
Common: shared.CommonResult{
HttpCode: 500,
Exception: exception,
HttpCode: 500,
Exception: new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceJoin).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorDatabase).
SetError(err).
Throw(payload.Context),
},
}
return
}
exception := new(exception.Builder).