Add isjoined to event info and event list
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -141,6 +141,31 @@ func (self *Attendance) GetAttendanceListByEventId(ctx context.Context, eventId
|
||||
return &result, err
|
||||
}
|
||||
|
||||
func (self *Attendance) GetJoinedEventIDs(ctx context.Context, userId uuid.UUID, eventIds []uuid.UUID) (map[uuid.UUID]bool, error) {
|
||||
joinedMap := make(map[uuid.UUID]bool)
|
||||
|
||||
if len(eventIds) == 0 {
|
||||
return joinedMap, nil
|
||||
}
|
||||
|
||||
var foundEventIds []uuid.UUID
|
||||
|
||||
err := Database.WithContext(ctx).
|
||||
Model(&Attendance{}).
|
||||
Where("user_id = ? AND event_id IN ?", userId, eventIds).
|
||||
Pluck("event_id", &foundEventIds).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, id := range foundEventIds {
|
||||
joinedMap[id] = true
|
||||
}
|
||||
|
||||
return joinedMap, nil
|
||||
}
|
||||
|
||||
func (self *Attendance) CountUsersByEventID(ctx context.Context, eventID uuid.UUID) (int64, error) {
|
||||
var count int64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user