updated discordwebhookqueue to return details on the items via dto

This commit is contained in:
James Tombleson 2023-01-21 17:55:36 -08:00
parent 176459f17d
commit c6cdec8e66
6 changed files with 60 additions and 23 deletions

View File

@ -905,11 +905,11 @@ const docTemplate = `{
} }
} }
}, },
"models.DiscordQueueDto": { "models.DiscordQueueDetailsDto": {
"type": "object", "type": "object",
"properties": { "properties": {
"articleId": { "article": {
"type": "string" "$ref": "#/definitions/models.ArticleDetailsDto"
}, },
"id": { "id": {
"type": "string" "type": "string"
@ -1095,7 +1095,7 @@ const docTemplate = `{
"payload": { "payload": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/models.DiscordQueueDto" "$ref": "#/definitions/models.DiscordQueueDetailsDto"
} }
}, },
"status": { "status": {

View File

@ -896,11 +896,11 @@
} }
} }
}, },
"models.DiscordQueueDto": { "models.DiscordQueueDetailsDto": {
"type": "object", "type": "object",
"properties": { "properties": {
"articleId": { "article": {
"type": "string" "$ref": "#/definitions/models.ArticleDetailsDto"
}, },
"id": { "id": {
"type": "string" "type": "string"
@ -1086,7 +1086,7 @@
"payload": { "payload": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/models.DiscordQueueDto" "$ref": "#/definitions/models.DiscordQueueDetailsDto"
} }
}, },
"status": { "status": {

View File

@ -62,10 +62,10 @@ definitions:
videoWidth: videoWidth:
type: integer type: integer
type: object type: object
models.DiscordQueueDto: models.DiscordQueueDetailsDto:
properties: properties:
articleId: article:
type: string $ref: '#/definitions/models.ArticleDetailsDto'
id: id:
type: string type: string
type: object type: object
@ -185,7 +185,7 @@ definitions:
type: string type: string
payload: payload:
items: items:
$ref: '#/definitions/models.DiscordQueueDto' $ref: '#/definitions/models.DiscordQueueDetailsDto'
type: array type: array
status: status:
type: integer type: integer

View File

@ -97,11 +97,9 @@ type DiscordQueueDto struct {
Articleid uuid.UUID `json:"articleId"` Articleid uuid.UUID `json:"articleId"`
} }
func ConvertToDiscordQueueDto(i database.Discordqueue) DiscordQueueDto { type DiscordQueueDetailsDto struct {
return DiscordQueueDto{ ID uuid.UUID `json:"id"`
ID: i.ID, Article ArticleDetailsDto `json:"article"`
Articleid: i.Articleid,
}
} }
type SubscriptionDto struct { type SubscriptionDto struct {

42
dto/queue.go Normal file
View File

@ -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,
}
}

View File

@ -18,7 +18,7 @@ func (s *Server) GetQueueRouter() http.Handler {
type ListDiscordWebHooksQueueResults struct { type ListDiscordWebHooksQueueResults struct {
ApiStatusModel ApiStatusModel
Payload []models.DiscordQueueDto `json:"payload"` Payload []models.DiscordQueueDetailsDto `json:"payload"`
} }
// GetDiscordQueue // GetDiscordQueue
@ -38,16 +38,13 @@ func (s *Server) ListDiscordWebhookQueue(w http.ResponseWriter, r *http.Request)
} }
// Get the raw resp from sql // 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 { if err != nil {
s.WriteError(w, err.Error(), http.StatusInternalServerError) s.WriteError(w, err.Error(), http.StatusInternalServerError)
return return
} }
// convert to dto p.Payload = res
for _, item := range res {
p.Payload = append(p.Payload, models.ConvertToDiscordQueueDto(item))
}
// convert to json // convert to json
b, err := json.Marshal(p) b, err := json.Marshal(p)