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
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ type EventIndexDoc struct {
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime time.Time `json:"end_time"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
RequireKyc bool `json:"require_kyc"`
|
||||
EnableKYC bool `json:"enable_kyc"`
|
||||
IsJoined bool `json:"is_joined"`
|
||||
JoinCount int64 `json:"join_count"`
|
||||
CheckinCount int64 `json:"checkin_count"`
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func (self *Event) FastListEvents(ctx context.Context, limit, offset int64) (*[]
|
||||
|
||||
err := Database.WithContext(ctx).
|
||||
Model(&Event{}).
|
||||
Select("event_id", "name", "type", "description", "start_time", "end_time").
|
||||
Select("event_id", "name", "type", "description", "start_time", "end_time", "enable_kyc").
|
||||
Limit(int(limit)).
|
||||
Offset(int(offset)).
|
||||
Scan(&results).Error
|
||||
|
||||
Reference in New Issue
Block a user