WIP Add join_event in service_event
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -20,7 +20,7 @@ type Attendance struct {
|
||||
EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||
UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||
Role string `json:"role" gorm:"type:varchar(255);not null"`
|
||||
State string `json:"state" gorm:"type:varchar(255);not null"`
|
||||
State string `json:"state" gorm:"type:varchar(255);not null"` // suspended | out_of_limit | success
|
||||
KycInfo string `json:"kyc_info" gorm:"type:text"`
|
||||
CheckinAt time.Time `json:"checkin_at"`
|
||||
}
|
||||
@@ -33,6 +33,31 @@ type AttendanceSearchDoc struct {
|
||||
CheckinAt time.Time `json:"checkin_at"`
|
||||
}
|
||||
|
||||
func (self *Attendance) SetEventId(s uuid.UUID) *Attendance {
|
||||
self.EventId = s
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Attendance) SetUserId(s uuid.UUID) *Attendance {
|
||||
self.UserId = s
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Attendance) SetRole(s string) *Attendance {
|
||||
self.Role = s
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Attendance) SetState(s string) *Attendance {
|
||||
self.State = s
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Attendance) SetKycInfo(s string) *Attendance {
|
||||
self.KycInfo = s
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Attendance) GetAttendance(ctx context.Context, userId, eventId uuid.UUID) (*Attendance, error) {
|
||||
var checkin Attendance
|
||||
|
||||
@@ -105,7 +130,7 @@ func (self *Attendance) Create(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Attendance) Update(ctx context.Context, attendanceId uuid.UUID, checkinTime *time.Time) (*Attendance, error) {
|
||||
func (self *Attendance) Update(ctx context.Context, attendanceId uuid.UUID) (*Attendance, error) {
|
||||
var attendance Attendance
|
||||
|
||||
err := Database.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
@@ -116,19 +141,9 @@ func (self *Attendance) Update(ctx context.Context, attendanceId uuid.UUID, chec
|
||||
return err
|
||||
}
|
||||
|
||||
updates := map[string]any{}
|
||||
|
||||
if checkinTime != nil {
|
||||
updates["checkin_at"] = *checkinTime
|
||||
}
|
||||
|
||||
if len(updates) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := tx.
|
||||
Model(&attendance).
|
||||
Updates(updates).Error; err != nil {
|
||||
Updates(self).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -196,8 +211,8 @@ func (self *Attendance) VerifyCheckinCode(ctx context.Context, checkinCode strin
|
||||
return err
|
||||
}
|
||||
|
||||
time := time.Now()
|
||||
_, err = self.Update(ctx, attendanceData.AttendanceId, &time)
|
||||
self.CheckinAt = time.Now()
|
||||
_, err = self.Update(ctx, attendanceData.AttendanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ type Event struct {
|
||||
UUID uuid.UUID `json:"uuid" gorm:"type:uuid;uniqueIndex;not null"`
|
||||
EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(255);index;not null"`
|
||||
Type string `json:"type" gotm:"type:varchar(255);index;not null"`
|
||||
Type string `json:"type" gotm:"type:varchar(255);index;not null"` // official | party
|
||||
Description string `json:"description" gorm:"type:text;not null"`
|
||||
StartTime time.Time `json:"start_time" gorm:"index"`
|
||||
EndTime time.Time `json:"end_time" gorm:"index"`
|
||||
Thumbnail string `json:"thumbnail" gorm:"type:varchar(255)"`
|
||||
Owner uuid.UUID `json:"owner" gorm:"type:uuid;index;not null"`
|
||||
EnableKYC bool `json:"enable_kyc" gorm:"not null"`
|
||||
}
|
||||
@@ -28,6 +29,7 @@ type EventIndexDoc struct {
|
||||
Description string `json:"description"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime time.Time `json:"end_time"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
}
|
||||
|
||||
func (self *Event) GetEventById(ctx context.Context, eventId uuid.UUID) (*Event, error) {
|
||||
@@ -86,15 +88,6 @@ func (self *Event) Create(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Event) GetFullTable(ctx context.Context) (*[]Event, error) {
|
||||
var events []Event
|
||||
err := Database.WithContext(ctx).Find(&events).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &events, err
|
||||
}
|
||||
|
||||
func (self *Event) FastListEvents(ctx context.Context, limit, offset int64) (*[]EventIndexDoc, error) {
|
||||
var results []EventIndexDoc
|
||||
|
||||
|
||||
@@ -135,15 +135,6 @@ func (self *User) UpdateByUserID(ctx context.Context, userId *uuid.UUID, updates
|
||||
})
|
||||
}
|
||||
|
||||
func (self *User) GetFullTable(ctx context.Context) (*[]User, error) {
|
||||
var users []User
|
||||
err := Database.WithContext(ctx).Find(&users).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &users, nil
|
||||
}
|
||||
|
||||
func (self *User) FastListUsers(ctx context.Context, limit, offset *int) (*[]UserIndexDoc, error) {
|
||||
var results []UserIndexDoc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user