From 67e2cbbd04fc8285596ccbde23e4252fecb49512 Mon Sep 17 00:00:00 2001 From: Asai Neko Date: Fri, 6 Feb 2026 10:30:28 +0800 Subject: [PATCH] Add attendance id resp for event join api, set root api to /app/api/v1 Signed-off-by: Asai Neko --- api/event/join.go | 14 +++++++------- data/attendance.go | 6 +++--- docs/docs.go | 10 +++++++++- docs/swagger.json | 10 +++++++++- docs/swagger.yaml | 7 ++++++- server/server.go | 4 ++-- service/service_event/join_event.go | 19 ++++++++++++++++++- 7 files changed, 54 insertions(+), 16 deletions(-) diff --git a/api/event/join.go b/api/event/join.go index 05ae356..7f6a567 100644 --- a/api/event/join.go +++ b/api/event/join.go @@ -15,13 +15,13 @@ import ( // @Tags Event // @Accept json // @Produce json -// @Param request body service_event.EventJoinData true "Event Join Details (UserId and EventId are required)" -// @Param X-Api-Version header string true "latest" -// @Success 200 {object} utils.RespStatus{data=nil} "Successfully joined the event" -// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input or UUID Parse Failed" -// @Failure 401 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized" -// @Failure 403 {object} utils.RespStatus{data=nil} "Unauthorized / Missing User ID / Event Limit Exceeded" -// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error / Database Error" +// @Param request body service_event.EventJoinData true "Event Join Details (UserId and EventId are required)" +// @Param X-Api-Version header string true "latest" +// @Success 200 {object} utils.RespStatus{data=service_event.EventJoinResponse} "Successfully joined the event" +// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input or UUID Parse Failed" +// @Failure 401 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized" +// @Failure 403 {object} utils.RespStatus{data=nil} "Unauthorized / Missing User ID / Event Limit Exceeded" +// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error / Database Error" // @Security ApiKeyAuth // @Router /event/join [post] func (self *EventHandler) Join(c *gin.Context) { diff --git a/data/attendance.go b/data/attendance.go index 343b23d..ad90c07 100644 --- a/data/attendance.go +++ b/data/attendance.go @@ -112,7 +112,7 @@ func (self *Attendance) GetEventsByUserID(ctx context.Context, userID uuid.UUID) return &result, err } -func (self *Attendance) Create(ctx context.Context) error { +func (self *Attendance) Create(ctx context.Context) (uuid.UUID, error) { self.UUID = uuid.New() self.AttendanceId = uuid.New() @@ -124,10 +124,10 @@ func (self *Attendance) Create(ctx context.Context) error { return nil }) if err != nil { - return err + return uuid.Nil, err } - return nil + return self.AttendanceId, nil } func (self *Attendance) GetAttendanceListByEventId(ctx context.Context, eventId uuid.UUID) (*[]Attendance, error) { diff --git a/docs/docs.go b/docs/docs.go index 88fb2d8..a647eb3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1104,7 +1104,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "type": "object" + "$ref": "#/definitions/service_event.EventJoinResponse" } } } @@ -2186,6 +2186,14 @@ const docTemplate = `{ } } }, + "service_event.EventJoinResponse": { + "type": "object", + "properties": { + "attendance_id": { + "type": "string" + } + } + }, "service_kyc.KycQueryData": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 2bb23c4..7c2f80c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1102,7 +1102,7 @@ "type": "object", "properties": { "data": { - "type": "object" + "$ref": "#/definitions/service_event.EventJoinResponse" } } } @@ -2184,6 +2184,14 @@ } } }, + "service_event.EventJoinResponse": { + "type": "object", + "properties": { + "attendance_id": { + "type": "string" + } + } + }, "service_kyc.KycQueryData": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 1bdf44b..3636865 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -125,6 +125,11 @@ definitions: kyc_id: type: string type: object + service_event.EventJoinResponse: + properties: + attendance_id: + type: string + type: object service_kyc.KycQueryData: properties: kyc_id: @@ -808,7 +813,7 @@ paths: - $ref: '#/definitions/utils.RespStatus' - properties: data: - type: object + $ref: '#/definitions/service_event.EventJoinResponse' type: object "400": description: Invalid Input or UUID Parse Failed diff --git a/server/server.go b/server/server.go index 70d649c..d868de1 100644 --- a/server/server.go +++ b/server/server.go @@ -28,7 +28,7 @@ import ( // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @host localhost:8000 -// @BasePath /api/v1 +// @BasePath /app/api/v1 // @schemes http https func Start(ctx context.Context) { if !viper.GetBool("server.debug_mode") { @@ -46,7 +46,7 @@ func Start(ctx context.Context) { r.Use(gin.Recovery()) - api.Handler(r.Group("/api/v1")) + api.Handler(r.Group("/app/api/v1")) // Start http server server := &http.Server{ diff --git a/service/service_event/join_event.go b/service/service_event/join_event.go index 0718fce..8ef8c4d 100644 --- a/service/service_event/join_event.go +++ b/service/service_event/join_event.go @@ -24,8 +24,13 @@ type EventJoinPayload struct { Data *EventJoinData } +type EventJoinResponse struct { + AttendanceId string `json:"attendance_id"` +} + type EventJoinResult struct { Common shared.CommonResult + Data *EventJoinResponse } func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *EventJoinResult) { @@ -49,6 +54,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even HttpCode: 400, Exception: exception, }, + Data: nil, } return @@ -71,6 +77,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even HttpCode: 500, Exception: exception, }, + Data: nil, } return @@ -91,6 +98,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even HttpCode: 400, Exception: exception, }, + Data: nil, } return @@ -112,6 +120,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even HttpCode: 400, Exception: exception, }, + Data: nil, } return @@ -132,6 +141,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even SetError(err). Throw(payload.Context), }, + Data: nil, } } @@ -148,6 +158,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even SetError(errors.New("user already joined this event")). Throw(payload.Context), }, + Data: nil, } } @@ -167,6 +178,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even SetError(err). Throw(payload.Context), }, + Data: nil, } } @@ -184,6 +196,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even SetError(errors.New("event limit exceeded")). Throw(payload.Context), }, + Data: nil, } } attendenceData.SetState("out_of_limit") @@ -192,7 +205,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even } attendenceData.SetRole("normal") - err = attendenceData.Create(payload.Context) + attendanceId, err := attendenceData.Create(payload.Context) if err != nil { return &EventJoinResult{ Common: shared.CommonResult{ @@ -206,6 +219,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even SetError(err). Throw(payload.Context), }, + Data: nil, } } @@ -223,6 +237,9 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even HttpCode: 200, Exception: exception, }, + Data: &EventJoinResponse{ + AttendanceId: attendanceId.String(), + }, } return