Add is_checked_in into joined event api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -34,6 +34,7 @@ type EventIndexDoc struct {
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
EnableKYC bool `json:"enable_kyc"`
|
||||
IsJoined bool `json:"is_joined"`
|
||||
IsCheckedIn bool `json:"is_checked_in"`
|
||||
JoinCount int64 `json:"join_count"`
|
||||
CheckinCount int64 `json:"checkin_count"`
|
||||
}
|
||||
|
||||
@@ -2106,6 +2106,9 @@ const docTemplate = `{
|
||||
"event_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_checked_in": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"is_joined": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -2104,6 +2104,9 @@
|
||||
"event_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_checked_in": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"is_joined": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -12,6 +12,8 @@ definitions:
|
||||
type: string
|
||||
event_id:
|
||||
type: string
|
||||
is_checked_in:
|
||||
type: boolean
|
||||
is_joined:
|
||||
type: boolean
|
||||
join_count:
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/shared"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -108,6 +109,34 @@ func (self *EventServiceImpl) GetJoinedEvent(payload *JoinedEventListPayload) (r
|
||||
}
|
||||
}
|
||||
|
||||
if eventList != nil && len(*eventList) > 0 {
|
||||
attendances, err := new(data.Attendance).GetEventsByUserID(payload.Context, payload.UserId)
|
||||
|
||||
checkinMap := make(map[uuid.UUID]time.Time)
|
||||
if err == nil && attendances != nil {
|
||||
for _, att := range *attendances {
|
||||
checkinMap[att.EventId] = att.CheckinAt
|
||||
}
|
||||
}
|
||||
|
||||
for i := range *eventList {
|
||||
item := &(*eventList)[i]
|
||||
|
||||
item.IsJoined = true
|
||||
|
||||
eID, _ := uuid.Parse(item.EventId)
|
||||
|
||||
if checkinTime, signedUp := checkinMap[eID]; signedUp {
|
||||
if !checkinTime.IsZero() && checkinTime.After(time.Unix(0, 0)) {
|
||||
item.IsCheckedIn = true
|
||||
}
|
||||
}
|
||||
|
||||
cCount, _ := new(data.Attendance).CountCheckedInUsersByEventID(payload.Context, eID)
|
||||
item.CheckinCount = cCount
|
||||
}
|
||||
}
|
||||
|
||||
if eventList != nil {
|
||||
for i := range *eventList {
|
||||
(*eventList)[i].IsJoined = true
|
||||
|
||||
Reference in New Issue
Block a user