features/move-domain-for-portal #8

Merged
jtom38 merged 6 commits from features/move-domain-for-portal into main 2024-05-09 19:10:04 -07:00
11 changed files with 201 additions and 56 deletions
Showing only changes of commit 94c2bdb312 - Show all commits

140
internal/entity/entity.go Normal file
View File

@ -0,0 +1,140 @@
package entity
import (
"time"
)
// This links a source to a discord webhook.
// It is owned by a user so they can remove the link
type AlertDiscordEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
UserID int64
SourceID int64
DiscordWebHookId int64
}
type ArticleEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
SourceID int64
Tags string
Title string
Url string
PubDate time.Time
IsVideo bool
Thumbnail string
Description string
AuthorName string
AuthorImageUrl string
}
type DiscordQueueEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
ArticleId int64
SourceId int64
}
type DiscordWebHookEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
UserID int64
Url string
Server string
Channel string
Enabled bool
}
type IconEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
FileName string
Site string
}
type SettingEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
Key string
Value string
Options string
}
type SourceEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
// Who will collect from it. Used
// domain.SourceCollector...
Source string
// Human Readable value to state what is getting collected
DisplayName string
// Tells the parser where to look for data
Url string
// Static tags for this defined record
Tags string
// If the record is disabled, then it will be skipped on processing
Enabled bool
}
//type SubscriptionEntity struct {
// ID int64
// CreatedAt time.Time
// UpdatedAt time.Time
// DeletedAt time.Time
// UserID int64
// SourceID int64
// //SourceType string
// //SourceName string
// DiscordID int64
// //DiscordName string
//}
// This defines what sources a user wants to follow.
// These will show up for the user as a front page
type UserSourceSubscriptionEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
UserID int64
SourceID int64
}
type UserEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
Username string
Hash string
Scopes string
}
type RefreshTokenEntity struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
Username string
Token string
}

View File

@ -12,7 +12,7 @@ import (
"github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/launcher"
"github.com/google/uuid" "github.com/google/uuid"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cache" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cache"
) )
@ -24,7 +24,7 @@ const (
) )
type FFXIVClient struct { type FFXIVClient struct {
record domain.SourceEntity record entity.SourceEntity
//SourceID uint //SourceID uint
//Url string //Url string
//Region string //Region string
@ -32,15 +32,15 @@ type FFXIVClient struct {
cacheGroup string cacheGroup string
} }
func NewFFXIVClient(Record domain.SourceEntity) FFXIVClient { func NewFFXIVClient(Record entity.SourceEntity) FFXIVClient {
return FFXIVClient{ return FFXIVClient{
record: Record, record: Record,
cacheGroup: "ffxiv", cacheGroup: "ffxiv",
} }
} }
func (fc *FFXIVClient) CheckSource() ([]domain.ArticleEntity, error) { func (fc *FFXIVClient) CheckSource() ([]entity.ArticleEntity, error) {
var articles []domain.ArticleEntity var articles []entity.ArticleEntity
parser := fc.GetBrowser() parser := fc.GetBrowser()
defer parser.Close() defer parser.Close()
@ -96,7 +96,7 @@ func (fc *FFXIVClient) CheckSource() ([]domain.ArticleEntity, error) {
return articles, err return articles, err
} }
article := domain.ArticleEntity{ article := entity.ArticleEntity{
SourceID: fc.record.ID, SourceID: fc.record.ID,
Tags: tags, Tags: tags,
Title: title, Title: title,

View File

@ -3,11 +3,12 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
ffxiv "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" ffxiv "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var FFXIVRecord domain.SourceEntity = domain.SourceEntity{ var FFXIVRecord entity.SourceEntity = entity.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "Final Fantasy XIV - NA", DisplayName: "Final Fantasy XIV - NA",
Source: domain.SourceCollectorFfxiv, Source: domain.SourceCollectorFfxiv,

View File

@ -9,6 +9,7 @@ import (
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"github.com/go-rod/rod" "github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/launcher"
@ -16,7 +17,7 @@ import (
type RedditClient struct { type RedditClient struct {
config RedditConfig config RedditConfig
record domain.SourceEntity record entity.SourceEntity
} }
type RedditConfig struct { type RedditConfig struct {
@ -25,7 +26,7 @@ type RedditConfig struct {
PullNSFW string PullNSFW string
} }
func NewRedditClient(Record domain.SourceEntity) *RedditClient { func NewRedditClient(Record entity.SourceEntity) *RedditClient {
rc := RedditClient{ rc := RedditClient{
record: Record, record: Record,
} }
@ -86,10 +87,10 @@ func (rc *RedditClient) GetContent() (domain.RedditJsonContent, error) {
return items, nil return items, nil
} }
func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []domain.ArticleEntity { func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []entity.ArticleEntity {
var redditArticles []domain.ArticleEntity var redditArticles []entity.ArticleEntity
for _, item := range items.Data.Children { for _, item := range items.Data.Children {
var article domain.ArticleEntity var article entity.ArticleEntity
article, err := rc.convertToArticle(item.Data) article, err := rc.convertToArticle(item.Data)
if err != nil { if err != nil {
log.Printf("[Reddit] %v", err) log.Printf("[Reddit] %v", err)
@ -102,8 +103,8 @@ func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []doma
// ConvertToArticle() will take the reddit model struct and convert them over to Article structs. // ConvertToArticle() will take the reddit model struct and convert them over to Article structs.
// This data can be passed to the database. // This data can be passed to the database.
func (rc *RedditClient) convertToArticle(source domain.RedditPost) (domain.ArticleEntity, error) { func (rc *RedditClient) convertToArticle(source domain.RedditPost) (entity.ArticleEntity, error) {
var item domain.ArticleEntity var item entity.ArticleEntity
if source.Content == "" && source.Url != "" { if source.Content == "" && source.Url != "" {
item = rc.convertPicturePost(source) item = rc.convertPicturePost(source)
@ -129,8 +130,8 @@ func (rc *RedditClient) convertToArticle(source domain.RedditPost) (domain.Artic
return item, nil return item, nil
} }
func (rc *RedditClient) convertPicturePost(source domain.RedditPost) domain.ArticleEntity { func (rc *RedditClient) convertPicturePost(source domain.RedditPost) entity.ArticleEntity {
var item = domain.ArticleEntity{ var item = entity.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Title: source.Title, Title: source.Title,
Tags: fmt.Sprintf("%v", rc.record.Tags), Tags: fmt.Sprintf("%v", rc.record.Tags),
@ -145,8 +146,8 @@ func (rc *RedditClient) convertPicturePost(source domain.RedditPost) domain.Arti
return item return item
} }
func (rc *RedditClient) convertTextPost(source domain.RedditPost) domain.ArticleEntity { func (rc *RedditClient) convertTextPost(source domain.RedditPost) entity.ArticleEntity {
var item = domain.ArticleEntity{ var item = entity.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,
@ -158,8 +159,8 @@ func (rc *RedditClient) convertTextPost(source domain.RedditPost) domain.Article
return item return item
} }
func (rc *RedditClient) convertVideoPost(source domain.RedditPost) domain.ArticleEntity { func (rc *RedditClient) convertVideoPost(source domain.RedditPost) entity.ArticleEntity {
var item = domain.ArticleEntity{ var item = entity.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,
@ -172,8 +173,8 @@ func (rc *RedditClient) convertVideoPost(source domain.RedditPost) domain.Articl
} }
// This post is nothing more then a redirect to another location. // This post is nothing more then a redirect to another location.
func (rc *RedditClient) convertRedirectPost(source domain.RedditPost) domain.ArticleEntity { func (rc *RedditClient) convertRedirectPost(source domain.RedditPost) entity.ArticleEntity {
var item = domain.ArticleEntity{ var item = entity.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,

View File

@ -3,11 +3,12 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var RedditRecord domain.SourceEntity = domain.SourceEntity{ var RedditRecord entity.SourceEntity = entity.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "dadjokes", DisplayName: "dadjokes",
Source: domain.SourceCollectorRss, Source: domain.SourceCollectorRss,

View File

@ -3,19 +3,19 @@ package input
import ( import (
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
) )
type FeedInput interface { type FeedInput interface {
GetArticles() (domain.ArticleEntity, error) GetArticles() (entity.ArticleEntity, error)
} }
type rssClient struct { type rssClient struct {
SourceRecord domain.SourceEntity SourceRecord entity.SourceEntity
} }
func NewRssClient(sourceRecord domain.SourceEntity) rssClient { func NewRssClient(sourceRecord entity.SourceEntity) rssClient {
client := rssClient{ client := rssClient{
SourceRecord: sourceRecord, SourceRecord: sourceRecord,
} }
@ -23,7 +23,7 @@ func NewRssClient(sourceRecord domain.SourceEntity) rssClient {
return client return client
} }
func (rc rssClient) GetArticles() ([]domain.ArticleEntity, error) { func (rc rssClient) GetArticles() ([]entity.ArticleEntity, error) {
parser := gofeed.NewParser() parser := gofeed.NewParser()
feed, err := parser.ParseURL(rc.SourceRecord.Url) feed, err := parser.ParseURL(rc.SourceRecord.Url)
if err != nil { if err != nil {
@ -31,9 +31,9 @@ func (rc rssClient) GetArticles() ([]domain.ArticleEntity, error) {
} }
sourceTags := strings.Split(rc.SourceRecord.Tags, ",") sourceTags := strings.Split(rc.SourceRecord.Tags, ",")
var articles []domain.ArticleEntity var articles []entity.ArticleEntity
for _, post := range feed.Items { for _, post := range feed.Items {
article := domain.ArticleEntity{ article := entity.ArticleEntity{
SourceID: rc.SourceRecord.ID, SourceID: rc.SourceRecord.ID,
Title: post.Title, Title: post.Title,
Description: post.Content, Description: post.Content,

View File

@ -3,11 +3,12 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var rssRecord = domain.SourceEntity{ var rssRecord = entity.SourceEntity{
ID: 1, ID: 1,
DisplayName: "ArsTechnica", DisplayName: "ArsTechnica",
Url: "https://feeds.arstechnica.com/arstechnica/index", Url: "https://feeds.arstechnica.com/arstechnica/index",
@ -27,7 +28,7 @@ func TestRssGetFeed(t *testing.T) {
} }
func TestRssAgainstGita(t *testing.T) { func TestRssAgainstGita(t *testing.T) {
client := input.NewRssClient(domain.SourceEntity{ client := input.NewRssClient(entity.SourceEntity{
ID: 2, ID: 2,
DisplayName: "Gitea - Newsbot-api", DisplayName: "Gitea - Newsbot-api",
Source: domain.SourceCollectorRss, Source: domain.SourceCollectorRss,

View File

@ -6,13 +6,13 @@ import (
"strings" "strings"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"github.com/nicklaw5/helix/v2" "github.com/nicklaw5/helix/v2"
) )
type TwitchClient struct { type TwitchClient struct {
SourceRecord domain.SourceEntity SourceRecord entity.SourceEntity
// config // config
monitorClips string monitorClips string
@ -71,7 +71,7 @@ func initTwitchApi(ClientId string, ClientSecret string) (helix.Client, error) {
} }
// This will let you replace the bound source record to keep the same session alive. // This will let you replace the bound source record to keep the same session alive.
func (tc *TwitchClient) ReplaceSourceRecord(source domain.SourceEntity) { func (tc *TwitchClient) ReplaceSourceRecord(source entity.SourceEntity) {
tc.SourceRecord = source tc.SourceRecord = source
} }
@ -86,8 +86,8 @@ func (tc *TwitchClient) Login() error {
return nil return nil
} }
func (tc *TwitchClient) GetContent() ([]domain.ArticleEntity, error) { func (tc *TwitchClient) GetContent() ([]entity.ArticleEntity, error) {
var items []domain.ArticleEntity var items []entity.ArticleEntity
user, err := tc.GetUserDetails() user, err := tc.GetUserDetails()
if err != nil { if err != nil {
@ -100,7 +100,7 @@ func (tc *TwitchClient) GetContent() ([]domain.ArticleEntity, error) {
} }
for _, video := range posts { for _, video := range posts {
var article domain.ArticleEntity var article entity.ArticleEntity
AuthorName, err := tc.ExtractAuthor(video) AuthorName, err := tc.ExtractAuthor(video)
if err != nil { if err != nil {

View File

@ -4,17 +4,18 @@ import (
"log" "log"
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var TwitchSourceRecord = domain.SourceEntity{ var TwitchSourceRecord = entity.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "nintendo", DisplayName: "nintendo",
Source: domain.SourceCollectorTwitch, Source: domain.SourceCollectorTwitch,
} }
var TwitchInvalidRecord = domain.SourceEntity{ var TwitchInvalidRecord = entity.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "EvilNintendo", DisplayName: "EvilNintendo",
Source: domain.SourceCollectorTwitch, Source: domain.SourceCollectorTwitch,

View File

@ -11,11 +11,11 @@ import (
"github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/launcher"
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
) )
type YoutubeClient struct { type YoutubeClient struct {
record domain.SourceEntity record entity.SourceEntity
// internal variables at time of collection // internal variables at time of collection
channelID string channelID string
@ -25,7 +25,7 @@ type YoutubeClient struct {
//debug bool //debug bool
// cache config // cache config
cacheGroup string //cacheGroup string
} }
var ( var (
@ -36,17 +36,16 @@ var (
const YOUTUBE_FEED_URL string = "https://www.youtube.com/feeds/videos.xml?channel_id=" const YOUTUBE_FEED_URL string = "https://www.youtube.com/feeds/videos.xml?channel_id="
func NewYoutubeClient(Record domain.SourceEntity) YoutubeClient { func NewYoutubeClient(Record entity.SourceEntity) YoutubeClient {
yc := YoutubeClient{ yc := YoutubeClient{
record: Record, record: Record,
cacheGroup: "youtube",
} }
return yc return yc
} }
// CheckSource will go and run all the commands needed to process a source. // CheckSource will go and run all the commands needed to process a source.
func (yc *YoutubeClient) GetContent() ([]domain.ArticleEntity, error) { func (yc *YoutubeClient) GetContent() ([]entity.ArticleEntity, error) {
var items []domain.ArticleEntity var items []entity.ArticleEntity
docParser, err := yc.GetParser(yc.record.Url) docParser, err := yc.GetParser(yc.record.Url)
if err != nil { if err != nil {
return items, err return items, err
@ -246,7 +245,7 @@ func (yc *YoutubeClient) CheckUriCache(uri *string) bool {
return false return false
} }
func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) domain.ArticleEntity { func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) entity.ArticleEntity {
parser, err := yc.GetParser(item.Link) parser, err := yc.GetParser(item.Link)
if err != nil { if err != nil {
log.Printf("[YouTube] Unable to process %v, submit this link as an issue.\n", item.Link) log.Printf("[YouTube] Unable to process %v, submit this link as an issue.\n", item.Link)
@ -264,7 +263,7 @@ func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) domain.ArticleEntit
log.Printf("[YouTube] %v", msg) log.Printf("[YouTube] %v", msg)
} }
var article = domain.ArticleEntity{ var article = entity.ArticleEntity{
SourceID: yc.record.ID, SourceID: yc.record.ID,
Tags: tags, Tags: tags,
Title: item.Title, Title: item.Title,

View File

@ -3,11 +3,12 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var YouTubeRecord = domain.SourceEntity{ var YouTubeRecord = entity.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "dadjokes", DisplayName: "dadjokes",
Source: domain.SourceCollectorReddit, Source: domain.SourceCollectorReddit,