features/move-domain-for-portal #8
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
@ -16,7 +16,7 @@ type AlertDiscordRepo interface {
|
||||
SoftDelete(ctx context.Context, id int64) (int64, error)
|
||||
Restore(ctx context.Context, id int64) (int64, error)
|
||||
Delete(ctx context.Context, id int64) (int64, error)
|
||||
ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.AlertDiscordEntity, error)
|
||||
ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.AlertDiscordEntity, error)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.AlertDiscordEntity, error) {
|
||||
func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.AlertDiscordEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("AlertDiscord")
|
||||
@ -74,19 +74,19 @@ func (r alertDiscordRepository) ListByUser(ctx context.Context, page, limit int,
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.AlertDiscordEntity{}, err
|
||||
return []entity.AlertDiscordEntity{}, err
|
||||
}
|
||||
|
||||
data := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.AlertDiscordEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.AlertDiscordEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (ur alertDiscordRepository) processRows(rows *sql.Rows) []domain.AlertDiscordEntity {
|
||||
items := []domain.AlertDiscordEntity{}
|
||||
func (ur alertDiscordRepository) processRows(rows *sql.Rows) []entity.AlertDiscordEntity {
|
||||
items := []entity.AlertDiscordEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -105,7 +105,7 @@ func (ur alertDiscordRepository) processRows(rows *sql.Rows) []domain.AlertDisco
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
item := domain.AlertDiscordEntity{
|
||||
item := entity.AlertDiscordEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
|
||||
)
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
@ -17,14 +17,14 @@ const (
|
||||
)
|
||||
|
||||
type ArticlesRepo interface {
|
||||
GetById(ctx context.Context, id int64) (domain.ArticleEntity, error)
|
||||
GetByUrl(ctx context.Context, url string) (domain.ArticleEntity, error)
|
||||
ListTop(ctx context.Context, limit int) ([]domain.ArticleEntity, error)
|
||||
ListByPage(ctx context.Context, page, limit int) ([]domain.ArticleEntity, error)
|
||||
ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]domain.ArticleEntity, error)
|
||||
ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]domain.ArticleEntity, error)
|
||||
GetById(ctx context.Context, id int64) (entity.ArticleEntity, error)
|
||||
GetByUrl(ctx context.Context, url string) (entity.ArticleEntity, error)
|
||||
ListTop(ctx context.Context, limit int) ([]entity.ArticleEntity, error)
|
||||
ListByPage(ctx context.Context, page, limit int) ([]entity.ArticleEntity, error)
|
||||
ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]entity.ArticleEntity, error)
|
||||
ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]entity.ArticleEntity, 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 domain.ArticleEntity) (int64, error)
|
||||
CreateFromEntity(ctx context.Context, entity entity.ArticleEntity) (int64, error)
|
||||
}
|
||||
|
||||
type ArticleRepository struct {
|
||||
@ -41,7 +41,7 @@ func NewArticleRepository(conn *sql.DB) ArticleRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) GetById(ctx context.Context, id int64) (domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) GetById(ctx context.Context, id int64) (entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles").Where(
|
||||
@ -52,18 +52,18 @@ func (ar ArticleRepository) GetById(ctx context.Context, id int64) (domain.Artic
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.ArticleEntity{}, err
|
||||
return entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles").Where(
|
||||
@ -74,18 +74,18 @@ func (ar ArticleRepository) GetByUrl(ctx context.Context, url string) (domain.Ar
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.ArticleEntity{}, err
|
||||
return entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles")
|
||||
@ -94,18 +94,18 @@ func (ar ArticleRepository) ListTop(ctx context.Context, limit int) ([]domain.Ar
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.ArticleEntity{}, err
|
||||
return []entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles")
|
||||
@ -116,18 +116,18 @@ func (ar ArticleRepository) ListByPage(ctx context.Context, page, limit int) ([]
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.ArticleEntity{}, err
|
||||
return []entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit int, orderBy string) ([]entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles")
|
||||
@ -140,17 +140,17 @@ func (ar ArticleRepository) ListByPublishDate(ctx context.Context, page, limit i
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.ArticleEntity{}, err
|
||||
return []entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]domain.ArticleEntity, error) {
|
||||
func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourceId int, orderBy string) ([]entity.ArticleEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("articles")
|
||||
@ -167,12 +167,12 @@ func (ar ArticleRepository) ListBySource(ctx context.Context, page, limit, sourc
|
||||
query, args := builder.Build()
|
||||
rows, err := ar.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.ArticleEntity{}, err
|
||||
return []entity.ArticleEntity{}, err
|
||||
}
|
||||
|
||||
data := ar.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.ArticleEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
@ -193,12 +193,12 @@ func (ar ArticleRepository) Create(ctx context.Context, sourceId int64, tags, ti
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity domain.ArticleEntity) (int64, error) {
|
||||
func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity entity.ArticleEntity) (int64, error) {
|
||||
dt := time.Now()
|
||||
queryBuilder := sqlbuilder.NewInsertBuilder()
|
||||
queryBuilder.InsertInto("articles")
|
||||
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()
|
||||
|
||||
_, err := ar.conn.ExecContext(ctx, query, args...)
|
||||
@ -209,8 +209,8 @@ func (ar ArticleRepository) CreateFromEntity(ctx context.Context, entity domain.
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (ur ArticleRepository) processRows(rows *sql.Rows) []domain.ArticleEntity {
|
||||
items := []domain.ArticleEntity{}
|
||||
func (ur ArticleRepository) processRows(rows *sql.Rows) []entity.ArticleEntity {
|
||||
items := []entity.ArticleEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -237,7 +237,7 @@ func (ur ArticleRepository) processRows(rows *sql.Rows) []domain.ArticleEntity {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
item := domain.ArticleEntity{
|
||||
item := entity.ArticleEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
@ -16,10 +16,10 @@ type DiscordWebHookRepo interface {
|
||||
SoftDelete(ctx context.Context, id int64) (int64, error)
|
||||
Restore(ctx context.Context, id int64) (int64, error)
|
||||
Delete(ctx context.Context, id int64) (int64, error)
|
||||
GetById(ctx context.Context, id int64) (domain.DiscordWebHookEntity, error)
|
||||
GetByUrl(ctx context.Context, url string) (domain.DiscordWebHookEntity, error)
|
||||
ListByServerName(ctx context.Context, name string) ([]domain.DiscordWebHookEntity, error)
|
||||
ListByServerAndChannel(ctx context.Context, server, channel string) ([]domain.DiscordWebHookEntity, error)
|
||||
GetById(ctx context.Context, id int64) (entity.DiscordWebHookEntity, error)
|
||||
GetByUrl(ctx context.Context, url string) (entity.DiscordWebHookEntity, error)
|
||||
ListByServerName(ctx context.Context, name string) ([]entity.DiscordWebHookEntity, error)
|
||||
ListByServerAndChannel(ctx context.Context, server, channel string) ([]entity.DiscordWebHookEntity, error)
|
||||
}
|
||||
|
||||
type discordWebHookRepository struct {
|
||||
@ -100,7 +100,7 @@ func (r discordWebHookRepository) Delete(ctx context.Context, id int64) (int64,
|
||||
return deleteFromTable(ctx, r.conn, "DiscordWebHooks", id)
|
||||
}
|
||||
|
||||
func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (domain.DiscordWebHookEntity, error) {
|
||||
func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (entity.DiscordWebHookEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("DiscordWebHooks").Where(
|
||||
@ -111,18 +111,18 @@ func (r discordWebHookRepository) GetById(ctx context.Context, id int64) (domain
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.DiscordWebHookEntity{}, err
|
||||
return entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.DiscordWebHookEntity{}, err
|
||||
return entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (domain.DiscordWebHookEntity, error) {
|
||||
func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (entity.DiscordWebHookEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("DiscordWebHooks").Where(
|
||||
@ -133,18 +133,18 @@ func (r discordWebHookRepository) GetByUrl(ctx context.Context, url string) (dom
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.DiscordWebHookEntity{}, err
|
||||
return entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.DiscordWebHookEntity{}, err
|
||||
return entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r discordWebHookRepository) ListByServerName(ctx context.Context, name string) ([]domain.DiscordWebHookEntity, error) {
|
||||
func (r discordWebHookRepository) ListByServerName(ctx context.Context, name string) ([]entity.DiscordWebHookEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("DiscordWebHooks").Where(
|
||||
@ -154,18 +154,18 @@ func (r discordWebHookRepository) ListByServerName(ctx context.Context, name str
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.DiscordWebHookEntity{}, err
|
||||
return []entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.DiscordWebHookEntity{}, err
|
||||
return []entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, server, channel string) ([]domain.DiscordWebHookEntity, error) {
|
||||
func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, server, channel string) ([]entity.DiscordWebHookEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("DiscordWebHooks").Where(
|
||||
@ -176,19 +176,19 @@ func (r discordWebHookRepository) ListByServerAndChannel(ctx context.Context, se
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.DiscordWebHookEntity{}, err
|
||||
return []entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.DiscordWebHookEntity{}, err
|
||||
return []entity.DiscordWebHookEntity{}, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]domain.DiscordWebHookEntity, error) {
|
||||
items := []domain.DiscordWebHookEntity{}
|
||||
func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]entity.DiscordWebHookEntity, error) {
|
||||
items := []entity.DiscordWebHookEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -209,7 +209,7 @@ func (r discordWebHookRepository) processRows(rows *sql.Rows) ([]domain.DiscordW
|
||||
return items, err
|
||||
}
|
||||
|
||||
item := domain.DiscordWebHookEntity{
|
||||
item := entity.DiscordWebHookEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
@ -17,7 +17,7 @@ const (
|
||||
|
||||
type RefreshToken interface {
|
||||
Create(ctx context.Context, username string, token string) (int64, error)
|
||||
GetByUsername(ctx context.Context, name string) (domain.RefreshTokenEntity, error)
|
||||
GetByUsername(ctx context.Context, name string) (entity.RefreshTokenEntity, 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
|
||||
}
|
||||
|
||||
func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string) (domain.RefreshTokenEntity, error) {
|
||||
func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string) (entity.RefreshTokenEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*").From(refreshTokenTableName).Where(
|
||||
builder.E("Username", name),
|
||||
@ -56,12 +56,12 @@ func (rt RefreshTokenRepository) GetByUsername(ctx context.Context, name string)
|
||||
query, args := builder.Build()
|
||||
rows, err := rt.connection.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.RefreshTokenEntity{}, err
|
||||
return entity.RefreshTokenEntity{}, err
|
||||
}
|
||||
|
||||
data := rt.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.RefreshTokenEntity{}, errors.New("no token found for user")
|
||||
return entity.RefreshTokenEntity{}, errors.New("no token found for user")
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
@ -83,8 +83,8 @@ func (rt RefreshTokenRepository) DeleteById(ctx context.Context, id int64) (int6
|
||||
return rows.RowsAffected()
|
||||
}
|
||||
|
||||
func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []domain.RefreshTokenEntity {
|
||||
items := []domain.RefreshTokenEntity{}
|
||||
func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []entity.RefreshTokenEntity {
|
||||
items := []entity.RefreshTokenEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -99,15 +99,15 @@ func (rd RefreshTokenRepository) processRows(rows *sql.Rows) []domain.RefreshTok
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
item := domain.RefreshTokenEntity{
|
||||
item := entity.RefreshTokenEntity{
|
||||
ID: id,
|
||||
Username: username,
|
||||
Token: token,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
|
||||
if (deletedAt.Valid) {
|
||||
|
||||
if deletedAt.Valid {
|
||||
item.DeletedAt = deletedAt.Time
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,18 @@ import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
type Sources interface {
|
||||
Create(ctx context.Context, source, displayName, url, tags string, enabled bool) (int64, error)
|
||||
GetById(ctx context.Context, id int64) (domain.SourceEntity, error)
|
||||
GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error)
|
||||
GetBySource(ctx context.Context, source string) (domain.SourceEntity, error)
|
||||
GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error)
|
||||
List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error)
|
||||
ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error)
|
||||
GetById(ctx context.Context, id int64) (entity.SourceEntity, error)
|
||||
GetByDisplayName(ctx context.Context, displayName string) (entity.SourceEntity, error)
|
||||
GetBySource(ctx context.Context, source string) (entity.SourceEntity, error)
|
||||
GetBySourceAndName(ctx context.Context, source, name string) (entity.SourceEntity, error)
|
||||
List(ctx context.Context, page, limit int) ([]entity.SourceEntity, error)
|
||||
ListBySource(ctx context.Context, page, limit int, source string) ([]entity.SourceEntity, error)
|
||||
Enable(ctx context.Context, id int64) (int64, error)
|
||||
Disable(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
|
||||
}
|
||||
|
||||
func (r sourceRepository) GetById(ctx context.Context, id int64) (domain.SourceEntity, error) {
|
||||
func (r sourceRepository) GetById(ctx context.Context, id int64) (entity.SourceEntity, error) {
|
||||
b := sqlbuilder.NewSelectBuilder()
|
||||
b.Select("*")
|
||||
b.From("Sources").Where(
|
||||
@ -61,18 +61,18 @@ func (r sourceRepository) GetById(ctx context.Context, id int64) (domain.SourceE
|
||||
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r sourceRepository) GetByDisplayName(ctx context.Context, displayName string) (domain.SourceEntity, error) {
|
||||
func (r sourceRepository) GetByDisplayName(ctx context.Context, displayName string) (entity.SourceEntity, error) {
|
||||
b := sqlbuilder.NewSelectBuilder()
|
||||
b.Select("*")
|
||||
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...)
|
||||
if err != nil {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r sourceRepository) GetBySource(ctx context.Context, source string) (domain.SourceEntity, error) {
|
||||
func (r sourceRepository) GetBySource(ctx context.Context, source string) (entity.SourceEntity, error) {
|
||||
b := sqlbuilder.NewSelectBuilder()
|
||||
b.Select("*")
|
||||
b.From("Sources").Where(
|
||||
@ -105,18 +105,18 @@ func (r sourceRepository) GetBySource(ctx context.Context, source string) (domai
|
||||
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name string) (domain.SourceEntity, error) {
|
||||
func (r sourceRepository) GetBySourceAndName(ctx context.Context, source, name string) (entity.SourceEntity, error) {
|
||||
b := sqlbuilder.NewSelectBuilder()
|
||||
b.Select("*")
|
||||
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...)
|
||||
if err != nil {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.SourceEntity{}, err
|
||||
return entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (r sourceRepository) List(ctx context.Context, page, limit int) ([]domain.SourceEntity, error) {
|
||||
func (r sourceRepository) List(ctx context.Context, page, limit int) ([]entity.SourceEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("Sources")
|
||||
@ -149,18 +149,18 @@ func (r sourceRepository) List(ctx context.Context, page, limit int) ([]domain.S
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.SourceEntity{}, err
|
||||
return []entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.SourceEntity{}, err
|
||||
return []entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, source string) ([]domain.SourceEntity, error) {
|
||||
func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, source string) ([]entity.SourceEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("Sources")
|
||||
@ -173,12 +173,12 @@ func (r sourceRepository) ListBySource(ctx context.Context, page, limit int, sou
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.SourceEntity{}, err
|
||||
return []entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
data, err := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.SourceEntity{}, err
|
||||
return []entity.SourceEntity{}, err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (r sourceRepository) processRows(rows *sql.Rows) ([]domain.SourceEntity, error) {
|
||||
items := []domain.SourceEntity{}
|
||||
func (r sourceRepository) processRows(rows *sql.Rows) ([]entity.SourceEntity, error) {
|
||||
items := []entity.SourceEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -258,7 +258,7 @@ func (r sourceRepository) processRows(rows *sql.Rows) ([]domain.SourceEntity, er
|
||||
return items, err
|
||||
}
|
||||
|
||||
item := domain.SourceEntity{
|
||||
item := entity.SourceEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
|
||||
)
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
)
|
||||
|
||||
@ -16,7 +16,7 @@ type UserSourceRepo interface {
|
||||
SoftDelete(ctx context.Context, id int64) (int64, error)
|
||||
Restore(ctx context.Context, id int64) (int64, error)
|
||||
Delete(ctx context.Context, id int64) (int64, error)
|
||||
ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.UserSourceSubscriptionEntity, error)
|
||||
ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.UserSourceSubscriptionEntity, error)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]domain.UserSourceSubscriptionEntity, error) {
|
||||
func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, userId int64) ([]entity.UserSourceSubscriptionEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*")
|
||||
builder.From("UserSourceSubscriptions")
|
||||
@ -74,19 +74,19 @@ func (r userSourceRepository) ListByUser(ctx context.Context, page, limit int, u
|
||||
query, args := builder.Build()
|
||||
rows, err := r.conn.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return []domain.UserSourceSubscriptionEntity{}, err
|
||||
return []entity.UserSourceSubscriptionEntity{}, err
|
||||
}
|
||||
|
||||
data := r.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return []domain.UserSourceSubscriptionEntity{}, errors.New(ErrUserNotFound)
|
||||
return []entity.UserSourceSubscriptionEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (ur userSourceRepository) processRows(rows *sql.Rows) []domain.UserSourceSubscriptionEntity {
|
||||
items := []domain.UserSourceSubscriptionEntity{}
|
||||
func (ur userSourceRepository) processRows(rows *sql.Rows) []entity.UserSourceSubscriptionEntity {
|
||||
items := []entity.UserSourceSubscriptionEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -104,13 +104,13 @@ func (ur userSourceRepository) processRows(rows *sql.Rows) []domain.UserSourceSu
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
item := domain.UserSourceSubscriptionEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
DeletedAt: deletedAt,
|
||||
UserID: userId,
|
||||
SourceID: sourceId,
|
||||
item := entity.UserSourceSubscriptionEntity{
|
||||
ID: id,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
DeletedAt: deletedAt,
|
||||
UserID: userId,
|
||||
SourceID: sourceId,
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
||||
|
||||
"github.com/huandu/go-sqlbuilder"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@ -19,9 +19,9 @@ const (
|
||||
)
|
||||
|
||||
type Users interface {
|
||||
GetByName(ctx context.Context, name string) (domain.UserEntity, error)
|
||||
GetByName(ctx context.Context, name string) (entity.UserEntity, error)
|
||||
Create(ctx context.Context, name, password, scope string) (int64, error)
|
||||
Update(ctx context.Context, id int, entity domain.UserEntity) error
|
||||
Update(ctx context.Context, id int, entity entity.UserEntity) error
|
||||
UpdatePassword(ctx context.Context, name, password string) error
|
||||
CheckUserHash(ctx context.Context, name, password string) error
|
||||
UpdateScopes(ctx context.Context, name, scope string) error
|
||||
@ -38,7 +38,7 @@ type userRepository struct {
|
||||
connection *sql.DB
|
||||
}
|
||||
|
||||
func (ur userRepository) GetByName(ctx context.Context, name string) (domain.UserEntity, error) {
|
||||
func (ur userRepository) GetByName(ctx context.Context, name string) (entity.UserEntity, error) {
|
||||
builder := sqlbuilder.NewSelectBuilder()
|
||||
builder.Select("*").From("users").Where(
|
||||
builder.E("Name", name),
|
||||
@ -47,18 +47,18 @@ func (ur userRepository) GetByName(ctx context.Context, name string) (domain.Use
|
||||
|
||||
rows, err := ur.connection.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return domain.UserEntity{}, err
|
||||
return entity.UserEntity{}, err
|
||||
}
|
||||
|
||||
data := ur.processRows(rows)
|
||||
if len(data) == 0 {
|
||||
return domain.UserEntity{}, errors.New(ErrUserNotFound)
|
||||
return entity.UserEntity{}, errors.New(ErrUserNotFound)
|
||||
}
|
||||
|
||||
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)
|
||||
hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
@ -80,7 +80,7 @@ func (ur userRepository) Create(ctx context.Context,name, password, scope string
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (ur userRepository) Update(ctx context.Context, id int, entity domain.UserEntity) error {
|
||||
func (ur userRepository) Update(ctx context.Context, id int, entity entity.UserEntity) error {
|
||||
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 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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -112,7 +112,7 @@ func (ur userRepository) CheckUserHash(ctx context.Context,name, password string
|
||||
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.Update("users")
|
||||
builder.Set(
|
||||
@ -130,8 +130,8 @@ func (ur userRepository) UpdateScopes(ctx context.Context,name, scope string) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ur userRepository) processRows(rows *sql.Rows) []domain.UserEntity {
|
||||
items := []domain.UserEntity{}
|
||||
func (ur userRepository) processRows(rows *sql.Rows) []entity.UserEntity {
|
||||
items := []entity.UserEntity{}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
@ -146,7 +146,7 @@ func (ur userRepository) processRows(rows *sql.Rows) []domain.UserEntity {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
item := domain.UserEntity{
|
||||
item := entity.UserEntity{
|
||||
ID: id,
|
||||
UpdatedAt: updatedAt,
|
||||
Username: username,
|
||||
|
Loading…
Reference in New Issue
Block a user