Compare commits

..

No commits in common. "4e9a17209f02985ba5cffe09313679361609a247" and "5b8cf6dfa6ccf13eec95f7d12e578c0b9fe5a152" have entirely different histories.

36 changed files with 237 additions and 246 deletions

View File

@ -1,4 +1,4 @@
package entity package domain
import ( import (
"time" "time"

View File

@ -4,8 +4,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -41,7 +41,7 @@ func (s *Handler) listArticles(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
resp.Payload = dtoconv.ArticlesToDto(res) resp.Payload = services.ArticlesToDto(res)
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -79,7 +79,7 @@ func (s *Handler) getArticle(c echo.Context) error {
} }
var dtos []domain.ArticleDto var dtos []domain.ArticleDto
dtos = append(dtos, dtoconv.ArticleToDto(item)) dtos = append(dtos, services.ArticleToDto(item))
p.Payload = dtos p.Payload = dtos
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
@ -123,8 +123,8 @@ func (s *Handler) getArticleDetails(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
p.Payload.Article = dtoconv.ArticleToDto(article) p.Payload.Article = services.ArticleToDto(article)
p.Payload.Source = dtoconv.SourceToDto(source) p.Payload.Source = services.SourceToDto(source)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -168,6 +168,6 @@ func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, err) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = dtoconv.ArticlesToDto(items) p.Payload = services.ArticlesToDto(items)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

View File

@ -5,8 +5,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -35,7 +35,7 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, err) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = dtoconv.DiscordWebhooksToDto(res) p.Payload = services.DiscordWebhooksToDto(res)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -71,7 +71,7 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(res)) dtos = append(dtos, services.DiscordWebhookToDto(res))
p.Payload = dtos p.Payload = dtos
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -114,7 +114,7 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
p.Payload = dtoconv.DiscordWebhooksToDto(res) p.Payload = services.DiscordWebhooksToDto(res)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -180,7 +180,7 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, services.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -239,7 +239,7 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, services.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -290,7 +290,7 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, services.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -344,7 +344,7 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) dtos = append(dtos, services.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,

View File

@ -13,7 +13,7 @@ import (
swagger "github.com/swaggo/echo-swagger" swagger "github.com/swaggo/echo-swagger"
_ "git.jamestombleson.com/jtom38/newsbot-api/docs" _ "git.jamestombleson.com/jtom38/newsbot-api/docs"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
) )

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )

View File

@ -6,8 +6,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -43,7 +43,7 @@ func (s *Handler) listSources(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
resp.Payload = dtoconv.SourcesToDto(items) resp.Payload = services.SourcesToDto(items)
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -88,7 +88,7 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
}) })
} }
resp.Payload = dtoconv.SourcesToDto(items) resp.Payload = services.SourcesToDto(items)
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -127,7 +127,7 @@ func (s *Handler) getSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -169,7 +169,7 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -224,7 +224,7 @@ func (s *Handler) newRedditSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -264,7 +264,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -282,7 +282,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -323,7 +323,7 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -341,7 +341,7 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name) item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
@ -399,7 +399,7 @@ func (s *Handler) newRssSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -446,7 +446,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
} }
var items []domain.SourceDto var items []domain.SourceDto
items = append(items, dtoconv.SourceToDto(item)) items = append(items, services.SourceToDto(item))
return c.JSON(http.StatusOK, domain.SourcesResponse{ return c.JSON(http.StatusOK, domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -499,7 +499,7 @@ func (s *Handler) disableSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -547,7 +547,7 @@ func (s *Handler) enableSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, dtoconv.SourceToDto(item)) dto = append(dto, services.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
@ -16,7 +16,7 @@ type AlertDiscordRepo interface {
SoftDelete(ctx context.Context, id int64) (int64, error) SoftDelete(ctx context.Context, id int64) (int64, error)
Restore(ctx context.Context, id int64) (int64, error) Restore(ctx context.Context, id int64) (int64, error)
Delete(ctx context.Context, id int64) (int64, error) Delete(ctx context.Context, id int64) (int64, error)
ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.AlertDiscordEntity, error) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.AlertDiscordEntity, error)
} }
type alertDiscordRepository struct { type alertDiscordRepository struct {
@ -61,7 +61,7 @@ func (r alertDiscordRepository) Delete(ctx context.Context, id int64) (int64, er
return deleteFromTable(ctx, r.conn, "AlertDiscord", id) return deleteFromTable(ctx, r.conn, "AlertDiscord", id)
} }
func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.AlertDiscordEntity, error) { func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.AlertDiscordEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("AlertDiscord") builder.From("AlertDiscord")
@ -74,19 +74,19 @@ func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int,
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.AlertDiscordEntity{}, err return []domain.AlertDiscordEntity{}, err
} }
data := r.processRows(rows) data := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.AlertDiscordEntity{}, errors.New(ErrUserNotFound) return []domain.AlertDiscordEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
func (ur alertDiscordRepository) processRows(rows *sql.Rows) []entity.AlertDiscordEntity { func (ur alertDiscordRepository) processRows(rows *sql.Rows) []domain.AlertDiscordEntity {
items := []entity.AlertDiscordEntity{} items := []domain.AlertDiscordEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -105,7 +105,7 @@ func (ur alertDiscordRepository) processRows(rows *sql.Rows) []entity.AlertDisco
fmt.Println(err) fmt.Println(err)
} }
item := entity.AlertDiscordEntity{ item := domain.AlertDiscordEntity{
ID: id, ID: id,
CreatedAt: createdAt, CreatedAt: createdAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
) )

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
@ -17,14 +17,14 @@ const (
) )
type ArticlesRepo interface { type ArticlesRepo interface {
GetById(ctx context.Context, id int64) (entity.ArticleEntity, error) GetById(ctx context.Context, id int64) (domain.ArticleEntity, error)
GetByUrl(ctx context.Context, url string) (entity.ArticleEntity, error) GetByUrl(ctx context.Context, url string) (domain.ArticleEntity, error)
ListTop(ctx context.Context, limit int) ([]entity.ArticleEntity, error) ListTop(ctx context.Context, limit int) ([]domain.ArticleEntity, error)
ListByPage(ctx context.Context, page, limit int) ([]entity.ArticleEntity, error) ListByPage(ctx context.Context, page, limit int) ([]domain.ArticleEntity, error)
ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]entity.ArticleEntity, error) ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]domain.ArticleEntity, error)
ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]entity.ArticleEntity, error) ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]domain.ArticleEntity, error)
Create(ctx context.Context, sourceId int64, tags, title, url, thumbnailUrl, description, authorName, authorImageUrl string, pubDate time.Time, isVideo bool) (int64, error) Create(ctx context.Context, sourceId int64, tags, title, url, thumbnailUrl, description, authorName, authorImageUrl string, pubDate time.Time, isVideo bool) (int64, error)
CreateFromEntity(ctx context.Context, entity entity.ArticleEntity) (int64, error) CreateFromEntity(ctx context.Context, entity domain.ArticleEntity) (int64, error)
} }
type ArticleRepository struct { type ArticleRepository struct {
@ -41,7 +41,7 @@ func NewArticleRepository(conn *sql.DB) ArticleRepository {
} }
} }
func (ar ArticleRepository) GetById(ctx context.Context, id int64) (entity.ArticleEntity, error) { func (ar ArticleRepository) GetById(ctx context.Context, id int64) (domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles").Where( builder.From("articles").Where(
@ -52,18 +52,18 @@ func (ar ArticleRepository) GetById(ctx context.Context, id int64) (entity.Artic
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.ArticleEntity{}, err return domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.ArticleEntity{}, errors.New(ErrUserNotFound) return domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data[0], nil return data[0], nil
} }
func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (entity.ArticleEntity, error) { func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles").Where( builder.From("articles").Where(
@ -74,18 +74,18 @@ func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (entity.Ar
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.ArticleEntity{}, err return domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.ArticleEntity{}, errors.New(ErrUserNotFound) return domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data[0], nil return data[0], nil
} }
func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]entity.ArticleEntity, error) { func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles") builder.From("articles")
@ -94,18 +94,18 @@ func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]entity.Ar
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.ArticleEntity{}, err return []domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound) return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]entity.ArticleEntity, error) { func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles") builder.From("articles")
@ -116,18 +116,18 @@ func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.ArticleEntity{}, err return []domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound) return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]entity.ArticleEntity, error) { func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles") builder.From("articles")
@ -140,17 +140,17 @@ func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit i
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.ArticleEntity{}, err return []domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound) return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]entity.ArticleEntity, error) { func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]domain.ArticleEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("articles") builder.From("articles")
@ -167,12 +167,12 @@ func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourc
query, args := builder.Build() query, args := builder.Build()
rows, err := ar.conn.QueryContext(ctx, query, args...) rows, err := ar.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.ArticleEntity{}, err return []domain.ArticleEntity{}, err
} }
data := ar.processRows(rows) data := ar.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound) return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
@ -193,12 +193,12 @@ func (ar ArticleRepository) Create(ctx context.Context, sourceId int64, tags, ti
return 1, nil return 1, nil
} }
func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity entity.ArticleEntity) (int64, error) { func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity domain.ArticleEntity) (int64, error) {
dt := time.Now() dt := time.Now()
queryBuilder := sqlbuilder.NewInsertBuilder() queryBuilder := sqlbuilder.NewInsertBuilder()
queryBuilder.InsertInto("articles") queryBuilder.InsertInto("articles")
queryBuilder.Cols("UpdatedAt", "CreatedAt", "DeletedAt", "SourceId", "Tags", "Title", "Url", "PubDate", "IsVideo", "ThumbnailUrl", "Description", "AuthorName", "AuthorImageUrl") queryBuilder.Cols("UpdatedAt", "CreatedAt", "DeletedAt", "SourceId", "Tags", "Title", "Url", "PubDate", "IsVideo", "ThumbnailUrl", "Description", "AuthorName", "AuthorImageUrl")
queryBuilder.Values(dt, dt, timeZero, entity.SourceID, entity.Tags, entity.Title, entity.Url, entity.PubDate, entity.IsVideo, entity.Thumbnail, entity.Description, entity.AuthorName, entity.AuthorImageUrl) queryBuilder.Values(dt, dt, timeZero, entity.SourceID, entity.Tags, entity.Title, entity.Url, entity.PubDate, entity.IsVideo, entity.Thumbnail, entity.Description, entity.AuthorName, entity.AuthorImageUrl)
query, args := queryBuilder.Build() query, args := queryBuilder.Build()
_, err := ar.conn.ExecContext(ctx, query, args...) _, err := ar.conn.ExecContext(ctx, query, args...)
@ -209,8 +209,8 @@ func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity entity.
return 1, nil return 1, nil
} }
func (ur ArticleRepository) processRows(rows *sql.Rows) []entity.ArticleEntity { func (ur ArticleRepository) processRows(rows *sql.Rows) []domain.ArticleEntity {
items := []entity.ArticleEntity{} items := []domain.ArticleEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -237,7 +237,7 @@ func (ur ArticleRepository) processRows(rows *sql.Rows) []entity.ArticleEntity {
fmt.Println(err) fmt.Println(err)
} }
item := entity.ArticleEntity{ item := domain.ArticleEntity{
ID: id, ID: id,
CreatedAt: createdAt, CreatedAt: createdAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,

View File

@ -5,7 +5,7 @@ import (
"database/sql" "database/sql"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
@ -16,10 +16,10 @@ type DiscordWebHookRepo interface {
SoftDelete(ctx context.Context, id int64) (int64, error) SoftDelete(ctx context.Context, id int64) (int64, error)
Restore(ctx context.Context, id int64) (int64, error) Restore(ctx context.Context, id int64) (int64, error)
Delete(ctx context.Context, id int64) (int64, error) Delete(ctx context.Context, id int64) (int64, error)
GetById(ctx context.Context, id int64) (entity.DiscordWebHookEntity, error) GetById(ctx context.Context, id int64) (domain.DiscordWebHookEntity, error)
GetByUrl(ctx context.Context, url string) (entity.DiscordWebHookEntity, error) GetByUrl(ctx context.Context, url string) (domain.DiscordWebHookEntity, error)
ListByServerName(ctx context.Context, name string) ([]entity.DiscordWebHookEntity, error) ListByServerName(ctx context.Context, name string) ([]domain.DiscordWebHookEntity, error)
ListByServerAndChannel(ctx context.Context, server, channel string) ([]entity.DiscordWebHookEntity, error) ListByServerAndChannel(ctx context.Context, server, channel string) ([]domain.DiscordWebHookEntity, error)
} }
type discordWebHookRepository struct { type discordWebHookRepository struct {
@ -100,7 +100,7 @@ func (r discordWebHookRepository) Delete(ctx context.Context, id int64) (int64,
return deleteFromTable(ctx, r.conn, "DiscordWebHooks", id) return deleteFromTable(ctx, r.conn, "DiscordWebHooks", id)
} }
func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (entity.DiscordWebHookEntity, error) { func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (domain.DiscordWebHookEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("DiscordWebHooks").Where( builder.From("DiscordWebHooks").Where(
@ -111,18 +111,18 @@ func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (entity
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.DiscordWebHookEntity{}, err return domain.DiscordWebHookEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.DiscordWebHookEntity{}, err return domain.DiscordWebHookEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (entity.DiscordWebHookEntity, error) { func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (domain.DiscordWebHookEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("DiscordWebHooks").Where( builder.From("DiscordWebHooks").Where(
@ -133,18 +133,18 @@ func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (ent
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.DiscordWebHookEntity{}, err return domain.DiscordWebHookEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.DiscordWebHookEntity{}, err return domain.DiscordWebHookEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r discordWebHookRepository) ListByServerName(ctx context.Context, name string) ([]entity.DiscordWebHookEntity, error) { func (r discordWebHookRepository) ListByServerName(ctx context.Context, name string) ([]domain.DiscordWebHookEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("DiscordWebHooks").Where( builder.From("DiscordWebHooks").Where(
@ -154,18 +154,18 @@ func (r discordWebHookRepository) ListByServerName(ctx context.Context, name str
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.DiscordWebHookEntity{}, err return []domain.DiscordWebHookEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.DiscordWebHookEntity{}, err return []domain.DiscordWebHookEntity{}, err
} }
return data, nil return data, nil
} }
func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, server, channel string) ([]entity.DiscordWebHookEntity, error) { func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, server, channel string) ([]domain.DiscordWebHookEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("DiscordWebHooks").Where( builder.From("DiscordWebHooks").Where(
@ -176,19 +176,19 @@ func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, se
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.DiscordWebHookEntity{}, err return []domain.DiscordWebHookEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.DiscordWebHookEntity{}, err return []domain.DiscordWebHookEntity{}, err
} }
return data, nil return data, nil
} }
func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]entity.DiscordWebHookEntity, error) { func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]domain.DiscordWebHookEntity, error) {
items := []entity.DiscordWebHookEntity{} items := []domain.DiscordWebHookEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -209,7 +209,7 @@ func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]entity.DiscordW
return items, err return items, err
} }
item := entity.DiscordWebHookEntity{ item := domain.DiscordWebHookEntity{
ID: id, ID: id,
CreatedAt: createdAt, CreatedAt: createdAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
@ -17,7 +17,7 @@ const (
type RefreshToken interface { type RefreshToken interface {
Create(ctx context.Context, username string, token string) (int64, error) Create(ctx context.Context, username string, token string) (int64, error)
GetByUsername(ctx context.Context, name string) (entity.RefreshTokenEntity, error) GetByUsername(ctx context.Context, name string) (domain.RefreshTokenEntity, error)
DeleteById(ctx context.Context, id int64) (int64, error) DeleteById(ctx context.Context, id int64) (int64, error)
} }
@ -47,7 +47,7 @@ func (rt RefreshTokenRepository) Create(ctx context.Context, username string, to
return 1, nil return 1, nil
} }
func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string) (entity.RefreshTokenEntity, error) { func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string) (domain.RefreshTokenEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*").From(refreshTokenTableName).Where( builder.Select("*").From(refreshTokenTableName).Where(
builder.E("Username", name), builder.E("Username", name),
@ -56,12 +56,12 @@ func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string)
query, args := builder.Build() query, args := builder.Build()
rows, err := rt.connection.QueryContext(ctx, query, args...) rows, err := rt.connection.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.RefreshTokenEntity{}, err return domain.RefreshTokenEntity{}, err
} }
data := rt.processRows(rows) data := rt.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.RefreshTokenEntity{}, errors.New("no token found for user") return domain.RefreshTokenEntity{}, errors.New("no token found for user")
} }
return data[0], nil return data[0], nil
@ -83,8 +83,8 @@ func (rt RefreshTokenRepository) DeleteById(ctx context.Context, id int64) (int6
return rows.RowsAffected() return rows.RowsAffected()
} }
func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []entity.RefreshTokenEntity { func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []domain.RefreshTokenEntity {
items := []entity.RefreshTokenEntity{} items := []domain.RefreshTokenEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -99,7 +99,7 @@ func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []entity.RefreshTok
fmt.Println(err) fmt.Println(err)
} }
item := entity.RefreshTokenEntity{ item := domain.RefreshTokenEntity{
ID: id, ID: id,
Username: username, Username: username,
Token: token, Token: token,
@ -107,7 +107,7 @@ func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []entity.RefreshTok
UpdatedAt: updatedAt, UpdatedAt: updatedAt,
} }
if deletedAt.Valid { if (deletedAt.Valid) {
item.DeletedAt = deletedAt.Time item.DeletedAt = deletedAt.Time
} }

View File

@ -5,18 +5,18 @@ import (
"database/sql" "database/sql"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
type Sources interface { type Sources interface {
Create(ctx context.Context, source, displayName, url, tags string, enabled bool) (int64, error) Create(ctx context.Context, source, displayName, url, tags string, enabled bool) (int64, error)
GetById(ctx context.Context, id int64) (entity.SourceEntity, error) GetById(ctx context.Context, id int64) (domain.SourceEntity, error)
GetByDisplayName(ctx context.Context, displayName string) (entity.SourceEntity, error) GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error)
GetBySource(ctx context.Context, source string) (entity.SourceEntity, error) GetBySource(ctx context.Context, source string) (domain.SourceEntity, error)
GetBySourceAndName(ctx context.Context, source, name string) (entity.SourceEntity, error) GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error)
List(ctx context.Context, page, limit int) ([]entity.SourceEntity, error) List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error)
ListBySource(ctx context.Context, page, limit int, source string) ([]entity.SourceEntity, error) ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error)
Enable(ctx context.Context, id int64) (int64, error) Enable(ctx context.Context, id int64) (int64, error)
Disable(ctx context.Context, id int64) (int64, error) Disable(ctx context.Context, id int64) (int64, error)
SoftDelete(ctx context.Context, id int64) (int64, error) SoftDelete(ctx context.Context, id int64) (int64, error)
@ -50,7 +50,7 @@ func (r sourceRepository) Create(ctx context.Context, source, displayName, url,
return 1, nil return 1, nil
} }
func (r sourceRepository) GetById(ctx context.Context, id int64) (entity.SourceEntity, error) { func (r sourceRepository) GetById(ctx context.Context, id int64) (domain.SourceEntity, error) {
b := sqlbuilder.NewSelectBuilder() b := sqlbuilder.NewSelectBuilder()
b.Select("*") b.Select("*")
b.From("Sources").Where( b.From("Sources").Where(
@ -61,18 +61,18 @@ func (r sourceRepository) GetById(ctx context.Context, id int64) (entity.SourceE
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r sourceRepository) GetByDisplayName(ctx context.Context, displayName string) (entity.SourceEntity, error) { func (r sourceRepository) GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error) {
b := sqlbuilder.NewSelectBuilder() b := sqlbuilder.NewSelectBuilder()
b.Select("*") b.Select("*")
b.From("Sources").Where( b.From("Sources").Where(
@ -83,18 +83,18 @@ func (r sourceRepository) GetByDisplayName(ctx context.Context, displayName stri
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r sourceRepository) GetBySource(ctx context.Context, source string) (entity.SourceEntity, error) { func (r sourceRepository) GetBySource(ctx context.Context, source string) (domain.SourceEntity, error) {
b := sqlbuilder.NewSelectBuilder() b := sqlbuilder.NewSelectBuilder()
b.Select("*") b.Select("*")
b.From("Sources").Where( b.From("Sources").Where(
@ -105,18 +105,18 @@ func (r sourceRepository) GetBySource(ctx context.Context, source string) (entit
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name string) (entity.SourceEntity, error) { func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error) {
b := sqlbuilder.NewSelectBuilder() b := sqlbuilder.NewSelectBuilder()
b.Select("*") b.Select("*")
b.From("Sources").Where( b.From("Sources").Where(
@ -128,18 +128,18 @@ func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name s
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.SourceEntity{}, err return domain.SourceEntity{}, err
} }
return data[0], nil return data[0], nil
} }
func (r sourceRepository) List(ctx context.Context, page, limit int) ([]entity.SourceEntity, error) { func (r sourceRepository) List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("Sources") builder.From("Sources")
@ -149,18 +149,18 @@ func (r sourceRepository) List(ctx context.Context, page, limit int) ([]entity.S
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.SourceEntity{}, err return []domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.SourceEntity{}, err return []domain.SourceEntity{}, err
} }
return data, nil return data, nil
} }
func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, source string) ([]entity.SourceEntity, error) { func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("Sources") builder.From("Sources")
@ -173,12 +173,12 @@ func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, sou
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.SourceEntity{}, err return []domain.SourceEntity{}, err
} }
data, err := r.processRows(rows) data, err := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.SourceEntity{}, err return []domain.SourceEntity{}, err
} }
return data, nil return data, nil
@ -236,8 +236,8 @@ func (r sourceRepository) Delete(ctx context.Context, id int64) (int64, error) {
return deleteFromTable(ctx, r.conn, "Sources", id) return deleteFromTable(ctx, r.conn, "Sources", id)
} }
func (r sourceRepository) processRows(rows *sql.Rows) ([]entity.SourceEntity, error) { func (r sourceRepository) processRows(rows *sql.Rows) ([]domain.SourceEntity, error) {
items := []entity.SourceEntity{} items := []domain.SourceEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -258,7 +258,7 @@ func (r sourceRepository) processRows(rows *sql.Rows) ([]entity.SourceEntity, er
return items, err return items, err
} }
item := entity.SourceEntity{ item := domain.SourceEntity{
ID: id, ID: id,
CreatedAt: createdAt, CreatedAt: createdAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
) )

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
) )
@ -16,7 +16,7 @@ type UserSourceRepo interface {
SoftDelete(ctx context.Context, id int64) (int64, error) SoftDelete(ctx context.Context, id int64) (int64, error)
Restore(ctx context.Context, id int64) (int64, error) Restore(ctx context.Context, id int64) (int64, error)
Delete(ctx context.Context, id int64) (int64, error) Delete(ctx context.Context, id int64) (int64, error)
ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.UserSourceSubscriptionEntity, error) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.UserSourceSubscriptionEntity, error)
} }
type userSourceRepository struct { type userSourceRepository struct {
@ -61,7 +61,7 @@ func (r userSourceRepository) Delete(ctx context.Context, id int64) (int64, erro
return deleteFromTable(ctx, r.conn, "UserSourceSubscriptions", id) return deleteFromTable(ctx, r.conn, "UserSourceSubscriptions", id)
} }
func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.UserSourceSubscriptionEntity, error) { func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.UserSourceSubscriptionEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*") builder.Select("*")
builder.From("UserSourceSubscriptions") builder.From("UserSourceSubscriptions")
@ -74,19 +74,19 @@ func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, u
query, args := builder.Build() query, args := builder.Build()
rows, err := r.conn.QueryContext(ctx, query, args...) rows, err := r.conn.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return []entity.UserSourceSubscriptionEntity{}, err return []domain.UserSourceSubscriptionEntity{}, err
} }
data := r.processRows(rows) data := r.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return []entity.UserSourceSubscriptionEntity{}, errors.New(ErrUserNotFound) return []domain.UserSourceSubscriptionEntity{}, errors.New(ErrUserNotFound)
} }
return data, nil return data, nil
} }
func (ur userSourceRepository) processRows(rows *sql.Rows) []entity.UserSourceSubscriptionEntity { func (ur userSourceRepository) processRows(rows *sql.Rows) []domain.UserSourceSubscriptionEntity {
items := []entity.UserSourceSubscriptionEntity{} items := []domain.UserSourceSubscriptionEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -104,13 +104,13 @@ func (ur userSourceRepository) processRows(rows *sql.Rows) []entity.UserSourceSu
fmt.Println(err) fmt.Println(err)
} }
item := entity.UserSourceSubscriptionEntity{ item := domain.UserSourceSubscriptionEntity{
ID: id, ID: id,
CreatedAt: createdAt, CreatedAt: createdAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,
DeletedAt: deletedAt, DeletedAt: deletedAt,
UserID: userId, UserID: userId,
SourceID: sourceId, SourceID: sourceId,
} }
items = append(items, item) items = append(items, item)

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/huandu/go-sqlbuilder" "github.com/huandu/go-sqlbuilder"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
@ -19,9 +19,9 @@ const (
) )
type Users interface { type Users interface {
GetByName(ctx context.Context, name string) (entity.UserEntity, error) GetByName(ctx context.Context, name string) (domain.UserEntity, error)
Create(ctx context.Context, name, password, scope string) (int64, error) Create(ctx context.Context, name, password, scope string) (int64, error)
Update(ctx context.Context, id int, entity entity.UserEntity) error Update(ctx context.Context, id int, entity domain.UserEntity) error
UpdatePassword(ctx context.Context, name, password string) error UpdatePassword(ctx context.Context, name, password string) error
CheckUserHash(ctx context.Context, name, password string) error CheckUserHash(ctx context.Context, name, password string) error
UpdateScopes(ctx context.Context, name, scope string) error UpdateScopes(ctx context.Context, name, scope string) error
@ -38,7 +38,7 @@ type userRepository struct {
connection *sql.DB connection *sql.DB
} }
func (ur userRepository) GetByName(ctx context.Context, name string) (entity.UserEntity, error) { func (ur userRepository) GetByName(ctx context.Context, name string) (domain.UserEntity, error) {
builder := sqlbuilder.NewSelectBuilder() builder := sqlbuilder.NewSelectBuilder()
builder.Select("*").From("users").Where( builder.Select("*").From("users").Where(
builder.E("Name", name), builder.E("Name", name),
@ -47,18 +47,18 @@ func (ur userRepository) GetByName(ctx context.Context, name string) (entity.Use
rows, err := ur.connection.QueryContext(ctx, query, args...) rows, err := ur.connection.QueryContext(ctx, query, args...)
if err != nil { if err != nil {
return entity.UserEntity{}, err return domain.UserEntity{}, err
} }
data := ur.processRows(rows) data := ur.processRows(rows)
if len(data) == 0 { if len(data) == 0 {
return entity.UserEntity{}, errors.New(ErrUserNotFound) return domain.UserEntity{}, errors.New(ErrUserNotFound)
} }
return data[0], nil return data[0], nil
} }
func (ur userRepository) Create(ctx context.Context, name, password, scope string) (int64, error) { func (ur userRepository) Create(ctx context.Context,name, password, scope string) (int64, error) {
passwordBytes := []byte(password) passwordBytes := []byte(password)
hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost) hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost)
if err != nil { if err != nil {
@ -80,7 +80,7 @@ func (ur userRepository) Create(ctx context.Context, name, password, scope strin
return 1, nil return 1, nil
} }
func (ur userRepository) Update(ctx context.Context, id int, entity entity.UserEntity) error { func (ur userRepository) Update(ctx context.Context, id int, entity domain.UserEntity) error {
return errors.New("not implemented") return errors.New("not implemented")
} }
@ -98,7 +98,7 @@ func (ur userRepository) UpdatePassword(ctx context.Context, name, password stri
// If the hash matches what we have in the database, an error will not be returned. // If the hash matches what we have in the database, an error will not be returned.
// If the user does not exist or the hash does not match, an error will be returned // If the user does not exist or the hash does not match, an error will be returned
func (ur userRepository) CheckUserHash(ctx context.Context, name, password string) error { func (ur userRepository) CheckUserHash(ctx context.Context,name, password string) error {
record, err := ur.GetByName(ctx, name) record, err := ur.GetByName(ctx, name)
if err != nil { if err != nil {
return err return err
@ -112,7 +112,7 @@ func (ur userRepository) CheckUserHash(ctx context.Context, name, password strin
return nil return nil
} }
func (ur userRepository) UpdateScopes(ctx context.Context, name, scope string) error { func (ur userRepository) UpdateScopes(ctx context.Context,name, scope string) error {
builder := sqlbuilder.NewUpdateBuilder() builder := sqlbuilder.NewUpdateBuilder()
builder.Update("users") builder.Update("users")
builder.Set( builder.Set(
@ -130,8 +130,8 @@ func (ur userRepository) UpdateScopes(ctx context.Context, name, scope string) e
return nil return nil
} }
func (ur userRepository) processRows(rows *sql.Rows) []entity.UserEntity { func (ur userRepository) processRows(rows *sql.Rows) []domain.UserEntity {
items := []entity.UserEntity{} items := []domain.UserEntity{}
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -146,7 +146,7 @@ func (ur userRepository) processRows(rows *sql.Rows) []entity.UserEntity {
fmt.Println(err) fmt.Println(err)
} }
item := entity.UserEntity{ item := domain.UserEntity{
ID: id, ID: id,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,
Username: username, Username: username,

View File

@ -5,7 +5,7 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -16,7 +16,7 @@ const (
type RefreshToken interface { type RefreshToken interface {
Create(ctx context.Context, username string) (string, error) Create(ctx context.Context, username string) (string, error)
GetByName(ctx context.Context, name string) (entity.RefreshTokenEntity, error) GetByName(ctx context.Context, name string) (domain.RefreshTokenEntity, error)
Delete(ctx context.Context, id int64) (int64, error) Delete(ctx context.Context, id int64) (int64, error)
IsRequestValid(ctx context.Context, username, refreshToken string) error IsRequestValid(ctx context.Context, username, refreshToken string) error
} }
@ -64,7 +64,7 @@ func (rt RefreshTokenService) Create(ctx context.Context, username string) (stri
} }
// Find the saved refresh token for a user and return it if it exists // Find the saved refresh token for a user and return it if it exists
func (rt RefreshTokenService) GetByName(ctx context.Context, name string) (entity.RefreshTokenEntity, error) { func (rt RefreshTokenService) GetByName(ctx context.Context, name string) (domain.RefreshTokenEntity, error) {
return rt.table.GetByUsername(ctx, name) return rt.table.GetByUsername(ctx, name)
} }

View File

@ -6,8 +6,7 @@ import (
"errors" "errors"
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
@ -22,10 +21,10 @@ const (
type UserServices interface { type UserServices interface {
DoesUserExist(ctx context.Context, username string) error DoesUserExist(ctx context.Context, username string) error
DoesPasswordMatchHash(ctx context.Context, username, password string) error DoesPasswordMatchHash(ctx context.Context, username, password string) error
GetUser(ctx context.Context, username string) (entity.UserEntity, error) GetUser(ctx context.Context, username string) (domain.UserEntity, error)
AddScopes(ctx context.Context, username string, scopes []string) error AddScopes(ctx context.Context, username string, scopes []string) error
RemoveScopes(ctx context.Context, username string, scopes []string) error RemoveScopes(ctx context.Context, username string, scopes []string) error
Create(ctx context.Context, name, password, scope string) (entity.UserEntity, error) Create(ctx context.Context, name, password, scope string) (domain.UserEntity, error)
CheckPasswordForRequirements(password string) error CheckPasswordForRequirements(password string) error
} }
@ -64,7 +63,7 @@ func (us UserService) DoesPasswordMatchHash(ctx context.Context, username, passw
return nil return nil
} }
func (us UserService) GetUser(ctx context.Context, username string) (entity.UserEntity, error) { func (us UserService) GetUser(ctx context.Context, username string) (domain.UserEntity, error) {
return us.repo.GetByName(ctx, username) return us.repo.GetByName(ctx, username)
} }
@ -125,14 +124,14 @@ func (us UserService) doesScopeExist(scopes []string, target string) bool {
return false return false
} }
func (us UserService) Create(ctx context.Context, name, password, scope string) (entity.UserEntity, error) { func (us UserService) Create(ctx context.Context, name, password, scope string) (domain.UserEntity, error) {
err := us.CheckPasswordForRequirements(password) err := us.CheckPasswordForRequirements(password)
if err != nil { if err != nil {
return entity.UserEntity{}, err return domain.UserEntity{}, err
} }
us.repo.Create(ctx, name, password, domain.ScopeArticleRead) us.repo.Create(ctx, name, password, domain.ScopeArticleRead)
return entity.UserEntity{}, nil return domain.UserEntity{}, nil
} }
func (us UserService) CheckPasswordForRequirements(password string) error { func (us UserService) CheckPasswordForRequirements(password string) error {

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
) )

View File

@ -1,11 +1,8 @@
package dtoconv package services
import ( import "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
)
func ArticlesToDto(items []entity.ArticleEntity) []domain.ArticleDto { func ArticlesToDto(items []domain.ArticleEntity) []domain.ArticleDto {
var dtos []domain.ArticleDto var dtos []domain.ArticleDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, ArticleToDto(item)) dtos = append(dtos, ArticleToDto(item))
@ -13,7 +10,7 @@ func ArticlesToDto(items []entity.ArticleEntity) []domain.ArticleDto {
return dtos return dtos
} }
func ArticleToDto(item entity.ArticleEntity) domain.ArticleDto { func ArticleToDto(item domain.ArticleEntity) domain.ArticleDto {
return domain.ArticleDto{ return domain.ArticleDto{
ID: item.ID, ID: item.ID,
SourceID: item.SourceID, SourceID: item.SourceID,
@ -29,7 +26,7 @@ func ArticleToDto(item entity.ArticleEntity) domain.ArticleDto {
} }
} }
func DiscordWebhooksToDto(items []entity.DiscordWebHookEntity) []domain.DiscordWebHookDto{ func DiscordWebhooksToDto(items []domain.DiscordWebHookEntity) []domain.DiscordWebHookDto{
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, DiscordWebhookToDto(item)) dtos = append(dtos, DiscordWebhookToDto(item))
@ -37,7 +34,7 @@ func DiscordWebhooksToDto(items []entity.DiscordWebHookEntity) []domain.DiscordW
return dtos return dtos
} }
func DiscordWebhookToDto(item entity.DiscordWebHookEntity) domain.DiscordWebHookDto { func DiscordWebhookToDto(item domain.DiscordWebHookEntity) domain.DiscordWebHookDto {
return domain.DiscordWebHookDto{ return domain.DiscordWebHookDto{
ID: item.ID, ID: item.ID,
Server: item.Server, Server: item.Server,
@ -47,7 +44,7 @@ func DiscordWebhookToDto(item entity.DiscordWebHookEntity) domain.DiscordWebHook
} }
} }
func SourcesToDto(items []entity.SourceEntity) []domain.SourceDto { func SourcesToDto(items []domain.SourceEntity) []domain.SourceDto {
var dtos []domain.SourceDto var dtos []domain.SourceDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, SourceToDto(item)) dtos = append(dtos, SourceToDto(item))
@ -55,7 +52,7 @@ func SourcesToDto(items []entity.SourceEntity) []domain.SourceDto {
return dtos return dtos
} }
func SourceToDto(item entity.SourceEntity) domain.SourceDto { func SourceToDto(item domain.SourceEntity) domain.SourceDto {
return domain.SourceDto{ return domain.SourceDto{
ID: item.ID, ID: item.ID,
Source: item.Source, Source: item.Source,

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/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"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 entity.SourceEntity record domain.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 entity.SourceEntity) FFXIVClient { func NewFFXIVClient(Record domain.SourceEntity) FFXIVClient {
return FFXIVClient{ return FFXIVClient{
record: Record, record: Record,
cacheGroup: "ffxiv", cacheGroup: "ffxiv",
} }
} }
func (fc *FFXIVClient) CheckSource() ([]entity.ArticleEntity, error) { func (fc *FFXIVClient) CheckSource() ([]domain.ArticleEntity, error) {
var articles []entity.ArticleEntity var articles []domain.ArticleEntity
parser := fc.GetBrowser() parser := fc.GetBrowser()
defer parser.Close() defer parser.Close()
@ -96,7 +96,7 @@ func (fc *FFXIVClient) CheckSource() ([]entity.ArticleEntity, error) {
return articles, err return articles, err
} }
article := entity.ArticleEntity{ article := domain.ArticleEntity{
SourceID: fc.record.ID, SourceID: fc.record.ID,
Tags: tags, Tags: tags,
Title: title, Title: title,

View File

@ -3,12 +3,11 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/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 entity.SourceEntity = entity.SourceEntity{ var FFXIVRecord domain.SourceEntity = domain.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "Final Fantasy XIV - NA", DisplayName: "Final Fantasy XIV - NA",
Source: domain.SourceCollectorFfxiv, Source: domain.SourceCollectorFfxiv,

View File

@ -9,7 +9,6 @@ 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"
@ -17,7 +16,7 @@ import (
type RedditClient struct { type RedditClient struct {
config RedditConfig config RedditConfig
record entity.SourceEntity record domain.SourceEntity
} }
type RedditConfig struct { type RedditConfig struct {
@ -26,7 +25,7 @@ type RedditConfig struct {
PullNSFW string PullNSFW string
} }
func NewRedditClient(Record entity.SourceEntity) *RedditClient { func NewRedditClient(Record domain.SourceEntity) *RedditClient {
rc := RedditClient{ rc := RedditClient{
record: Record, record: Record,
} }
@ -87,10 +86,10 @@ func (rc *RedditClient) GetContent() (domain.RedditJsonContent, error) {
return items, nil return items, nil
} }
func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []entity.ArticleEntity { func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []domain.ArticleEntity {
var redditArticles []entity.ArticleEntity var redditArticles []domain.ArticleEntity
for _, item := range items.Data.Children { for _, item := range items.Data.Children {
var article entity.ArticleEntity var article domain.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)
@ -103,8 +102,8 @@ func (rc *RedditClient) ConvertToArticles(items domain.RedditJsonContent) []enti
// 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) (entity.ArticleEntity, error) { func (rc *RedditClient) convertToArticle(source domain.RedditPost) (domain.ArticleEntity, error) {
var item entity.ArticleEntity var item domain.ArticleEntity
if source.Content == "" && source.Url != "" { if source.Content == "" && source.Url != "" {
item = rc.convertPicturePost(source) item = rc.convertPicturePost(source)
@ -130,8 +129,8 @@ func (rc *RedditClient) convertToArticle(source domain.RedditPost) (entity.Artic
return item, nil return item, nil
} }
func (rc *RedditClient) convertPicturePost(source domain.RedditPost) entity.ArticleEntity { func (rc *RedditClient) convertPicturePost(source domain.RedditPost) domain.ArticleEntity {
var item = entity.ArticleEntity{ var item = domain.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),
@ -146,8 +145,8 @@ func (rc *RedditClient) convertPicturePost(source domain.RedditPost) entity.Arti
return item return item
} }
func (rc *RedditClient) convertTextPost(source domain.RedditPost) entity.ArticleEntity { func (rc *RedditClient) convertTextPost(source domain.RedditPost) domain.ArticleEntity {
var item = entity.ArticleEntity{ var item = domain.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,
@ -159,8 +158,8 @@ func (rc *RedditClient) convertTextPost(source domain.RedditPost) entity.Article
return item return item
} }
func (rc *RedditClient) convertVideoPost(source domain.RedditPost) entity.ArticleEntity { func (rc *RedditClient) convertVideoPost(source domain.RedditPost) domain.ArticleEntity {
var item = entity.ArticleEntity{ var item = domain.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,
@ -173,8 +172,8 @@ func (rc *RedditClient) convertVideoPost(source domain.RedditPost) entity.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) entity.ArticleEntity { func (rc *RedditClient) convertRedirectPost(source domain.RedditPost) domain.ArticleEntity {
var item = entity.ArticleEntity{ var item = domain.ArticleEntity{
SourceID: rc.record.ID, SourceID: rc.record.ID,
Tags: "a", Tags: "a",
Title: source.Title, Title: source.Title,

View File

@ -3,12 +3,11 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/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/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var RedditRecord entity.SourceEntity = entity.SourceEntity{ var RedditRecord domain.SourceEntity = domain.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/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
) )
type FeedInput interface { type FeedInput interface {
GetArticles() (entity.ArticleEntity, error) GetArticles() (domain.ArticleEntity, error)
} }
type rssClient struct { type rssClient struct {
SourceRecord entity.SourceEntity SourceRecord domain.SourceEntity
} }
func NewRssClient(sourceRecord entity.SourceEntity) rssClient { func NewRssClient(sourceRecord domain.SourceEntity) rssClient {
client := rssClient{ client := rssClient{
SourceRecord: sourceRecord, SourceRecord: sourceRecord,
} }
@ -23,7 +23,7 @@ func NewRssClient(sourceRecord entity.SourceEntity) rssClient {
return client return client
} }
func (rc rssClient) GetArticles() ([]entity.ArticleEntity, error) { func (rc rssClient) GetArticles() ([]domain.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() ([]entity.ArticleEntity, error) {
} }
sourceTags := strings.Split(rc.SourceRecord.Tags, ",") sourceTags := strings.Split(rc.SourceRecord.Tags, ",")
var articles []entity.ArticleEntity var articles []domain.ArticleEntity
for _, post := range feed.Items { for _, post := range feed.Items {
article := entity.ArticleEntity{ article := domain.ArticleEntity{
SourceID: rc.SourceRecord.ID, SourceID: rc.SourceRecord.ID,
Title: post.Title, Title: post.Title,
Description: post.Content, Description: post.Content,

View File

@ -3,12 +3,11 @@ package input_test
import ( import (
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/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/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var rssRecord = entity.SourceEntity{ var rssRecord = domain.SourceEntity{
ID: 1, ID: 1,
DisplayName: "ArsTechnica", DisplayName: "ArsTechnica",
Url: "https://feeds.arstechnica.com/arstechnica/index", Url: "https://feeds.arstechnica.com/arstechnica/index",
@ -28,7 +27,7 @@ func TestRssGetFeed(t *testing.T) {
} }
func TestRssAgainstGita(t *testing.T) { func TestRssAgainstGita(t *testing.T) {
client := input.NewRssClient(entity.SourceEntity{ client := input.NewRssClient(domain.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/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"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 entity.SourceEntity SourceRecord domain.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 entity.SourceEntity) { func (tc *TwitchClient) ReplaceSourceRecord(source domain.SourceEntity) {
tc.SourceRecord = source tc.SourceRecord = source
} }
@ -86,8 +86,8 @@ func (tc *TwitchClient) Login() error {
return nil return nil
} }
func (tc *TwitchClient) GetContent() ([]entity.ArticleEntity, error) { func (tc *TwitchClient) GetContent() ([]domain.ArticleEntity, error) {
var items []entity.ArticleEntity var items []domain.ArticleEntity
user, err := tc.GetUserDetails() user, err := tc.GetUserDetails()
if err != nil { if err != nil {
@ -100,7 +100,7 @@ func (tc *TwitchClient) GetContent() ([]entity.ArticleEntity, error) {
} }
for _, video := range posts { for _, video := range posts {
var article entity.ArticleEntity var article domain.ArticleEntity
AuthorName, err := tc.ExtractAuthor(video) AuthorName, err := tc.ExtractAuthor(video)
if err != nil { if err != nil {

View File

@ -4,18 +4,17 @@ import (
"log" "log"
"testing" "testing"
"git.jamestombleson.com/jtom38/newsbot-api/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/input" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
) )
var TwitchSourceRecord = entity.SourceEntity{ var TwitchSourceRecord = domain.SourceEntity{
ID: 9999, ID: 9999,
DisplayName: "nintendo", DisplayName: "nintendo",
Source: domain.SourceCollectorTwitch, Source: domain.SourceCollectorTwitch,
} }
var TwitchInvalidRecord = entity.SourceEntity{ var TwitchInvalidRecord = domain.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/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
) )
type YoutubeClient struct { type YoutubeClient struct {
record entity.SourceEntity record domain.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,16 +36,17 @@ 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 entity.SourceEntity) YoutubeClient { func NewYoutubeClient(Record domain.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() ([]entity.ArticleEntity, error) { func (yc *YoutubeClient) GetContent() ([]domain.ArticleEntity, error) {
var items []entity.ArticleEntity var items []domain.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
@ -245,7 +246,7 @@ func (yc *YoutubeClient) CheckUriCache(uri *string) bool {
return false return false
} }
func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) entity.ArticleEntity { func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) domain.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)
@ -263,7 +264,7 @@ func (yc *YoutubeClient) ConvertToArticle(item *gofeed.Item) entity.ArticleEntit
log.Printf("[YouTube] %v", msg) log.Printf("[YouTube] %v", msg)
} }
var article = entity.ArticleEntity{ var article = domain.ArticleEntity{
SourceID: yc.record.ID, SourceID: yc.record.ID,
Tags: tags, Tags: tags,
Title: item.Title, Title: item.Title,

View File

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