From c6cdec8e66fa9be0f1a81c7cb2d6f5e04af9ee54 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sat, 21 Jan 2023 17:55:36 -0800 Subject: [PATCH] updated discordwebhookqueue to return details on the items via dto --- docs/docs.go | 8 ++++---- docs/swagger.json | 8 ++++---- docs/swagger.yaml | 8 ++++---- domain/models/dto.go | 8 +++----- dto/queue.go | 42 ++++++++++++++++++++++++++++++++++++++++++ routes/queue.go | 9 +++------ 6 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 dto/queue.go diff --git a/docs/docs.go b/docs/docs.go index 062302a..781391a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -905,11 +905,11 @@ const docTemplate = `{ } } }, - "models.DiscordQueueDto": { + "models.DiscordQueueDetailsDto": { "type": "object", "properties": { - "articleId": { - "type": "string" + "article": { + "$ref": "#/definitions/models.ArticleDetailsDto" }, "id": { "type": "string" @@ -1095,7 +1095,7 @@ const docTemplate = `{ "payload": { "type": "array", "items": { - "$ref": "#/definitions/models.DiscordQueueDto" + "$ref": "#/definitions/models.DiscordQueueDetailsDto" } }, "status": { diff --git a/docs/swagger.json b/docs/swagger.json index 04d71ad..6b67c8c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -896,11 +896,11 @@ } } }, - "models.DiscordQueueDto": { + "models.DiscordQueueDetailsDto": { "type": "object", "properties": { - "articleId": { - "type": "string" + "article": { + "$ref": "#/definitions/models.ArticleDetailsDto" }, "id": { "type": "string" @@ -1086,7 +1086,7 @@ "payload": { "type": "array", "items": { - "$ref": "#/definitions/models.DiscordQueueDto" + "$ref": "#/definitions/models.DiscordQueueDetailsDto" } }, "status": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 18215fa..ba5a2cf 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -62,10 +62,10 @@ definitions: videoWidth: type: integer type: object - models.DiscordQueueDto: + models.DiscordQueueDetailsDto: properties: - articleId: - type: string + article: + $ref: '#/definitions/models.ArticleDetailsDto' id: type: string type: object @@ -185,7 +185,7 @@ definitions: type: string payload: items: - $ref: '#/definitions/models.DiscordQueueDto' + $ref: '#/definitions/models.DiscordQueueDetailsDto' type: array status: type: integer diff --git a/domain/models/dto.go b/domain/models/dto.go index d25a8b1..b0f3510 100644 --- a/domain/models/dto.go +++ b/domain/models/dto.go @@ -97,11 +97,9 @@ type DiscordQueueDto struct { Articleid uuid.UUID `json:"articleId"` } -func ConvertToDiscordQueueDto(i database.Discordqueue) DiscordQueueDto { - return DiscordQueueDto{ - ID: i.ID, - Articleid: i.Articleid, - } +type DiscordQueueDetailsDto struct { + ID uuid.UUID `json:"id"` + Article ArticleDetailsDto `json:"article"` } type SubscriptionDto struct { diff --git a/dto/queue.go b/dto/queue.go new file mode 100644 index 0000000..d5697f2 --- /dev/null +++ b/dto/queue.go @@ -0,0 +1,42 @@ +package dto + +import ( + "context" + + "github.com/jtom38/newsbot/collector/database" + "github.com/jtom38/newsbot/collector/domain/models" +) + +func (c DtoClient) ListDiscordWebhookQueue(ctx context.Context, limit int32) { + +} + +func (c DtoClient) ListDiscordWebhookQueueDetails(ctx context.Context, limit int32) ([]models.DiscordQueueDetailsDto, error) { + var res []models.DiscordQueueDetailsDto + + items, err := c.db.ListDiscordQueueItems(ctx, limit) + if err != nil { + return res, err + } + + for _, item := range items { + article, err := c.GetArticleDetails(ctx, item.ID) + if err != nil { + return res, err + } + + res = append(res, models.DiscordQueueDetailsDto{ + ID: item.ID, + Article: article, + }) + } + + return res, nil +} + +func (c DtoClient) ConvertToDiscordQueueDto(i database.Discordqueue) models.DiscordQueueDto { + return models.DiscordQueueDto{ + ID: i.ID, + Articleid: i.Articleid, + } +} diff --git a/routes/queue.go b/routes/queue.go index 27d47c4..dddb5a6 100644 --- a/routes/queue.go +++ b/routes/queue.go @@ -18,7 +18,7 @@ func (s *Server) GetQueueRouter() http.Handler { type ListDiscordWebHooksQueueResults struct { ApiStatusModel - Payload []models.DiscordQueueDto `json:"payload"` + Payload []models.DiscordQueueDetailsDto `json:"payload"` } // GetDiscordQueue @@ -38,16 +38,13 @@ func (s *Server) ListDiscordWebhookQueue(w http.ResponseWriter, r *http.Request) } // Get the raw resp from sql - res, err := s.Db.ListDiscordQueueItems(*s.ctx, 100) + res, err := s.dto.ListDiscordWebhookQueueDetails(r.Context(), 50) if err != nil { s.WriteError(w, err.Error(), http.StatusInternalServerError) return } - // convert to dto - for _, item := range res { - p.Payload = append(p.Payload, models.ConvertToDiscordQueueDto(item)) - } + p.Payload = res // convert to json b, err := json.Marshal(p)