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",
"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": {

View File

@ -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": {

View File

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

View File

@ -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 {

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 {
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)