Add quota and limit for events
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -153,8 +153,44 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
|
||||
|
||||
attendenceData.SetUserId(userId)
|
||||
attendenceData.SetEventId(eventId)
|
||||
attendenceData.SetRole("notmal")
|
||||
attendenceData.SetState("success")
|
||||
attendenceCount, err := attendenceData.CountUsersByEventID(payload.Context, eventId)
|
||||
if err != nil {
|
||||
return &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
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),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if attendenceCount >= eventData.Quota {
|
||||
if attendenceCount >= eventData.Limit {
|
||||
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.EventJoinLimitExceeded).
|
||||
SetError(errors.New("event limit exceeded")).
|
||||
Throw(payload.Context),
|
||||
},
|
||||
}
|
||||
}
|
||||
attendenceData.SetState("out_of_limit")
|
||||
} else {
|
||||
attendenceData.SetState("success")
|
||||
}
|
||||
attendenceData.SetRole("normal")
|
||||
|
||||
err = attendenceData.Create(payload.Context)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user