From 0751780ed7ea4969c21b905e7af82d54a664919b Mon Sep 17 00:00:00 2001 From: Josh Holman Date: Wed, 21 Oct 2026 16:11:46 -0700 Subject: [PATCH] goodbye! --- README.md | 3 +- fixtures/README.md | 22 +- fixtures/announcement_create.json | 13 - fixtures/announcement_create_basic.json | 13 - fixtures/announcement_create_no_discord.json | 13 - fixtures/announcement_create_private.json | 13 - fixtures/announcement_update.json | 16 -- internal/api/docs/docs.go | 263 ------------------ internal/api/docs/swagger.json | 263 ------------------ internal/api/docs/swagger.yaml | 174 ------------ internal/api/handlers/announcement.go | 195 ------------- internal/api/routes/v1.go | 10 +- internal/api/server.go | 3 +- internal/api/services/announcement.go | 95 ------- internal/api/store/announcements_mapper.go | 38 --- .../api/store/dbmodels/announcement.sql.go | 151 ---------- internal/api/store/dbmodels/models.go | 8 - internal/cli/command/announcements/delete.go | 42 --- internal/cli/command/announcements/get.go | 41 --- internal/cli/command/announcements/post.go | 99 ------- internal/cli/command/announcements/put.go | 122 -------- internal/cli/command/announcements/root.go | 17 -- internal/cli/command/root.go | 2 - internal/domain/announcements.go | 25 -- internal/dto/announcement.go | 64 ----- .../000001_create_announcements.down.sql | 3 - .../000001_create_announcements.up.sql | 11 - sql/queries/announcement.sql | 49 ---- 28 files changed, 4 insertions(+), 1764 deletions(-) delete mode 100644 fixtures/announcement_create.json delete mode 100644 fixtures/announcement_create_basic.json delete mode 100644 fixtures/announcement_create_no_discord.json delete mode 100644 fixtures/announcement_create_private.json delete mode 100644 fixtures/announcement_update.json delete mode 100644 internal/api/handlers/announcement.go delete mode 100644 internal/api/services/announcement.go delete mode 100644 internal/api/store/announcements_mapper.go delete mode 100644 internal/api/store/dbmodels/announcement.sql.go delete mode 100644 internal/cli/command/announcements/delete.go delete mode 100644 internal/cli/command/announcements/get.go delete mode 100644 internal/cli/command/announcements/post.go delete mode 100644 internal/cli/command/announcements/put.go delete mode 100644 internal/cli/command/announcements/root.go delete mode 100644 internal/domain/announcements.go delete mode 100644 internal/dto/announcement.go delete mode 100644 sql/migrations/000001_create_announcements.down.sql delete mode 100644 sql/migrations/000001_create_announcements.up.sql delete mode 100644 sql/queries/announcement.sql diff --git a/README.md b/README.md index 91dd81bb..029ecfe7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # api.acmcsuf.com -ACM at CSUF club API for managing events, announcements, forms, and other services! Keep reading for information on setting up this project locally, and see the [contributor guide](./docs/CONTRIBUTING.md) and [`docs/`](./docs) for more information on using and contributing to this project. +ACM at CSUF club API for managing events, forms, and other services! Keep reading for information on setting up this project locally, and see the [contributor guide](./docs/CONTRIBUTING.md) and [`docs/`](./docs) for more information on using and contributing to this project. --- @@ -45,7 +45,6 @@ Usage: acmcsuf-cli [command] Available Commands: - announcements Manage ACM CSUF's Announcements completion Generate the autocompletion script for the specified shell events A command to manage events. help Help about any command diff --git a/fixtures/README.md b/fixtures/README.md index b98cf524..e451505d 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -6,7 +6,7 @@ This directory contains JSON payloads for testing the ACM CSUF API endpoints. Fixtures are named using the pattern: `{resource}_{action}_{variant}.json` -- `resource`: The API resource (event, announcement, officer, tier, position) +- `resource`: The API resource (event, officer, tier, position) - `action`: The operation (create, update, delete) - `variant`: Optional descriptor for the specific test case @@ -23,17 +23,6 @@ Fixtures are named using the pattern: `{resource}_{action}_{variant}.json` - `event_update_location.json` - Update only the location field - `event_update_full.json` - Full update with all fields -## Announcements - -### Create Operations -- `announcement_create_basic.json` - Basic announcement with Discord integration -- `announcement_create.json` - Public announcement with full Discord details -- `announcement_create_private.json` - Private announcement for officers -- `announcement_create_no_discord.json` - Website-only announcement without Discord - -### Update Operations -- `announcement_update.json` - Update announcement visibility and Discord info - ## Board Members ### Officers @@ -126,15 +115,6 @@ xh GET :8080/v1/events # Filter events by host xh GET :8080/v1/events host==ACM -# Create an announcement -xh POST :8080/v1/announcements < fixtures/announcement_create.json - -# Update an announcement -xh PUT :8080/v1/announcements/spring-kickoff-2024 < fixtures/announcement_update.json - -# Delete an announcement -xh DELETE :8080/v1/announcements/spring-kickoff-2024 - # Create an officer xh POST :8080/v1/board/officers < fixtures/officer_create.json diff --git a/fixtures/announcement_create.json b/fixtures/announcement_create.json deleted file mode 100644 index b31142de..00000000 --- a/fixtures/announcement_create.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "uuid": "spring-kickoff-2024", - "visibility": "public", - "announce_at": 1712851200000, - "discord_channel_id": { - "string": "1234567890123456789", - "valid": true - }, - "discord_message_id": { - "string": "9876543210987654321", - "valid": true - } -} diff --git a/fixtures/announcement_create_basic.json b/fixtures/announcement_create_basic.json deleted file mode 100644 index c7d98c59..00000000 --- a/fixtures/announcement_create_basic.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "uuid": "big-announcement", - "visibility": "public", - "announce_at": 1712851200000, - "discord_channel_id": { - "string": "chan-id", - "valid": true - }, - "discord_message_id": { - "string": "message-id", - "valid": true - } -} diff --git a/fixtures/announcement_create_no_discord.json b/fixtures/announcement_create_no_discord.json deleted file mode 100644 index c141cdc4..00000000 --- a/fixtures/announcement_create_no_discord.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "uuid": "website-announcement", - "visibility": "public", - "announce_at": 1713110400000, - "discord_channel_id": { - "string": "", - "valid": false - }, - "discord_message_id": { - "string": "", - "valid": false - } -} diff --git a/fixtures/announcement_create_private.json b/fixtures/announcement_create_private.json deleted file mode 100644 index 7085cf10..00000000 --- a/fixtures/announcement_create_private.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "uuid": "officer-meeting-reminder", - "visibility": "private", - "announce_at": 1712880000000, - "discord_channel_id": { - "string": "officer-channel-id", - "valid": true - }, - "discord_message_id": { - "string": "", - "valid": false - } -} diff --git a/fixtures/announcement_update.json b/fixtures/announcement_update.json deleted file mode 100644 index f8094e8e..00000000 --- a/fixtures/announcement_update.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "uuid": "spring-kickoff-2024", - "visibility": { - "string": "members", - "valid": true - }, - "announce_at": 1712865600000, - "discord_channel_id": { - "string": "updated-channel-id", - "valid": true - }, - "discord_message_id": { - "string": "updated-message-id", - "valid": true - } -} diff --git a/internal/api/docs/docs.go b/internal/api/docs/docs.go index 67f7d10f..d64bed71 100644 --- a/internal/api/docs/docs.go +++ b/internal/api/docs/docs.go @@ -15,229 +15,6 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/v1/announcements": { - "post": { - "description": "Creates a new announcement and generates unique ID", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Announcements" - ], - "summary": "Create new Announcement", - "parameters": [ - { - "description": "Announcement data", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.Announcement" - } - } - ], - "responses": { - "200": { - "description": "Success message with UUID", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/v1/announcements/{id}": { - "get": { - "description": "Retrieves a single announcement from the database.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Announcements" - ], - "summary": "Get an announcement by ID", - "parameters": [ - { - "type": "string", - "description": "Announcement ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Announcement details", - "schema": { - "$ref": "#/definitions/dto.Announcement" - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "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 - }, - { - "description": "Updated announcement data", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.UpdateAnnouncement" - } - } - ], - "responses": { - "200": { - "description": "Success message", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "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": "Announcement ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Success message", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, "/v1/board/officers": { "get": { "description": "Get all officers from the database", @@ -1294,26 +1071,6 @@ const docTemplate = `{ } }, "definitions": { - "dto.Announcement": { - "type": "object", - "properties": { - "announce_at": { - "type": "integer" - }, - "discord_channel_id": { - "type": "string" - }, - "discord_message_id": { - "type": "string" - }, - "uuid": { - "type": "string" - }, - "visibility": { - "type": "string" - } - } - }, "dto.DeletePosition": { "type": "object", "properties": { @@ -1411,26 +1168,6 @@ const docTemplate = `{ } } }, - "dto.UpdateAnnouncement": { - "type": "object", - "properties": { - "announce_at": { - "type": "integer" - }, - "discord_channel_id": { - "type": "string" - }, - "discord_message_id": { - "type": "string" - }, - "uuid": { - "type": "string" - }, - "visibility": { - "type": "string" - } - } - }, "dto.UpdateEvent": { "type": "object", "properties": { diff --git a/internal/api/docs/swagger.json b/internal/api/docs/swagger.json index 269b9848..90676515 100644 --- a/internal/api/docs/swagger.json +++ b/internal/api/docs/swagger.json @@ -4,229 +4,6 @@ "contact": {} }, "paths": { - "/v1/announcements": { - "post": { - "description": "Creates a new announcement and generates unique ID", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Announcements" - ], - "summary": "Create new Announcement", - "parameters": [ - { - "description": "Announcement data", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.Announcement" - } - } - ], - "responses": { - "200": { - "description": "Success message with UUID", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, - "/v1/announcements/{id}": { - "get": { - "description": "Retrieves a single announcement from the database.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Announcements" - ], - "summary": "Get an announcement by ID", - "parameters": [ - { - "type": "string", - "description": "Announcement ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Announcement details", - "schema": { - "$ref": "#/definitions/dto.Announcement" - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "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 - }, - { - "description": "Updated announcement data", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.UpdateAnnouncement" - } - } - ], - "responses": { - "200": { - "description": "Success message", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "400": { - "description": "Bad Request", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - }, - "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": "Announcement ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Success message", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "404": { - "description": "Not Found", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - } - } - }, "/v1/board/officers": { "get": { "description": "Get all officers from the database", @@ -1283,26 +1060,6 @@ } }, "definitions": { - "dto.Announcement": { - "type": "object", - "properties": { - "announce_at": { - "type": "integer" - }, - "discord_channel_id": { - "type": "string" - }, - "discord_message_id": { - "type": "string" - }, - "uuid": { - "type": "string" - }, - "visibility": { - "type": "string" - } - } - }, "dto.DeletePosition": { "type": "object", "properties": { @@ -1400,26 +1157,6 @@ } } }, - "dto.UpdateAnnouncement": { - "type": "object", - "properties": { - "announce_at": { - "type": "integer" - }, - "discord_channel_id": { - "type": "string" - }, - "discord_message_id": { - "type": "string" - }, - "uuid": { - "type": "string" - }, - "visibility": { - "type": "string" - } - } - }, "dto.UpdateEvent": { "type": "object", "properties": { diff --git a/internal/api/docs/swagger.yaml b/internal/api/docs/swagger.yaml index 8a0b55e1..8c38a5ef 100644 --- a/internal/api/docs/swagger.yaml +++ b/internal/api/docs/swagger.yaml @@ -1,17 +1,4 @@ definitions: - dto.Announcement: - properties: - announce_at: - type: integer - discord_channel_id: - type: string - discord_message_id: - type: string - uuid: - type: string - visibility: - type: string - type: object dto.DeletePosition: properties: officer_id: @@ -75,19 +62,6 @@ definitions: title: type: string type: object - dto.UpdateAnnouncement: - properties: - announce_at: - type: integer - discord_channel_id: - type: string - discord_message_id: - type: string - uuid: - type: string - visibility: - type: string - type: object dto.UpdateEvent: properties: end_at: @@ -139,154 +113,6 @@ definitions: info: contact: {} paths: - /v1/announcements: - post: - consumes: - - application/json - description: Creates a new announcement and generates unique ID - parameters: - - description: Announcement data - in: body - name: body - required: true - schema: - $ref: '#/definitions/dto.Announcement' - produces: - - application/json - responses: - "200": - description: Success message with UUID - schema: - additionalProperties: true - type: object - "400": - description: Bad Request - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal Server Error - schema: - additionalProperties: - type: string - type: object - summary: Create new Announcement - tags: - - Announcements - /v1/announcements/{id}: - delete: - consumes: - - application/json - description: Deletes the Announcement of choice in the database - parameters: - - description: Announcement ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: Success message - schema: - additionalProperties: - type: string - type: object - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal Server Error - schema: - additionalProperties: - type: string - type: object - summary: Deletes the Announcement of Choice - tags: - - Announcements - get: - consumes: - - application/json - description: Retrieves a single announcement from the database. - parameters: - - description: Announcement ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: Announcement details - schema: - $ref: '#/definitions/dto.Announcement' - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal Server Error - schema: - additionalProperties: - type: string - type: object - summary: Get an announcement by ID - 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 - - description: Updated announcement data - in: body - name: body - required: true - schema: - $ref: '#/definitions/dto.UpdateAnnouncement' - produces: - - application/json - responses: - "200": - description: Success message - schema: - additionalProperties: - type: string - type: object - "400": - description: Bad Request - schema: - additionalProperties: - type: string - type: object - "404": - description: Not Found - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal Server Error - schema: - additionalProperties: - type: string - type: object - summary: Updates the Announcement of Choice - tags: - - Announcements /v1/board/officers: get: consumes: diff --git a/internal/api/handlers/announcement.go b/internal/api/handlers/announcement.go deleted file mode 100644 index d0ebfcd9..00000000 --- a/internal/api/handlers/announcement.go +++ /dev/null @@ -1,195 +0,0 @@ -// Package handlers handles http requests and responses -// Business logic belongs in services, not here -package handlers - -import ( - "database/sql" - "errors" - "log" - "net/http" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/api/services" - "github.com/acmcsufoss/api.acmcsuf.com/internal/dto" - "github.com/gin-gonic/gin" -) - -type AnnouncementHandler struct { - announcementService services.AnnouncementServicer -} - -func NewAnnouncementHandler(announcementService services.AnnouncementServicer) *AnnouncementHandler { - return &AnnouncementHandler{announcementService: announcementService} -} - -// GetAnnouncement godoc -// -// @Summary Get an announcement by ID -// @Description Retrieves a single announcement from the database. -// @Tags Announcements -// @Accept json -// @Produce json -// @Param id path string true "Announcement ID" -// @Success 200 {object} dto.Announcement "Announcement details" -// @Failure 404 {object} map[string]string -// @Failure 500 {object} map[string]string -// @Router /v1/announcements/{id} [get] -func (h *AnnouncementHandler) GetAnnouncement(c *gin.Context) { - ctx := c.Request.Context() - id := c.Param("id") - - announcement, err := h.announcementService.Get(ctx, id) - if err != nil { - if errors.Is(err, sql.ErrNoRows) { - c.JSON(http.StatusNotFound, gin.H{ - "error": "Announcement not found", - }) - return - } - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to retrieve announcement", - }) - log.Println("Failed to retrieve announcement:", err) - return - } - - if announcement.IsZero() { - c.JSON(http.StatusNotFound, gin.H{ - "error": "Announcement not found", - }) - return - } - - // NOTE: We won't have to do this once implement domain models - dtoA := dto.AnnouncementDomainToDto(&announcement) - - // response dto btw, no domain here - c.JSON(http.StatusOK, dtoA) -} - -func (h *AnnouncementHandler) GetAnnouncements(c *gin.Context) { - ctx := c.Request.Context() - // TODO: query for things to filter by - filters := []any{} - - announcements, err := h.announcementService.List(ctx, filters...) - if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to retrieve announcements", - }) - return - } - - var dtoSlice []dto.Announcement - for _, elm := range announcements { - dtoSlice = append(dtoSlice, dto.AnnouncementDomainToDto(&elm)) - } - c.JSON(http.StatusOK, dtoSlice) -} - -// CreateAnnouncement godoc -// -// @Summary Create new Announcement -// @Description Creates a new announcement and generates unique ID -// @Tags Announcements -// @Accept json -// @Produce json -// @Param body body dto.Announcement true "Announcement data" -// @Success 200 {object} map[string]interface{} "Success message with UUID" -// @Failure 400 {object} map[string]string -// @Failure 500 {object} map[string]string -// @Router /v1/announcements [post] -func (h *AnnouncementHandler) CreateAnnouncement(c *gin.Context) { - ctx := c.Request.Context() - var params dto.Announcement - - if err := c.ShouldBindJSON(¶ms); err != nil { - c.JSON(http.StatusBadRequest, gin.H{ - "error": "Invalid request body. " + err.Error(), - }) - return - } - - domainA := params.ToDomain() - - // TODO: error out if required fields aren't provided - if err := h.announcementService.Create(ctx, domainA); err != nil { - log.Printf("Failed to create announcement: %v\n", err) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to create announcement", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "message": "Announcement created successfully", - "uuid": params.Uuid, - }) -} - -// 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" -// @Param body body dto.UpdateAnnouncement true "Updated announcement data" -// @Success 200 {object} map[string]string "Success message" -// @Failure 400 {object} map[string]string -// @Failure 404 {object} map[string]string -// @Failure 500 {object} map[string]string -// @Router /v1/announcements/{id} [put] -func (h *AnnouncementHandler) UpdateAnnouncement(c *gin.Context) { - ctx := c.Request.Context() - var params dto.UpdateAnnouncement - id := c.Param("id") - - if err := c.ShouldBindJSON(¶ms); err != nil { - c.JSON(http.StatusBadRequest, gin.H{ - "error": "Invalid request body. " + err.Error(), - }) - } - - domainA := params.ToDomain() - - if err := h.announcementService.Update(ctx, id, domainA); err != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to update announcement", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "message": "Announcement updated successfully", - "uuid": params.Uuid, - }) -} - -// 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 "Announcement ID" -// @Success 200 {object} map[string]string "Success message" -// @Failure 404 {object} map[string]string -// @Failure 500 {object} map[string]string -// @Router /v1/announcements/{id} [delete] -func (h *AnnouncementHandler) DeleteAnnouncement(c *gin.Context) { - ctx := c.Request.Context() - id := c.Param("id") - - if err := h.announcementService.Delete(ctx, id); err != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to delete announcement", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "message": "Announcement updated successfully", - }) -} diff --git a/internal/api/routes/v1.go b/internal/api/routes/v1.go index beb7e3ff..ee97bc24 100644 --- a/internal/api/routes/v1.go +++ b/internal/api/routes/v1.go @@ -15,7 +15,7 @@ import ( ) func SetupV1(router *gin.Engine, eventService services.EventsServicer, - announcementService services.AnnouncementServicer, boardService services.BoardServicer) { + boardService services.BoardServicer) { cfg := config.Load() if cfg.DiscordBotToken == "" && cfg.Env != "development" { @@ -37,7 +37,6 @@ func SetupV1(router *gin.Engine, eventService services.EventsServicer, } eh := handlers.NewEventHandler(eventService) - ah := handlers.NewAnnouncementHandler(announcementService) bh := handlers.NewBoardHandler(boardService) v1 := router.Group("/v1") @@ -46,9 +45,6 @@ func SetupV1(router *gin.Engine, eventService services.EventsServicer, v1.GET("/events", eh.GetEvents) v1.GET("/events/:id", eh.GetEvent) - v1.GET("/announcements", ah.GetAnnouncements) - v1.GET("/announcements/:id", ah.GetAnnouncement) - board := v1.Group("/board") { board.GET("/officers", bh.GetOfficers) @@ -70,10 +66,6 @@ func SetupV1(router *gin.Engine, eventService services.EventsServicer, protected.PUT("/events/:id", eh.UpdateEvent) protected.DELETE("/events/:id", eh.DeleteEvent) - protected.POST("/announcements", ah.CreateAnnouncement) - protected.PUT("/announcements/:id", ah.UpdateAnnouncement) - protected.DELETE("/announcements/:id", ah.DeleteAnnouncement) - board := protected.Group("/board") { // Officers diff --git a/internal/api/server.go b/internal/api/server.go index 25094bdd..760a51ba 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -52,14 +52,13 @@ func Run(ctx context.Context) { // Now we init services & gin router, and then start the server queries := dbmodels.New(db) eventsService := services.NewEventsService(queries) - announcementService := services.NewAnnouncementService(queries) boardService := services.NewBoardService(queries, db) router := gin.Default() router.Use(mw.Cors(), mw.Ratelimiter()) router.SetTrustedProxies(cfg.TrustedProxies) routes.SetupRoot(router) - routes.SetupV1(router, eventsService, announcementService, boardService) + routes.SetupV1(router, eventsService, boardService) go func() { serverAddr := ":" + cfg.Port diff --git a/internal/api/services/announcement.go b/internal/api/services/announcement.go deleted file mode 100644 index e9014eff..00000000 --- a/internal/api/services/announcement.go +++ /dev/null @@ -1,95 +0,0 @@ -package services - -import ( - "context" - "log" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/api/store" - "github.com/acmcsufoss/api.acmcsuf.com/internal/api/store/dbmodels" - "github.com/acmcsufoss/api.acmcsuf.com/internal/domain" -) - -type AnnouncementServicer interface { - Service[domain.Announcement, string, domain.Announcement, - domain.UpdateAnnouncement] -} - -type AnnouncementService struct { - q *dbmodels.Queries -} - -// compile time check -var _ AnnouncementServicer = (*AnnouncementService)(nil) - -func NewAnnouncementService(q *dbmodels.Queries) *AnnouncementService { - return &AnnouncementService{q: q} -} - -func (s *AnnouncementService) Get(ctx context.Context, uuid string) (domain.Announcement, error) { - announcement, err := s.q.GetAnnouncement(ctx, uuid) - if err != nil { - return domain.Announcement{}, err - } - - domainA := store.AnnouncementDBToDomain(announcement) - - return domainA, nil -} - -func (s *AnnouncementService) Create(ctx context.Context, - params domain.Announcement, -) error { - dbA := store.AnnouncementDomainToDB(params) - if err := s.q.CreateAnnouncement(ctx, dbA); err != nil { - return err - } - return nil -} - -type AnnouncementFilter interface { - Apply(events []dbmodels.Announcement) []dbmodels.Announcement -} - -func (s *AnnouncementService) List(ctx context.Context, - filters ...any, -) ([]domain.Announcement, error) { - announcements, err := s.q.GetAnnouncements(ctx) - if err != nil { - return nil, err - } - - result := announcements - for _, filter := range filters { - if announcementFilter, ok := filter.(AnnouncementFilter); ok { - result = announcementFilter.Apply(result) - } - } - - domainAs := make([]domain.Announcement, len(result)) - for i, elm := range result { - domainAs[i] = store.AnnouncementDBToDomain(elm) - } - return domainAs, nil -} - -func (s *AnnouncementService) Update(ctx context.Context, uuid string, - params domain.UpdateAnnouncement, -) error { - dbA := store.UpdateAnnouncementDomainToDB(params) - - err := s.q.UpdateAnnouncement(ctx, dbA) - if err != nil { - log.Printf("Error updating announcement with UUID %s: %v", uuid, err) - return err - } - return nil -} - -func (s *AnnouncementService) Delete(ctx context.Context, uuid string) error { - err := s.q.DeleteAnnouncement(ctx, uuid) - if err != nil { - log.Printf("Error deleting announcement with UUID %s: %v", uuid, err) - return err - } - return nil -} diff --git a/internal/api/store/announcements_mapper.go b/internal/api/store/announcements_mapper.go deleted file mode 100644 index 64fef0c7..00000000 --- a/internal/api/store/announcements_mapper.go +++ /dev/null @@ -1,38 +0,0 @@ -package store - -import ( - "time" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/api/store/dbmodels" - "github.com/acmcsufoss/api.acmcsuf.com/internal/domain" -) - -func AnnouncementDomainToDB(announcement domain.Announcement) dbmodels.CreateAnnouncementParams { - return dbmodels.CreateAnnouncementParams{ - Uuid: announcement.Uuid, - Visibility: announcement.Visibility, - AnnounceAt: announcement.AnnounceAt.Unix(), - DiscordChannelID: stringToNullString(announcement.DiscordChannelID), - DiscordMessageID: stringToNullString(announcement.DiscordMessageID), - } -} - -func UpdateAnnouncementDomainToDB(announcement domain.UpdateAnnouncement) dbmodels.UpdateAnnouncementParams { - return dbmodels.UpdateAnnouncementParams{ - Uuid: announcement.Uuid, - Visibility: stringToNullString(announcement.Visibility), - AnnounceAt: timeToNullInt64(announcement.AnnounceAt), - DiscordChannelID: stringToNullString(announcement.DiscordChannelID), - DiscordMessageID: stringToNullString(announcement.DiscordMessageID), - } -} - -func AnnouncementDBToDomain(announcement dbmodels.Announcement) domain.Announcement { - return domain.Announcement{ - Uuid: announcement.Uuid, - Visibility: announcement.Visibility, - AnnounceAt: time.Unix(announcement.AnnounceAt, 0), - DiscordChannelID: nullStringPtr(announcement.DiscordChannelID), - DiscordMessageID: nullStringPtr(announcement.DiscordMessageID), - } -} diff --git a/internal/api/store/dbmodels/announcement.sql.go b/internal/api/store/dbmodels/announcement.sql.go deleted file mode 100644 index 1ddce458..00000000 --- a/internal/api/store/dbmodels/announcement.sql.go +++ /dev/null @@ -1,151 +0,0 @@ -// Code generated by sqlc. DO NOT EDIT. -// versions: -// sqlc v1.30.0 -// source: announcement.sql - -package dbmodels - -import ( - "context" - "database/sql" -) - -const createAnnouncement = `-- name: CreateAnnouncement :exec -INSERT INTO -announcement ( - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -) -VALUES -(?, ?, ?, ?, ?) -RETURNING uuid, visibility, announce_at, discord_channel_id, discord_message_id -` - -type CreateAnnouncementParams struct { - Uuid string - Visibility string - AnnounceAt int64 - DiscordChannelID sql.NullString - DiscordMessageID sql.NullString -} - -func (q *Queries) CreateAnnouncement(ctx context.Context, arg CreateAnnouncementParams) error { - _, err := q.db.ExecContext(ctx, createAnnouncement, - arg.Uuid, - arg.Visibility, - arg.AnnounceAt, - arg.DiscordChannelID, - arg.DiscordMessageID, - ) - return err -} - -const deleteAnnouncement = `-- name: DeleteAnnouncement :exec -DELETE FROM announcement -WHERE uuid = ? -` - -func (q *Queries) DeleteAnnouncement(ctx context.Context, uuid string) error { - _, err := q.db.ExecContext(ctx, deleteAnnouncement, uuid) - return err -} - -const getAnnouncement = `-- name: GetAnnouncement :one -SELECT - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -FROM - announcement -WHERE - uuid = ? -` - -func (q *Queries) GetAnnouncement(ctx context.Context, uuid string) (Announcement, error) { - row := q.db.QueryRowContext(ctx, getAnnouncement, uuid) - var i Announcement - err := row.Scan( - &i.Uuid, - &i.Visibility, - &i.AnnounceAt, - &i.DiscordChannelID, - &i.DiscordMessageID, - ) - return i, err -} - -const getAnnouncements = `-- name: GetAnnouncements :many -SELECT - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -FROM - announcement -` - -func (q *Queries) GetAnnouncements(ctx context.Context) ([]Announcement, error) { - rows, err := q.db.QueryContext(ctx, getAnnouncements) - if err != nil { - return nil, err - } - defer rows.Close() - var items []Announcement - for rows.Next() { - var i Announcement - if err := rows.Scan( - &i.Uuid, - &i.Visibility, - &i.AnnounceAt, - &i.DiscordChannelID, - &i.DiscordMessageID, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - -const updateAnnouncement = `-- name: UpdateAnnouncement :exec -UPDATE announcement -SET - visibility = COALESCE(?1, visibility), - announce_at = COALESCE(?2, announce_at), - discord_channel_id = COALESCE(?3, discord_channel_id), - discord_message_id = COALESCE(?4, discord_message_id) - -WHERE - uuid = ?5 -` - -type UpdateAnnouncementParams struct { - Visibility sql.NullString - AnnounceAt sql.NullInt64 - DiscordChannelID sql.NullString - DiscordMessageID sql.NullString - Uuid string -} - -func (q *Queries) UpdateAnnouncement(ctx context.Context, arg UpdateAnnouncementParams) error { - _, err := q.db.ExecContext(ctx, updateAnnouncement, - arg.Visibility, - arg.AnnounceAt, - arg.DiscordChannelID, - arg.DiscordMessageID, - arg.Uuid, - ) - return err -} diff --git a/internal/api/store/dbmodels/models.go b/internal/api/store/dbmodels/models.go index f0415f86..904f1cfd 100644 --- a/internal/api/store/dbmodels/models.go +++ b/internal/api/store/dbmodels/models.go @@ -8,14 +8,6 @@ import ( "database/sql" ) -type Announcement struct { - Uuid string - Visibility string - AnnounceAt int64 - DiscordChannelID sql.NullString - DiscordMessageID sql.NullString -} - type Event struct { Uuid string Location string diff --git a/internal/cli/command/announcements/delete.go b/internal/cli/command/announcements/delete.go deleted file mode 100644 index 7da48e49..00000000 --- a/internal/cli/command/announcements/delete.go +++ /dev/null @@ -1,42 +0,0 @@ -package announcements - -import ( - "fmt" - "net/http" - "os" - - "github.com/spf13/cobra" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config" - "github.com/acmcsufoss/api.acmcsuf.com/utils" -) - -var DeleteAnnouncements = &cobra.Command{ - Use: "delete", - Short: "delete an announcement by its id", - - Run: func(cmd *cobra.Command, args []string) { - var uuid string - uuid, _ = cmd.Flags().GetString("id") - deleteAnnouncement(uuid, config.Cfg) - }, -} - -func init() { - DeleteAnnouncements.Flags().String("id", "", "delete an announcement by its id") - DeleteAnnouncements.MarkFlagRequired("id") -} - -func deleteAnnouncement(id string, cfg *config.Config) { - deleteUrl := config.GetBaseURL(cfg).JoinPath("v1", "announcements", id) - - if body, err := client.SendRequestAndReadResponse(deleteUrl, true, http.MethodDelete, nil); err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - if body != nil { - utils.PrettyPrintJSONErr(body) - } - } else { - utils.PrettyPrintJSON(body) - } -} diff --git a/internal/cli/command/announcements/get.go b/internal/cli/command/announcements/get.go deleted file mode 100644 index 71e0ac86..00000000 --- a/internal/cli/command/announcements/get.go +++ /dev/null @@ -1,41 +0,0 @@ -package announcements - -import ( - "fmt" - "net/http" - "os" - - "github.com/spf13/cobra" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config" - "github.com/acmcsufoss/api.acmcsuf.com/utils" -) - -var GetAnnouncement = &cobra.Command{ - Use: "get", - Short: "Get an announcement", - - Run: func(cmd *cobra.Command, args []string) { - var uuid string - uuid, _ = cmd.Flags().GetString("id") - getAnnouncement(uuid, config.Cfg) - }, -} - -func init() { - GetAnnouncement.Flags().String("id", "", "Get a specific announcement by its id") -} - -func getAnnouncement(uuid string, cfg *config.Config) { - getUrl := config.GetBaseURL(cfg).JoinPath("v1", "announcements", uuid) - - if body, err := client.SendRequestAndReadResponse(getUrl, false, http.MethodGet, nil); err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - if body != nil { - utils.PrettyPrintJSONErr(body) - } - } else { - utils.PrettyPrintJSON(body) - } -} diff --git a/internal/cli/command/announcements/post.go b/internal/cli/command/announcements/post.go deleted file mode 100644 index c8cd7a7b..00000000 --- a/internal/cli/command/announcements/post.go +++ /dev/null @@ -1,99 +0,0 @@ -package announcements - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "os" - - "github.com/charmbracelet/huh" - "github.com/spf13/cobra" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/forms" - "github.com/acmcsufoss/api.acmcsuf.com/internal/dto" - "github.com/acmcsufoss/api.acmcsuf.com/utils" -) - -var PostAnnouncement = &cobra.Command{ - Use: "post", - Short: "post a new announcement", - - Run: func(cmd *cobra.Command, args []string) { - postAnnouncement(config.Cfg) - }, -} - -func postAnnouncement(cfg *config.Config) { - postUrl := config.GetBaseURL(cfg).JoinPath("v1", "announcements") - - payload, err := postForm() - if err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - return - } - b, err := json.Marshal(payload) - if err != nil { - fmt.Fprintln(os.Stderr, "Error: could not marshal JSON:", err) - return - } - - if body, err := client.SendRequestAndReadResponse(postUrl, true, http.MethodPost, - bytes.NewBuffer(b)); err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - if body != nil { - utils.PrettyPrintJSONErr(body) - } - } else { - utils.PrettyPrintJSON(body) - } -} - -func postForm() (*dto.Announcement, error) { - var payload dto.Announcement - var err error - var ( - announceAtStr string - channelIDStr string - messageIDStr string - ) - form := huh.NewForm( - huh.NewGroup( - huh.NewInput(). - Title("Announcement ID"). - Value(&payload.Uuid). - Validate(forms.ValidateNonEmpty()), - huh.NewInput(). - Title("Announcement Visibility"). - Value(&payload.Visibility). - Validate(forms.ValidateNonEmpty()), - huh.NewInput(). - Title("Announcement Time\n"+ - "Format: \x1b[93mMM/DD/YY HH:MM[PM | AM]\x1b[0m\n"+ - "Example: \x1b[93m01/02/06 03:04PM\x1b[0m"). - Value(&announceAtStr). - Validate(forms.ValidateNonEmpty()), - // TODO: write validator for time inputs - huh.NewInput(). - Title("Channel ID"). - Value(&channelIDStr), - huh.NewInput(). - Title("Message ID"). - Value(&messageIDStr), - ), - ) - if err = form.Run(); err != nil { - return nil, err - } - - payload.AnnounceAt, err = utils.ParseTime(announceAtStr) - if err != nil { - return nil, err - } - payload.DiscordChannelID = &channelIDStr - payload.DiscordMessageID = &messageIDStr - - return &payload, nil -} diff --git a/internal/cli/command/announcements/put.go b/internal/cli/command/announcements/put.go deleted file mode 100644 index 9be02f8e..00000000 --- a/internal/cli/command/announcements/put.go +++ /dev/null @@ -1,122 +0,0 @@ -package announcements - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "os" - - "github.com/charmbracelet/huh" - "github.com/spf13/cobra" - - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config" - "github.com/acmcsufoss/api.acmcsuf.com/internal/dto" - "github.com/acmcsufoss/api.acmcsuf.com/utils" -) - -var PutAnnouncements = &cobra.Command{ - Use: "put --id ", - Short: "update an existing announcement by its id", - - Run: func(cmd *cobra.Command, args []string) { - id, _ := cmd.Flags().GetString("id") - putAnnouncements(id, config.Cfg) - }, -} - -func init() { - PutAnnouncements.Flags().String("id", "", "Get an announcement by its id") - PutAnnouncements.MarkFlagRequired("id") -} - -func putAnnouncements(id string, cfg *config.Config) { - resourceUrl := config.GetBaseURL(cfg).JoinPath("v1", "announcements", id) - - // ----- Get announcement we want to update ----- - var oldPayload dto.Announcement - if body, err := client.SendRequestAndReadResponse(resourceUrl, false, http.MethodGet, nil); err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - if body != nil { - utils.PrettyPrintJSON(body) - } - return - } else { - err = json.Unmarshal(body, &oldPayload) - if err != nil { - fmt.Fprintln(os.Stderr, "Error: failed to unmarshal response body:", err) - return - } - } - - // ----- Update found announcement ----- - newPayload, err := putForm(&oldPayload) - if err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - return - } - b, err := json.Marshal(newPayload) - if err != nil { - fmt.Fprintln(os.Stderr, "Error: failed to marshal data:", err) - return - } - - // Update remote resource with new data - if body, err := client.SendRequestAndReadResponse(resourceUrl, true, http.MethodPut, - bytes.NewBuffer(b)); err != nil { - fmt.Fprintln(os.Stderr, "Error:", err) - if body != nil { - utils.PrettyPrintJSONErr(body) - } - } else { - utils.PrettyPrintJSON(body) - } -} - -func putForm(oldPayload *dto.Announcement) (*dto.UpdateAnnouncement, error) { - var payload dto.UpdateAnnouncement - var err error - var ( - visibilityStr string = oldPayload.Visibility - announceAtStr string // no default for now bc its stored as a raw timestamp - channelIDStr string = *oldPayload.DiscordChannelID - messageIDStr string = *oldPayload.DiscordMessageID - ) - form := huh.NewForm( - huh.NewGroup( - huh.NewInput(). - Title("Announcement Visibility"). - Value(&visibilityStr), - huh.NewInput(). - Title("Announcement Time\n"+ - "Format: \x1b[93mMM/DD/YY HH:MM[PM | AM]\x1b[0m\n"+ - "Example: \x1b[93m01/02/06 03:04PM\x1b[0m"). - Value(&announceAtStr), - // TODO: write validator for time inputs - huh.NewInput(). - Title("Channel ID"). - Value(&channelIDStr), - huh.NewInput(). - Title("Message ID"). - Value(&messageIDStr), - ), - ) - if err = form.Run(); err != nil { - return nil, err - } - - payload.Uuid = oldPayload.Uuid - payload.Visibility = &visibilityStr - if announceAtStr != "" { - timestamp, err := utils.ParseTime(announceAtStr) - if err != nil { - return nil, err - } - payload.AnnounceAt = ×tamp - } - payload.DiscordChannelID = &channelIDStr - payload.DiscordMessageID = &messageIDStr - - return &payload, nil -} diff --git a/internal/cli/command/announcements/root.go b/internal/cli/command/announcements/root.go deleted file mode 100644 index 5f4c1446..00000000 --- a/internal/cli/command/announcements/root.go +++ /dev/null @@ -1,17 +0,0 @@ -package announcements - -import ( - "github.com/spf13/cobra" -) - -var CLIAnnouncements = &cobra.Command{ - Use: "announcements", - Short: "Manage ACM CSUF's Announcements", -} - -func init() { - CLIAnnouncements.AddCommand(GetAnnouncement) - CLIAnnouncements.AddCommand(PostAnnouncement) - CLIAnnouncements.AddCommand(DeleteAnnouncements) - CLIAnnouncements.AddCommand(PutAnnouncements) -} diff --git a/internal/cli/command/root.go b/internal/cli/command/root.go index 13b46f71..3bd16c79 100644 --- a/internal/cli/command/root.go +++ b/internal/cli/command/root.go @@ -10,7 +10,6 @@ import ( "github.com/spf13/cobra" "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client" - "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/command/announcements" "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/command/events" "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/command/officers" "github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config" @@ -51,7 +50,6 @@ func init() { } rootCmd.AddCommand(events.CLIEvents) - rootCmd.AddCommand(announcements.CLIAnnouncements) rootCmd.AddCommand(officers.CLIOfficers) rootCmd.AddCommand(config.ConfigCmd) diff --git a/internal/domain/announcements.go b/internal/domain/announcements.go deleted file mode 100644 index 093977b1..00000000 --- a/internal/domain/announcements.go +++ /dev/null @@ -1,25 +0,0 @@ -package domain - -import ( - "time" -) - -type Announcement struct { - Uuid string - Visibility string - AnnounceAt time.Time - DiscordChannelID *string - DiscordMessageID *string -} - -type UpdateAnnouncement struct { - Uuid string - Visibility *string - AnnounceAt *time.Time - DiscordChannelID *string - DiscordMessageID *string -} - -func (a Announcement) IsZero() bool { - return a.Uuid == "" -} diff --git a/internal/dto/announcement.go b/internal/dto/announcement.go deleted file mode 100644 index 0563bcaa..00000000 --- a/internal/dto/announcement.go +++ /dev/null @@ -1,64 +0,0 @@ -package dto - -import ( - "github.com/acmcsufoss/api.acmcsuf.com/internal/domain" - "github.com/acmcsufoss/api.acmcsuf.com/utils" -) - -type Announcement struct { - Uuid string `json:"uuid"` - Visibility string `json:"visibility"` - AnnounceAt int64 `json:"announce_at"` - DiscordChannelID *string `json:"discord_channel_id"` - DiscordMessageID *string `json:"discord_message_id"` -} - -func (a *Announcement) ToDomain() domain.Announcement { - if a == nil { - return domain.Announcement{} - } - - return domain.Announcement{ - Uuid: a.Uuid, - Visibility: a.Visibility, - AnnounceAt: utils.UnixToTime(a.AnnounceAt), - DiscordChannelID: a.DiscordChannelID, - DiscordMessageID: a.DiscordMessageID, - } -} - -func AnnouncementDomainToDto(a *domain.Announcement) Announcement { - if a == nil { - return Announcement{} - } - - return Announcement{ - Uuid: a.Uuid, - Visibility: a.Visibility, - AnnounceAt: a.AnnounceAt.Unix(), - DiscordChannelID: a.DiscordChannelID, - DiscordMessageID: a.DiscordMessageID, - } -} - -type UpdateAnnouncement struct { - Uuid string `json:"uuid"` - Visibility *string `json:"visibility"` - AnnounceAt *int64 `json:"announce_at"` - DiscordChannelID *string `json:"discord_channel_id"` - DiscordMessageID *string `json:"discord_message_id"` -} - -func (a *UpdateAnnouncement) ToDomain() domain.UpdateAnnouncement { - if a == nil { - return domain.UpdateAnnouncement{} - } - - return domain.UpdateAnnouncement{ - Uuid: a.Uuid, - Visibility: a.Visibility, - AnnounceAt: utils.UnixToTimePtr(a.AnnounceAt), - DiscordChannelID: a.DiscordChannelID, - DiscordMessageID: a.DiscordMessageID, - } -} diff --git a/sql/migrations/000001_create_announcements.down.sql b/sql/migrations/000001_create_announcements.down.sql deleted file mode 100644 index 9ff85a41..00000000 --- a/sql/migrations/000001_create_announcements.down.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Language: sqlite - -DROP TABLE IF EXISTS announcement; diff --git a/sql/migrations/000001_create_announcements.up.sql b/sql/migrations/000001_create_announcements.up.sql deleted file mode 100644 index 68a7462b..00000000 --- a/sql/migrations/000001_create_announcements.up.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Language: sqlite - --- Create the 'announcement' table which is a table of announcement resources. -CREATE TABLE IF NOT EXISTS announcement ( - uuid TEXT PRIMARY KEY, - visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. - announce_at INTEGER NOT NULL, -- UTC milliseconds. - discord_channel_id TEXT, -- Discord channel ID. - discord_message_id TEXT UNIQUE -- Discord message ID. If present, the announcement has been posted. - --UNIQUE (id) -); diff --git a/sql/queries/announcement.sql b/sql/queries/announcement.sql deleted file mode 100644 index ebcf1add..00000000 --- a/sql/queries/announcement.sql +++ /dev/null @@ -1,49 +0,0 @@ --- name: CreateAnnouncement :exec -INSERT INTO -announcement ( - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -) -VALUES -(?, ?, ?, ?, ?) -RETURNING *; - --- name: GetAnnouncement :one -SELECT - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -FROM - announcement -WHERE - uuid = ?; - --- name: UpdateAnnouncement :exec -UPDATE announcement -SET - visibility = COALESCE(sqlc.narg('visibility'), visibility), - announce_at = COALESCE(sqlc.narg('announce_at'), announce_at), - discord_channel_id = COALESCE(sqlc.narg('discord_channel_id'), discord_channel_id), - discord_message_id = COALESCE(sqlc.narg('discord_message_id'), discord_message_id) - -WHERE - uuid = sqlc.arg('uuid'); - --- name: GetAnnouncements :many -SELECT - uuid, - visibility, - announce_at, - discord_channel_id, - discord_message_id -FROM - announcement; - --- name: DeleteAnnouncement :exec -DELETE FROM announcement -WHERE uuid = ?;