Add agenda service and submit api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -14,6 +14,7 @@ type Agenda struct {
|
||||
AttendanceId uuid.UUID `json:"attendance_id" gorm:"type:uuid;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(255);not null"`
|
||||
Description string `json:"description" gorm:"type:text;not null"`
|
||||
IsApproved bool `json:"is_approved" gorm:"type:boolean;default:false"`
|
||||
}
|
||||
|
||||
func (self *Agenda) SetAttendanceId(id uuid.UUID) *Agenda {
|
||||
@@ -31,6 +32,11 @@ func (self *Agenda) SetDescription(desc string) *Agenda {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Agenda) SetIsApproved(approved bool) *Agenda {
|
||||
self.IsApproved = approved
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Agenda) GetByAgendaId(ctx context.Context, agendaId uuid.UUID) (*Agenda, error) {
|
||||
var agenda Agenda
|
||||
|
||||
|
||||
@@ -59,11 +59,11 @@ func (self *Attendance) SetState(s string) *Attendance {
|
||||
}
|
||||
|
||||
func (self *Attendance) GetAttendance(ctx context.Context, userId, eventId uuid.UUID) (*Attendance, error) {
|
||||
var checkin Attendance
|
||||
var attendance Attendance
|
||||
|
||||
err := Database.WithContext(ctx).
|
||||
Where("user_id = ? AND event_id = ?", userId, eventId).
|
||||
First(&checkin).Error
|
||||
First(&attendance).Error
|
||||
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -72,7 +72,7 @@ func (self *Attendance) GetAttendance(ctx context.Context, userId, eventId uuid.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &checkin, err
|
||||
return &attendance, err
|
||||
}
|
||||
|
||||
type AttendanceUsers struct {
|
||||
|
||||
@@ -110,3 +110,33 @@ func (self *Event) FastListEvents(ctx context.Context, limit, offset int64) (*[]
|
||||
|
||||
return &results, nil
|
||||
}
|
||||
|
||||
func (self *Event) GetEventsByUserId(ctx context.Context, userId uuid.UUID, limit, offset int64) (*[]EventIndexDoc, error) {
|
||||
var results []EventIndexDoc
|
||||
|
||||
err := Database.WithContext(ctx).
|
||||
Table("events").
|
||||
Select(`
|
||||
events.event_id,
|
||||
events.name,
|
||||
events.type,
|
||||
events.description,
|
||||
events.start_time,
|
||||
events.end_time,
|
||||
events.thumbnail,
|
||||
events.enable_kyc,
|
||||
(SELECT COUNT(*) FROM attendances WHERE attendances.event_id = events.event_id) as join_count
|
||||
`).
|
||||
Joins("JOIN attendances ON attendances.event_id = events.event_id").
|
||||
Where("attendances.user_id = ?", userId).
|
||||
Order("events.start_time DESC").
|
||||
Limit(int(limit)).
|
||||
Offset(int(offset)).
|
||||
Scan(&results).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &results, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user