James Tombleson
ada453e08a
* updated db, added dto for ListSources, and added delete source * updated from model > models * updated to models * sources now sends back a standard message * updated subscription routes to have beter logid and swagger details * moved the dto objects back to modles given they are not bound to the database * cleaned up how we return the error * cleaned up swag and updated models to take from the base apistatusmodel. less human errors this way * cleaned up swag and updated models * swag updated * updated queue to return a router and also renamed it as it will hold all queue info later on * removed config tag * added subscription details route * article routes have been moved to support dto * updated discordwebhooks to use dto * updated discordwebhookqueue to return details on the items via dto * removed the example routes * updated sources to use dto * subscriptions moved to dto * generated swag
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
package dto
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jtom38/newsbot/collector/database"
|
|
"github.com/jtom38/newsbot/collector/domain/models"
|
|
)
|
|
|
|
func (c DtoClient) ListSubscriptions(ctx context.Context, limit int32) ([]models.SubscriptionDto, error) {
|
|
var res []models.SubscriptionDto
|
|
|
|
items, err := c.db.ListSubscriptions(ctx, limit)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
for _, item := range items {
|
|
res = append(res, c.ConvertSubscription(item))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (c DtoClient) ListSubscriptionDetails(ctx context.Context, limit int32) ([]models.SubscriptionDetailsDto, error) {
|
|
var res []models.SubscriptionDetailsDto
|
|
|
|
items, err := c.ListSubscriptions(ctx, limit)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
for _, item := range items {
|
|
dwh, err := c.GetDiscordWebhook(ctx, item.DiscordWebhookId)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
source, err := c.GetSourceById(ctx, item.SourceId)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
res = append(res, models.SubscriptionDetailsDto{
|
|
ID: item.ID,
|
|
Source: source,
|
|
DiscordWebHook: dwh,
|
|
})
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (c DtoClient) ListSubscriptionsByDiscordWebhookId(ctx context.Context, id uuid.UUID) ([]models.SubscriptionDto, error) {
|
|
var res []models.SubscriptionDto
|
|
|
|
items, err := c.db.GetSubscriptionsByDiscordWebHookId(ctx, id)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
for _, item := range items {
|
|
res = append(res, c.ConvertSubscription(item))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (c DtoClient) ListSubscriptionsBySourceId(ctx context.Context, id uuid.UUID) ([]models.SubscriptionDto, error) {
|
|
var res []models.SubscriptionDto
|
|
|
|
items, err := c.db.GetSubscriptionsBySourceID(ctx, id)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
|
|
for _, item := range items {
|
|
res = append(res, c.ConvertSubscription(item))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (c DtoClient) ConvertSubscription(i database.Subscription) models.SubscriptionDto {
|
|
return models.SubscriptionDto{
|
|
ID: i.ID,
|
|
DiscordWebhookId: i.Discordwebhookid,
|
|
SourceId: i.Sourceid,
|
|
}
|
|
}
|