Add checkin count in attendance and event api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -149,6 +149,29 @@ func (self *Attendance) CountUsersByEventID(ctx context.Context, eventID uuid.UU
|
|||||||
Where("event_id = ?", eventID).
|
Where("event_id = ?", eventID).
|
||||||
Count(&count).Error
|
Count(&count).Error
|
||||||
|
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Attendance) CountCheckedInUsersByEventID(ctx context.Context, eventID uuid.UUID) (int64, error) {
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
err := Database.WithContext(ctx).
|
||||||
|
Model(&Attendance{}).
|
||||||
|
Where("event_id = ? AND checkin_at IS NOT NULL AND checkin_at > ?", eventID, time.Time{}). // 过滤未签到用户
|
||||||
|
Count(&count).Error
|
||||||
|
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,14 @@ type Event struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EventIndexDoc struct {
|
type EventIndexDoc struct {
|
||||||
EventId string `json:"event_id"`
|
EventId string `json:"event_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
EndTime time.Time `json:"end_time"`
|
EndTime time.Time `json:"end_time"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
|
CheckinCount int64 `json:"checkin_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Event) GetEventById(ctx context.Context, eventId uuid.UUID) (*Event, error) {
|
func (self *Event) GetEventById(ctx context.Context, eventId uuid.UUID) (*Event, error) {
|
||||||
|
|||||||
@@ -45,6 +45,27 @@ func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *E
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkinCount, err := new(data.Attendance).CountCheckedInUsersByEventID(payload.Context, payload.Data.EventId)
|
||||||
|
if err != nil {
|
||||||
|
exception := new(exception.Builder).
|
||||||
|
SetStatus(exception.StatusUser).
|
||||||
|
SetService(exception.ServiceEvent).
|
||||||
|
SetEndpoint(exception.EndpointEventServiceInfo).
|
||||||
|
SetType(exception.TypeCommon).
|
||||||
|
SetOriginal(exception.CommonErrorDatabase).
|
||||||
|
SetError(err).
|
||||||
|
Throw(payload.Context)
|
||||||
|
|
||||||
|
result = &EventInfoResult{
|
||||||
|
Common: shared.CommonResult{
|
||||||
|
HttpCode: 500,
|
||||||
|
Exception: exception,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
result = &EventInfoResult{
|
result = &EventInfoResult{
|
||||||
Common: shared.CommonResult{
|
Common: shared.CommonResult{
|
||||||
HttpCode: 200,
|
HttpCode: 200,
|
||||||
@@ -57,13 +78,14 @@ func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *E
|
|||||||
Throw(payload.Context),
|
Throw(payload.Context),
|
||||||
},
|
},
|
||||||
Data: &data.EventIndexDoc{
|
Data: &data.EventIndexDoc{
|
||||||
EventId: event.EventId.String(),
|
EventId: event.EventId.String(),
|
||||||
Name: event.Name,
|
Name: event.Name,
|
||||||
Type: event.Type,
|
Type: event.Type,
|
||||||
Description: event.Description,
|
Description: event.Description,
|
||||||
StartTime: event.StartTime,
|
StartTime: event.StartTime,
|
||||||
EndTime: event.EndTime,
|
EndTime: event.EndTime,
|
||||||
Thumbnail: event.Thumbnail,
|
Thumbnail: event.Thumbnail,
|
||||||
|
CheckinCount: checkinCount,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user