From f05cfb09d9371a87704a9e32bd410e44f679769d Mon Sep 17 00:00:00 2001 From: Asai Neko Date: Thu, 4 Jun 2026 21:41:28 +0800 Subject: [PATCH] Add user profile response for schedule_get service Signed-off-by: Asai Neko --- api/agenda/schedule_get.go | 2 +- docs/docs.go | 30 +------------- docs/swagger.json | 30 +------------- docs/swagger.yaml | 26 +++---------- service/service_agenda/schedule_get.go | 54 +++++++++++++++++++++++++- 5 files changed, 62 insertions(+), 80 deletions(-) diff --git a/api/agenda/schedule_get.go b/api/agenda/schedule_get.go index fc1b9ec..20568ae 100644 --- a/api/agenda/schedule_get.go +++ b/api/agenda/schedule_get.go @@ -19,7 +19,7 @@ import ( // @Produce json // @Security Bearer // @Param event_id query string true "Event ID" -// @Success 200 {object} utils.RespStatus{data=[]data.AgendaDoc} +// @Success 200 {object} utils.RespStatus{data=[]service_agenda.AgendaListItem} // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" // @Failure 403 {object} utils.RespStatus{data=nil} "Agenda Not Published" // @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found" diff --git a/docs/docs.go b/docs/docs.go index b678d48..98982d0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -415,7 +415,7 @@ const docTemplate = `{ "data": { "type": "array", "items": { - "$ref": "#/definitions/data.AgendaDoc" + "$ref": "#/definitions/service_agenda.AgendaListItem" } } } @@ -2631,7 +2631,7 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "Allows the event owner (Manager) to update name, subtitle, description, start_time, end_time, thumbnail, and is_agenda_published. Changes to type or enable_kyc are rejected. is_agenda_published is write-once: it can only be set to true (requires at least one agenda submission) and cannot be reverted.", + "description": "Allows the event owner (Manager) to update name, subtitle, description, start_time, end_time, thumbnail, and is_agenda_published. Lv40+ users (admins) bypass the owner restriction and may update any event. Changes to type or enable_kyc are rejected. is_agenda_published is write-once: it can only be set to true (requires at least one agenda submission) and cannot be reverted.", "consumes": [ "application/json" ], @@ -3664,32 +3664,6 @@ const docTemplate = `{ } } }, - "data.AgendaDoc": { - "type": "object", - "properties": { - "agenda_id": { - "type": "string" - }, - "attendance_id": { - "type": "string" - }, - "description": { - "type": "string" - }, - "end_time": { - "type": "string" - }, - "name": { - "type": "string" - }, - "start_time": { - "type": "string" - }, - "status": { - "type": "string" - } - } - }, "data.EventStatDoc": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index f7a018d..f56ad15 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -413,7 +413,7 @@ "data": { "type": "array", "items": { - "$ref": "#/definitions/data.AgendaDoc" + "$ref": "#/definitions/service_agenda.AgendaListItem" } } } @@ -2629,7 +2629,7 @@ "Bearer": [] } ], - "description": "Allows the event owner (Manager) to update name, subtitle, description, start_time, end_time, thumbnail, and is_agenda_published. Changes to type or enable_kyc are rejected. is_agenda_published is write-once: it can only be set to true (requires at least one agenda submission) and cannot be reverted.", + "description": "Allows the event owner (Manager) to update name, subtitle, description, start_time, end_time, thumbnail, and is_agenda_published. Lv40+ users (admins) bypass the owner restriction and may update any event. Changes to type or enable_kyc are rejected. is_agenda_published is write-once: it can only be set to true (requires at least one agenda submission) and cannot be reverted.", "consumes": [ "application/json" ], @@ -3662,32 +3662,6 @@ } } }, - "data.AgendaDoc": { - "type": "object", - "properties": { - "agenda_id": { - "type": "string" - }, - "attendance_id": { - "type": "string" - }, - "description": { - "type": "string" - }, - "end_time": { - "type": "string" - }, - "name": { - "type": "string" - }, - "start_time": { - "type": "string" - }, - "status": { - "type": "string" - } - } - }, "data.EventStatDoc": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2a827df..e58627c 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -23,23 +23,6 @@ definitions: uuid: type: string type: object - data.AgendaDoc: - properties: - agenda_id: - type: string - attendance_id: - type: string - description: - type: string - end_time: - type: string - name: - type: string - start_time: - type: string - status: - type: string - type: object data.EventStatDoc: properties: checkin_count: @@ -804,7 +787,7 @@ paths: - properties: data: items: - $ref: '#/definitions/data.AgendaDoc' + $ref: '#/definitions/service_agenda.AgendaListItem' type: array type: object "400": @@ -2018,9 +2001,10 @@ paths: consumes: - application/json description: 'Allows the event owner (Manager) to update name, subtitle, description, - start_time, end_time, thumbnail, and is_agenda_published. Changes to type - or enable_kyc are rejected. is_agenda_published is write-once: it can only - be set to true (requires at least one agenda submission) and cannot be reverted.' + start_time, end_time, thumbnail, and is_agenda_published. Lv40+ users (admins) + bypass the owner restriction and may update any event. Changes to type or + enable_kyc are rejected. is_agenda_published is write-once: it can only be + set to true (requires at least one agenda submission) and cannot be reverted.' parameters: - description: Fields to update (all optional except event_id) in: body diff --git a/service/service_agenda/schedule_get.go b/service/service_agenda/schedule_get.go index 404bcbc..94de59d 100644 --- a/service/service_agenda/schedule_get.go +++ b/service/service_agenda/schedule_get.go @@ -7,6 +7,7 @@ import ( "nixcn-cms/internal/exception" "nixcn-cms/service/shared" "nixcn-cms/tracer" + "time" "github.com/google/uuid" ) @@ -22,7 +23,7 @@ type AgendaScheduleGetPayload struct { type AgendaScheduleGetResult struct { Common shared.CommonResult - Data *[]data.AgendaDoc + Data *[]AgendaListItem } func (self *AgendaServiceImpl) ScheduleGet(payload *AgendaScheduleGetPayload) (result *AgendaScheduleGetResult) { @@ -93,6 +94,55 @@ func (self *AgendaServiceImpl) ScheduleGet(payload *AgendaScheduleGetPayload) (r return } + attendanceIds := make([]uuid.UUID, 0, len(*agendas)) + for _, a := range *agendas { + attendanceIds = append(attendanceIds, a.AttendanceId) + } + + userProfiles, err := new(data.Attendance).GetUserProfilesByAttendanceIds(ctx, attendanceIds) + if err != nil { + exc := exception.New( + exception.WithStatus(exception.StatusServer), + exception.WithType(exception.TypeCommon), + exception.WithOriginal(exception.CommonErrorDatabase), + exception.WithError(err), + ).Throw(ctx) + + result = &AgendaScheduleGetResult{ + Common: shared.CommonResult{HttpCode: 500, Exception: exc}, + } + return + } + + zero := time.Time{} + items := make([]AgendaListItem, 0, len(*agendas)) + for _, a := range *agendas { + profile := userProfiles[a.AttendanceId] + + var startTime, endTime *time.Time + if a.StartTime != zero { + startTime = &a.StartTime + } + if a.EndTime != zero { + endTime = &a.EndTime + } + + items = append(items, AgendaListItem{ + AgendaId: a.AgendaId, + AttendanceId: a.AttendanceId, + Name: a.Name, + Description: a.Description, + Status: a.Status, + StartTime: startTime, + EndTime: endTime, + UserProfile: &AgendaUserProfile{ + UserId: profile.UserId, + Nickname: profile.Nickname, + Username: profile.Username, + }, + }) + } + exc := exception.New( exception.WithStatus(exception.StatusSuccess), exception.WithType(exception.TypeCommon), @@ -101,7 +151,7 @@ func (self *AgendaServiceImpl) ScheduleGet(payload *AgendaScheduleGetPayload) (r result = &AgendaScheduleGetResult{ Common: shared.CommonResult{HttpCode: 200, Exception: exc}, - Data: agendas, + Data: &items, } return } -- 2.49.1