From 1d885feb1f1d71a3439b9251bc43f91506c95e07 Mon Sep 17 00:00:00 2001 From: Asai Neko Date: Sat, 31 Jan 2026 08:29:02 +0800 Subject: [PATCH] WIP Add join_event in service_event Signed-off-by: Asai Neko --- api/event/info.go | 10 +++--- data/attendance.go | 45 ++++++++++++++++--------- data/event.go | 13 ++----- data/user.go | 9 ----- docs/docs.go | 19 +++-------- docs/swagger.json | 19 +++-------- docs/swagger.yaml | 13 ++----- service/service_event/get_event_info.go | 21 +++++------- service/service_event/join_event.go | 17 ++++++++++ service/service_event/service.go | 1 + 10 files changed, 76 insertions(+), 91 deletions(-) create mode 100644 service/service_event/join_event.go diff --git a/api/event/info.go b/api/event/info.go index e0d143c..fcdcbd7 100644 --- a/api/event/info.go +++ b/api/event/info.go @@ -16,11 +16,11 @@ import ( // @Tags Event // @Accept json // @Produce json -// @Param event_id query string true "Event UUID" -// @Success 200 {object} utils.RespStatus{data=service_event.EventInfoResponse} "Successful retrieval" -// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" -// @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found" -// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" +// @Param event_id query string true "Event UUID" +// @Success 200 {object} utils.RespStatus{data=data.EventIndexDoc} "Successful retrieval" +// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" +// @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found" +// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" // @Security ApiKeyAuth // @Router /event/info [get] func (self *EventHandler) Info(c *gin.Context) { diff --git a/data/attendance.go b/data/attendance.go index 201beec..a42ced1 100644 --- a/data/attendance.go +++ b/data/attendance.go @@ -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 } diff --git a/data/event.go b/data/event.go index 674d39e..fcef9ae 100644 --- a/data/event.go +++ b/data/event.go @@ -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 diff --git a/data/user.go b/data/user.go index 5ce477b..80a6d1d 100644 --- a/data/user.go +++ b/data/user.go @@ -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 diff --git a/docs/docs.go b/docs/docs.go index ed9a89d..d07a48d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -809,7 +809,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/service_event.EventInfoResponse" + "$ref": "#/definitions/data.EventIndexDoc" } } } @@ -1280,6 +1280,9 @@ const docTemplate = `{ "start_time": { "type": "string" }, + "thumbnail": { + "type": "string" + }, "type": { "type": "string" } @@ -1415,20 +1418,6 @@ const docTemplate = `{ } } }, - "service_event.EventInfoResponse": { - "type": "object", - "properties": { - "end_time": { - "type": "string" - }, - "name": { - "type": "string" - }, - "start_time": { - "type": "string" - } - } - }, "service_user.UserInfoData": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 95fefa3..54024c0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -807,7 +807,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/service_event.EventInfoResponse" + "$ref": "#/definitions/data.EventIndexDoc" } } } @@ -1278,6 +1278,9 @@ "start_time": { "type": "string" }, + "thumbnail": { + "type": "string" + }, "type": { "type": "string" } @@ -1413,20 +1416,6 @@ } } }, - "service_event.EventInfoResponse": { - "type": "object", - "properties": { - "end_time": { - "type": "string" - }, - "name": { - "type": "string" - }, - "start_time": { - "type": "string" - } - } - }, "service_user.UserInfoData": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 09407bc..9d39a78 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -12,6 +12,8 @@ definitions: type: string start_time: type: string + thumbnail: + type: string type: type: string type: object @@ -98,15 +100,6 @@ definitions: checkin_code: type: string type: object - service_event.EventInfoResponse: - properties: - end_time: - type: string - name: - type: string - start_time: - type: string - type: object service_user.UserInfoData: properties: allow_public: @@ -591,7 +584,7 @@ paths: - $ref: '#/definitions/utils.RespStatus' - properties: data: - $ref: '#/definitions/service_event.EventInfoResponse' + $ref: '#/definitions/data.EventIndexDoc' type: object "400": description: Invalid Input diff --git a/service/service_event/get_event_info.go b/service/service_event/get_event_info.go index 87bfd8d..fbd71b8 100644 --- a/service/service_event/get_event_info.go +++ b/service/service_event/get_event_info.go @@ -5,7 +5,6 @@ import ( "nixcn-cms/data" "nixcn-cms/internal/exception" "nixcn-cms/service/shared" - "time" "github.com/google/uuid" ) @@ -19,15 +18,9 @@ type EventInfoPayload struct { Data *EventInfoData } -type EventInfoResponse struct { - Name string `json:"name"` - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` -} - type EventInfoResult struct { Common shared.CommonResult - Data *EventInfoResponse + Data *data.EventIndexDoc } func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *EventInfoResult) { @@ -63,10 +56,14 @@ func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *E SetOriginal(exception.CommonSuccess). Throw(payload.Context), }, - Data: &EventInfoResponse{ - Name: event.Name, - StartTime: event.StartTime, - EndTime: event.EndTime, + Data: &data.EventIndexDoc{ + EventId: event.EventId.String(), + Name: event.Name, + Type: event.Type, + Description: event.Description, + StartTime: event.StartTime, + EndTime: event.EndTime, + Thumbnail: event.Thumbnail, }, } diff --git a/service/service_event/join_event.go b/service/service_event/join_event.go new file mode 100644 index 0000000..bd22a4c --- /dev/null +++ b/service/service_event/join_event.go @@ -0,0 +1,17 @@ +package service_event + +import "nixcn-cms/service/shared" + +type EventJoinData struct { +} + +type EventJoinPayload struct { +} + +type EventJoinResult struct { + Common shared.CommonResult +} + +func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *EventJoinResult) { + return +} diff --git a/service/service_event/service.go b/service/service_event/service.go index 6d46708..ffe86a1 100644 --- a/service/service_event/service.go +++ b/service/service_event/service.go @@ -6,6 +6,7 @@ type EventService interface { CheckinQuery(*CheckinQueryPayload) *CheckinQueryResult GetEventInfo(*EventInfoPayload) *EventInfoResult ListEvents(*EventListPayload) *EventListResult + JoinEvent(*EventJoinPayload) *EventJoinResult } type EventServiceImpl struct{}