2022-12-11 09:46:14 -08:00
|
|
|
package models
|
2022-12-07 22:47:10 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2023-01-21 16:08:12 -08:00
|
|
|
"time"
|
2022-12-07 22:47:10 -08:00
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2022-12-11 09:46:14 -08:00
|
|
|
|
|
|
|
"github.com/jtom38/newsbot/collector/database"
|
2022-12-07 22:47:10 -08:00
|
|
|
)
|
|
|
|
|
2023-01-21 16:08:12 -08:00
|
|
|
type ArticleDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Source uuid.UUID `json:"sourceid"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Pubdate time.Time `json:"pubdate"`
|
|
|
|
Video string `json:"video"`
|
|
|
|
Videoheight int32 `json:"videoHeight"`
|
|
|
|
Videowidth int32 `json:"videoWidth"`
|
|
|
|
Thumbnail string `json:"thumbnail"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Authorname string `json:"authorName"`
|
|
|
|
Authorimage string `json:"authorImage"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArticleDetailsDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Source SourceDto `json:"source"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Pubdate time.Time `json:"pubdate"`
|
|
|
|
Video string `json:"video"`
|
|
|
|
Videoheight int32 `json:"videoHeight"`
|
|
|
|
Videowidth int32 `json:"videoWidth"`
|
|
|
|
Thumbnail string `json:"thumbnail"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Authorname string `json:"authorName"`
|
|
|
|
Authorimage string `json:"authorImage"`
|
|
|
|
}
|
|
|
|
|
2023-01-21 12:20:33 -08:00
|
|
|
type DiscordWebHooksDto struct {
|
|
|
|
ID uuid.UUID `json:"ID"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Server string `json:"server"`
|
|
|
|
Channel string `json:"channel"`
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertToDiscordWebhookDto(i database.Discordwebhook) DiscordWebHooksDto {
|
|
|
|
return DiscordWebHooksDto{
|
|
|
|
ID: i.ID,
|
|
|
|
Url: i.Url,
|
|
|
|
Server: i.Server,
|
|
|
|
Channel: i.Channel,
|
|
|
|
Enabled: i.Enabled,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 22:47:10 -08:00
|
|
|
type SourceDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Site string `json:"site"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Source string `json:"source"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Deleted bool `json:"deleted"`
|
|
|
|
}
|
|
|
|
|
2022-12-11 09:46:14 -08:00
|
|
|
func ConvertToSourceDto(i database.Source) SourceDto {
|
2022-12-07 22:47:10 -08:00
|
|
|
var deleted bool
|
|
|
|
if !i.Deleted.Valid {
|
|
|
|
deleted = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return SourceDto{
|
|
|
|
ID: i.ID,
|
|
|
|
Site: i.Site,
|
|
|
|
Name: i.Name,
|
|
|
|
Source: i.Source,
|
|
|
|
Type: i.Type,
|
|
|
|
Value: i.Value.String,
|
|
|
|
Enabled: i.Enabled,
|
|
|
|
Url: i.Url,
|
|
|
|
Tags: splitTags(i.Tags),
|
|
|
|
Deleted: deleted,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 09:46:14 -08:00
|
|
|
type DiscordQueueDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Articleid uuid.UUID `json:"articleId"`
|
|
|
|
}
|
|
|
|
|
2023-01-21 17:55:36 -08:00
|
|
|
type DiscordQueueDetailsDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Article ArticleDetailsDto `json:"article"`
|
2022-12-11 09:46:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type SubscriptionDto struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
DiscordWebhookId uuid.UUID `json:"discordwebhookid"`
|
|
|
|
SourceId uuid.UUID `json:"sourceid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertToSubscriptionDto(i database.Subscription) SubscriptionDto {
|
|
|
|
c := SubscriptionDto{
|
|
|
|
ID: i.ID,
|
|
|
|
DiscordWebhookId: i.Discordwebhookid,
|
|
|
|
SourceId: i.Sourceid,
|
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2023-01-21 18:49:16 -08:00
|
|
|
type SubscriptionDetailsDto struct {
|
2023-01-21 12:20:33 -08:00
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Source SourceDto `json:"source"`
|
|
|
|
DiscordWebHook DiscordWebHooksDto `json:"discordwebhook"`
|
|
|
|
}
|
|
|
|
|
2022-12-07 22:47:10 -08:00
|
|
|
func splitTags(t string) []string {
|
|
|
|
items := strings.Split(t, ", ")
|
|
|
|
return items
|
|
|
|
}
|