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"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
EnableKYC bool `json:"enable_kyc"`
|
EnableKYC bool `json:"enable_kyc"`
|
||||||
IsJoined bool `json:"is_joined"`
|
IsJoined bool `json:"is_joined"`
|
||||||
|
IsCheckedIn bool `json:"is_checked_in"`
|
||||||
JoinCount int64 `json:"join_count"`
|
JoinCount int64 `json:"join_count"`
|
||||||
CheckinCount int64 `json:"checkin_count"`
|
CheckinCount int64 `json:"checkin_count"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2106,6 +2106,9 @@ const docTemplate = `{
|
|||||||
"event_id": {
|
"event_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"is_checked_in": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"is_joined": {
|
"is_joined": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2104,6 +2104,9 @@
|
|||||||
"event_id": {
|
"event_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"is_checked_in": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"is_joined": {
|
"is_joined": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
event_id:
|
event_id:
|
||||||
type: string
|
type: string
|
||||||
|
is_checked_in:
|
||||||
|
type: boolean
|
||||||
is_joined:
|
is_joined:
|
||||||
type: boolean
|
type: boolean
|
||||||
join_count:
|
join_count:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"nixcn-cms/internal/exception"
|
"nixcn-cms/internal/exception"
|
||||||
"nixcn-cms/service/shared"
|
"nixcn-cms/service/shared"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"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 {
|
if eventList != nil {
|
||||||
for i := range *eventList {
|
for i := range *eventList {
|
||||||
(*eventList)[i].IsJoined = true
|
(*eventList)[i].IsJoined = true
|
||||||
|
|||||||
Reference in New Issue
Block a user