diff --git a/data/event.go b/data/event.go index 1d760a5..590b925 100644 --- a/data/event.go +++ b/data/event.go @@ -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"` } diff --git a/docs/docs.go b/docs/docs.go index 533f749..0eb603b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2106,6 +2106,9 @@ const docTemplate = `{ "event_id": { "type": "string" }, + "is_checked_in": { + "type": "boolean" + }, "is_joined": { "type": "boolean" }, diff --git a/docs/swagger.json b/docs/swagger.json index 46765d0..5de02ae 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2104,6 +2104,9 @@ "event_id": { "type": "string" }, + "is_checked_in": { + "type": "boolean" + }, "is_joined": { "type": "boolean" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c3972a0..d1f7826 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -12,6 +12,8 @@ definitions: type: string event_id: type: string + is_checked_in: + type: boolean is_joined: type: boolean join_count: diff --git a/service/service_event/get_joined_event.go b/service/service_event/get_joined_event.go index 482038a..2bb0ac5 100644 --- a/service/service_event/get_joined_event.go +++ b/service/service_event/get_joined_event.go @@ -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