Add isjoined to event info and event list
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"nixcn-cms/service/shared"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type EventInfoData struct {
|
||||
@@ -15,6 +16,7 @@ type EventInfoData struct {
|
||||
|
||||
type EventInfoPayload struct {
|
||||
Context context.Context
|
||||
UserId uuid.UUID
|
||||
Data *EventInfoData
|
||||
}
|
||||
|
||||
@@ -87,6 +89,32 @@ func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *E
|
||||
return
|
||||
}
|
||||
|
||||
var isJoined bool
|
||||
joinedInfo, err := new(data.Attendance).GetAttendance(payload.Context, payload.UserId, payload.Data.EventId)
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
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
|
||||
} else if err == gorm.ErrRecordNotFound {
|
||||
isJoined = false
|
||||
} else if joinedInfo.AttendanceId != uuid.Nil {
|
||||
isJoined = true
|
||||
}
|
||||
|
||||
result = &EventInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
@@ -106,7 +134,8 @@ func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *E
|
||||
StartTime: event.StartTime,
|
||||
EndTime: event.EndTime,
|
||||
Thumbnail: event.Thumbnail,
|
||||
RequireKyc: event.EnableKYC,
|
||||
EnableKYC: event.EnableKYC,
|
||||
IsJoined: isJoined,
|
||||
JoinCount: joinCount,
|
||||
CheckinCount: checkinCount,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user