updated to models

This commit is contained in:
James Tombleson 2022-12-10 11:13:45 -08:00
parent 53f02585b9
commit b0a78c4a1e
6 changed files with 25 additions and 25 deletions

View File

@ -3,7 +3,7 @@ package cache
import (
"time"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
)
type CacheClient struct {
@ -19,7 +19,7 @@ func NewCacheClient(group string) CacheClient {
}
func (cc *CacheClient) Insert(key string, value string) {
item := model.CacheItem{
item := models.CacheItem{
Key: key,
Value: value,
Group: cc.group,
@ -29,7 +29,7 @@ func (cc *CacheClient) Insert(key string, value string) {
cacheStorage = append(cacheStorage, &item)
}
func (cc *CacheClient) FindByKey(key string) (*model.CacheItem, error) {
func (cc *CacheClient) FindByKey(key string) (*models.CacheItem, error) {
for _, item := range cacheStorage {
if item.Group != cc.group {
continue
@ -46,10 +46,10 @@ func (cc *CacheClient) FindByKey(key string) (*model.CacheItem, error) {
return item, nil
}
return &model.CacheItem{}, ErrCacheRecordMissing
return &models.CacheItem{}, ErrCacheRecordMissing
}
func (cc *CacheClient) FindByValue(value string) (*model.CacheItem, error) {
func (cc *CacheClient) FindByValue(value string) (*models.CacheItem, error) {
for _, item := range cacheStorage {
if item.Group != cc.group {
continue
@ -65,5 +65,5 @@ func (cc *CacheClient) FindByValue(value string) (*model.CacheItem, error) {
}
return item, nil
}
return &model.CacheItem{}, ErrCacheRecordMissing
return &models.CacheItem{}, ErrCacheRecordMissing
}

View File

@ -3,11 +3,11 @@ package cache
import (
"errors"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
)
var (
cacheStorage []*model.CacheItem
cacheStorage []*models.CacheItem
ErrCacheRecordMissing = errors.New("unable to find the requested record")
)

View File

@ -3,7 +3,7 @@ package cache
import (
"time"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
)
// When a record becomes tainted, it needs to be renewed or it will be dropped from the cache.
@ -36,8 +36,8 @@ func (cam CacheAgeMonitor) CheckExpiredEntries() {
}
// This creates a new slice and skips over the item that needs to be dropped
func (cam CacheAgeMonitor) removeEntry(index int) []*model.CacheItem {
var temp []*model.CacheItem
func (cam CacheAgeMonitor) removeEntry(index int) []*models.CacheItem {
var temp []*models.CacheItem
for i, item := range cacheStorage {
if i != index {
temp = append(temp, item)

View File

@ -12,7 +12,7 @@ import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/jtom38/newsbot/collector/database"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
"github.com/jtom38/newsbot/collector/services/config"
)
@ -65,8 +65,8 @@ func (rc *RedditClient) GetPage(parser *rod.Browser, url string) *rod.Page {
// GetContent() reaches out to Reddit and pulls the Json data.
// It will then convert the data to a struct and return the struct.
func (rc *RedditClient) GetContent() (model.RedditJsonContent, error) {
var items model.RedditJsonContent = model.RedditJsonContent{}
func (rc *RedditClient) GetContent() (models.RedditJsonContent, error) {
var items models.RedditJsonContent = models.RedditJsonContent{}
// TODO Wire this to support the config options
Url := fmt.Sprintf("%v.json", rc.record.Url)
@ -88,7 +88,7 @@ func (rc *RedditClient) GetContent() (model.RedditJsonContent, error) {
return items, nil
}
func (rc *RedditClient) ConvertToArticles(items model.RedditJsonContent) []database.Article {
func (rc *RedditClient) ConvertToArticles(items models.RedditJsonContent) []database.Article {
var redditArticles []database.Article
for _, item := range items.Data.Children {
var article database.Article
@ -104,7 +104,7 @@ func (rc *RedditClient) ConvertToArticles(items model.RedditJsonContent) []datab
// ConvertToArticle() will take the reddit model struct and convert them over to Article structs.
// This data can be passed to the database.
func (rc *RedditClient) convertToArticle(source model.RedditPost) (database.Article, error) {
func (rc *RedditClient) convertToArticle(source models.RedditPost) (database.Article, error) {
var item database.Article
if source.Content == "" && source.Url != "" {
@ -131,7 +131,7 @@ func (rc *RedditClient) convertToArticle(source model.RedditPost) (database.Arti
return item, nil
}
func (rc *RedditClient) convertPicturePost(source model.RedditPost) database.Article {
func (rc *RedditClient) convertPicturePost(source models.RedditPost) database.Article {
var item = database.Article{
Sourceid: rc.record.ID,
Title: source.Title,
@ -149,7 +149,7 @@ func (rc *RedditClient) convertPicturePost(source model.RedditPost) database.Art
return item
}
func (rc *RedditClient) convertTextPost(source model.RedditPost) database.Article {
func (rc *RedditClient) convertTextPost(source models.RedditPost) database.Article {
var item = database.Article{
Sourceid: rc.record.ID,
Tags: "a",
@ -164,7 +164,7 @@ func (rc *RedditClient) convertTextPost(source model.RedditPost) database.Articl
return item
}
func (rc *RedditClient) convertVideoPost(source model.RedditPost) database.Article {
func (rc *RedditClient) convertVideoPost(source models.RedditPost) database.Article {
var item = database.Article{
Sourceid: rc.record.ID,
Tags: "a",
@ -180,7 +180,7 @@ func (rc *RedditClient) convertVideoPost(source model.RedditPost) database.Artic
}
// This post is nothing more then a redirect to another location.
func (rc *RedditClient) convertRedirectPost(source model.RedditPost) database.Article {
func (rc *RedditClient) convertRedirectPost(source models.RedditPost) database.Article {
var item = database.Article{
Sourceid: rc.record.ID,
Tags: "a",

View File

@ -4,16 +4,16 @@ import (
"fmt"
"log"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
"github.com/jtom38/newsbot/collector/services/cache"
"github.com/mmcdole/gofeed"
)
type rssClient struct {
SourceRecord model.Sources
SourceRecord models.Sources
}
func NewRssClient(sourceRecord model.Sources) rssClient {
func NewRssClient(sourceRecord models.Sources) rssClient {
client := rssClient{
SourceRecord: sourceRecord,
}

View File

@ -3,11 +3,11 @@ package input_test
import (
"testing"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/domain/models"
"github.com/jtom38/newsbot/collector/services/input"
)
var rssRecord = model.Sources{
var rssRecord = models.Sources{
ID: 1,
Name: "ArsTechnica",
Url: "https://feeds.arstechnica.com/arstechnica/index",