newsbot-api/internal/dtoconv/dtoconv.go

68 lines
1.7 KiB
Go

package services
import (
"git.jamestombleson.com/jtom38/newsbot-api/domain"
internal "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
)
func ArticlesToDto(items []internal.ArticleEntity) []domain.ArticleDto {
var dtos []domain.ArticleDto
for _, item := range items {
dtos = append(dtos, ArticleToDto(item))
}
return dtos
}
func ArticleToDto(item internal.ArticleEntity) domain.ArticleDto {
return domain.ArticleDto{
ID: item.ID,
SourceID: item.SourceID,
Tags: item.Tags,
Title: item.Title,
Url: item.Url,
PubDate: item.PubDate,
IsVideo: item.IsVideo,
Thumbnail: item.Thumbnail,
Description: item.Description,
AuthorName: item.AuthorName,
AuthorImageUrl: item.AuthorImageUrl,
}
}
func DiscordWebhooksToDto(items []internal.DiscordWebHookEntity) []domain.DiscordWebHookDto{
var dtos []domain.DiscordWebHookDto
for _, item := range items {
dtos = append(dtos, DiscordWebhookToDto(item))
}
return dtos
}
func DiscordWebhookToDto(item internal.DiscordWebHookEntity) domain.DiscordWebHookDto {
return domain.DiscordWebHookDto{
ID: item.ID,
Server: item.Server,
Channel: item.Channel,
Url: item.Url,
Enabled: item.Enabled,
}
}
func SourcesToDto(items []internal.SourceEntity) []domain.SourceDto {
var dtos []domain.SourceDto
for _, item := range items {
dtos = append(dtos, SourceToDto(item))
}
return dtos
}
func SourceToDto(item internal.SourceEntity) domain.SourceDto {
return domain.SourceDto{
ID: item.ID,
Source: item.Source,
DisplayName: item.DisplayName,
Url: item.Url,
Tags: item.Tags,
Enabled: item.Enabled,
}
}