Add quota and limit for events

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-02-05 12:53:54 +08:00
parent 2ad3ba2400
commit 6504c20708
5 changed files with 57 additions and 3 deletions

View File

@@ -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 {