From e5418bc360054f83a38ca3c60b0e74419a7a0f18 Mon Sep 17 00:00:00 2001 From: AdamHo2028 Date: Sun, 27 Apr 2025 15:55:07 -0700 Subject: [PATCH] fixed handling, added documentation for updateAnnouncement and deleteAnnouncement --- docs/docs.go | 54 +++++++++++++++++-- docs/swagger.json | 54 +++++++++++++++++-- docs/swagger.yaml | 39 ++++++++++++-- internal/api/handlers/announcement_handler.go | 19 +++++++ internal/api/handlers/events_handler.go | 6 +-- internal/api/routes/routes.go | 2 +- internal/api/services/announcement_service.go | 1 + internal/db/models/board.sql.go | 34 ++++++++++-- 8 files changed, 191 insertions(+), 18 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 120fa08..9e9ab4c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -15,6 +15,54 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/announcement/:id": { + "put": { + "description": "Updates the Announcement of choice in the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Announcements" + ], + "summary": "Updates the Announcement of Choice", + "parameters": [ + { + "type": "string", + "description": "Announcement ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} + }, + "delete": { + "description": "Deletes the Announcement of choice in the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Announcements" + ], + "summary": "Deletes the Announcement of Choice", + "parameters": [ + { + "type": "string", + "description": "Event ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} + } + }, "/announcements": { "post": { "description": "Creates a new announcement and generates unique ID", @@ -58,7 +106,7 @@ const docTemplate = `{ }, "/events": { "get": { - "description": "Gets all the events from the event database", + "description": "Get all the events from the event database", "consumes": [ "application/json" ], @@ -68,7 +116,7 @@ const docTemplate = `{ "tags": [ "Events" ], - "summary": "Gets all the events", + "summary": "Get all the events", "responses": {} }, "post": { @@ -121,7 +169,7 @@ const docTemplate = `{ "tags": [ "Events" ], - "summary": "Update the Event of Choice", + "summary": "Updates the Event of Choice", "parameters": [ { "type": "string", diff --git a/docs/swagger.json b/docs/swagger.json index 4e3085b..3988683 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4,6 +4,54 @@ "contact": {} }, "paths": { + "/announcement/:id": { + "put": { + "description": "Updates the Announcement of choice in the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Announcements" + ], + "summary": "Updates the Announcement of Choice", + "parameters": [ + { + "type": "string", + "description": "Announcement ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} + }, + "delete": { + "description": "Deletes the Announcement of choice in the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Announcements" + ], + "summary": "Deletes the Announcement of Choice", + "parameters": [ + { + "type": "string", + "description": "Event ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} + } + }, "/announcements": { "post": { "description": "Creates a new announcement and generates unique ID", @@ -47,7 +95,7 @@ }, "/events": { "get": { - "description": "Gets all the events from the event database", + "description": "Get all the events from the event database", "consumes": [ "application/json" ], @@ -57,7 +105,7 @@ "tags": [ "Events" ], - "summary": "Gets all the events", + "summary": "Get all the events", "responses": {} }, "post": { @@ -110,7 +158,7 @@ "tags": [ "Events" ], - "summary": "Update the Event of Choice", + "summary": "Updates the Event of Choice", "parameters": [ { "type": "string", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d01d36f..510c1a6 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,6 +1,39 @@ info: contact: {} paths: + /announcement/:id: + delete: + consumes: + - application/json + description: Deletes the Announcement of choice in the database + parameters: + - description: Event ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: {} + summary: Deletes the Announcement of Choice + tags: + - Announcements + put: + consumes: + - application/json + description: Updates the Announcement of choice in the database + parameters: + - description: Announcement ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: {} + summary: Updates the Announcement of Choice + tags: + - Announcements /announcements: post: consumes: @@ -33,11 +66,11 @@ paths: get: consumes: - application/json - description: Gets all the events from the event database + description: Get all the events from the event database produces: - application/json responses: {} - summary: Gets all the events + summary: Get all the events tags: - Events post: @@ -96,7 +129,7 @@ paths: produces: - application/json responses: {} - summary: Update the Event of Choice + summary: Updates the Event of Choice tags: - Events swagger: "2.0" diff --git a/internal/api/handlers/announcement_handler.go b/internal/api/handlers/announcement_handler.go index 4e2bdab..b7071f6 100644 --- a/internal/api/handlers/announcement_handler.go +++ b/internal/api/handlers/announcement_handler.go @@ -78,9 +78,28 @@ func (h *AnnouncementHandler) CreateAnnouncement(c *gin.Context) { }) } +// UpdateAnnouncement godoc +// +// @Summary Updates the Announcement of Choice +// @Description Updates the Announcement of choice in the database +// @Tags Announcements +// @Accept json +// @Produce json +// @Param id path string true "Announcement ID" +// @Router /announcement/:id [Put] func (h *AnnouncementHandler) UpdateAnnouncement(c *gin.Context) { panic("implement me (UpdateAnnouncement Handler)") } + +// DeleteAnnouncement godoc +// +// @Summary Deletes the Announcement of Choice +// @Description Deletes the Announcement of choice in the database +// @Tags Announcements +// @Accept json +// @Produce json +// @Param id path string true "Event ID" +// @Router /announcement/:id [Delete] func (h *AnnouncementHandler) DeleteAnnouncement(c *gin.Context) { panic("implement me (DeleteAnnouncement Handler)") } diff --git a/internal/api/handlers/events_handler.go b/internal/api/handlers/events_handler.go index 087ea6b..b5b6b3c 100644 --- a/internal/api/handlers/events_handler.go +++ b/internal/api/handlers/events_handler.go @@ -93,8 +93,8 @@ func (h *EventsHandler) CreateEvent(c *gin.Context) { // GetEvents godoc // -// @Summary Gets all the events -// @Description Gets all the events from the event database +// @Summary Get all the events +// @Description Get all the events from the event database // @Tags Events // @Accept json // @Produce json @@ -120,7 +120,7 @@ func (h *EventsHandler) GetEvents(c *gin.Context) { // UpdateEvent godoc // -// @Summary Update the Event of Choice +// @Summary Updates the Event of Choice // @Description Updates the event of choice in the database // @Tags Events // @Accept json diff --git a/internal/api/routes/routes.go b/internal/api/routes/routes.go index 8d6d750..cefdaa3 100644 --- a/internal/api/routes/routes.go +++ b/internal/api/routes/routes.go @@ -17,6 +17,6 @@ func SetupRoutes(router *gin.Engine, eventService *services.EventsService, annou announcementHandler := handlers.NewAnnouncementHandler(announcementService) router.GET("/announcement/:id", announcementHandler.GetAnnouncement) router.POST("/announcement", announcementHandler.CreateAnnouncement) - router.POST("/announcement/:id", announcementHandler.DeleteAnnouncement) + router.DELETE("/announcement/:id", announcementHandler.DeleteAnnouncement) router.POST("/announcement/:id", announcementHandler.UpdateAnnouncement) } diff --git a/internal/api/services/announcement_service.go b/internal/api/services/announcement_service.go index 09e1cc5..4dd1a0c 100644 --- a/internal/api/services/announcement_service.go +++ b/internal/api/services/announcement_service.go @@ -55,6 +55,7 @@ func (s *AnnouncementService) List(ctx context.Context, filters ...any) ([]model return result, nil } +// partially implemented func (s *AnnouncementService) Update(ctx context.Context, uuid string, params models.UpdateAnnouncementParams) error { err := s.q.UpdateAnnouncement(ctx, params) if err != nil { diff --git a/internal/db/models/board.sql.go b/internal/db/models/board.sql.go index 3c50f33..7ac0537 100644 --- a/internal/db/models/board.sql.go +++ b/internal/db/models/board.sql.go @@ -144,7 +144,7 @@ func (q *Queries) GetOfficer(ctx context.Context, uuid interface{}) (GetOfficerR return i, err } -const getPositions = `-- name: GetPositions :one +const getPosition = `-- name: GetPosition :one SELECT positions.semester, tiers.title, @@ -158,15 +158,39 @@ INNER JOIN tiers WHERE officers.full_name = ? ` -type GetPositionsRow struct { +type GetPositionRow struct { Semester interface{} `json:"semester"` Title sql.NullString `json:"title"` Team sql.NullString `json:"team"` } -func (q *Queries) GetPositions(ctx context.Context, fullName string) (GetPositionsRow, error) { - row := q.db.QueryRowContext(ctx, getPositions, fullName) - var i GetPositionsRow +func (q *Queries) GetPosition(ctx context.Context, fullName string) (GetPositionRow, error) { + row := q.db.QueryRowContext(ctx, getPosition, fullName) + var i GetPositionRow err := row.Scan(&i.Semester, &i.Title, &i.Team) return i, err } + +const getTier = `-- name: GetTier :one +SELECT + tier, + title, + t_index, + team +FROM + tiers +WHERE + tier = ? +` + +func (q *Queries) GetTier(ctx context.Context, tier int64) (Tier, error) { + row := q.db.QueryRowContext(ctx, getTier, tier) + var i Tier + err := row.Scan( + &i.Tier, + &i.Title, + &i.TIndex, + &i.Team, + ) + return i, err +}