Add is_checked_in into joined event api
All checks were successful
Client CMS Check Build (NixCN CMS) TeamCity build finished
Backend Check Build (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-02-08 16:22:40 +08:00
parent 83e62ba825
commit e7df62e673
5 changed files with 38 additions and 0 deletions

View File

@@ -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"`
} }

View File

@@ -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"
}, },

View File

@@ -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"
}, },

View File

@@ -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:

View File

@@ -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