diff --git a/internal/domain/entity/news.go b/internal/domain/entity/news.go index e6da336..3bc94a4 100644 --- a/internal/domain/entity/news.go +++ b/internal/domain/entity/news.go @@ -1,7 +1,13 @@ package entity +import "time" + type News struct { - ID int64 `gorm:"primaryKey" json:"id"` - FixtureID int64 `json:"fixture_id"` - Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"` + ID int64 `gorm:"primaryKey" json:"id"` + FixtureID int64 `json:"fixture_id"` + Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"` + Title string `gorm:"size:300;not null" json:"title"` + Slug string `gorm:"size:300;not null" json:"slug"` + Description string `gorm:"type:text" json:"description"` + CreatedAt time.Time `json:"created_at"` } diff --git a/internal/domain/repository/fixture_repository.go b/internal/domain/repository/fixture_repository.go index b71cf49..ede7659 100644 --- a/internal/domain/repository/fixture_repository.go +++ b/internal/domain/repository/fixture_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type FixtureRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewFixtureRepository(db *gorm.DB) *FixtureRepository { } type IFixtureRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Fixture, error) + Save(*entity.Fixture) (*entity.Fixture, error) + Update(*entity.Fixture) (*entity.Fixture, error) + Delete(*entity.Fixture) error +} + +func (r *FixtureRepository) Count(homeId, awayId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Fixture{}).Where("home_id = ?", homeId).Where("away_id = ?", awayId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *FixtureRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var fixtures []*entity.Fixture + err := r.db.Scopes(Paginate(fixtures, pagination, r.db)).Preload("Home").Preload("Away").Find(&fixtures).Error + if err != nil { + return nil, err + } + pagination.Rows = fixtures + return pagination, nil +} + +func (r *FixtureRepository) Get(homeId, awayId int) (*entity.Fixture, error) { + var c entity.Fixture + err := r.db.Where("home_id = ?", homeId).Where("away_id = ?", awayId).Preload("Home").Preload("Away").Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *FixtureRepository) Save(c *entity.Fixture) (*entity.Fixture, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *FixtureRepository) Update(c *entity.Fixture) (*entity.Fixture, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *FixtureRepository) Delete(c *entity.Fixture) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/home_repository.go b/internal/domain/repository/home_repository.go index 238916a..7460a7d 100644 --- a/internal/domain/repository/home_repository.go +++ b/internal/domain/repository/home_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type HomeRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewHomeRepository(db *gorm.DB) *HomeRepository { } type IHomeRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Home, error) + Save(*entity.Home) (*entity.Home, error) + Update(*entity.Home) (*entity.Home, error) + Delete(*entity.Home) error +} + +func (r *HomeRepository) Count(fixtureId, teamId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Home{}).Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *HomeRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var homes []*entity.Home + err := r.db.Scopes(Paginate(homes, pagination, r.db)).Preload("Fixture").Preload("Team").Find(&homes).Error + if err != nil { + return nil, err + } + pagination.Rows = homes + return pagination, nil +} + +func (r *HomeRepository) Get(fixtureId, teamId int) (*entity.Home, error) { + var c entity.Home + err := r.db.Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Preload("Fixture").Preload("Team").Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *HomeRepository) Save(c *entity.Home) (*entity.Home, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *HomeRepository) Update(c *entity.Home) (*entity.Home, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *HomeRepository) Delete(c *entity.Home) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/league_repository.go b/internal/domain/repository/league_repository.go index f166bf7..d7d6410 100644 --- a/internal/domain/repository/league_repository.go +++ b/internal/domain/repository/league_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type LeagueRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewLeagueRepository(db *gorm.DB) *LeagueRepository { } type ILeagueRepository interface { + Count(string) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(string) (*entity.League, error) + Save(*entity.League) (*entity.League, error) + Update(*entity.League) (*entity.League, error) + Delete(*entity.League) error +} + +func (r *LeagueRepository) Count(slug string) (int64, error) { + var count int64 + err := r.db.Model(&entity.League{}).Where("slug = ?", slug).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *LeagueRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var leagues []*entity.League + err := r.db.Scopes(Paginate(leagues, pagination, r.db)).Find(&leagues).Error + if err != nil { + return nil, err + } + pagination.Rows = leagues + return pagination, nil +} + +func (r *LeagueRepository) Get(slug string) (*entity.League, error) { + var c entity.League + err := r.db.Where("slug = ?", slug).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *LeagueRepository) Save(c *entity.League) (*entity.League, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *LeagueRepository) Update(c *entity.League) (*entity.League, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *LeagueRepository) Delete(c *entity.League) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/livescore_repository.go b/internal/domain/repository/livescore_repository.go index a8400b3..357c6d7 100644 --- a/internal/domain/repository/livescore_repository.go +++ b/internal/domain/repository/livescore_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type LiveScoreRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewLivescoreRepository(db *gorm.DB) *LiveScoreRepository { } type ILiveScoreRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Livescore, error) + Save(*entity.Livescore) (*entity.Livescore, error) + Update(*entity.Livescore) (*entity.Livescore, error) + Delete(*entity.Livescore) error +} + +func (r *LiveScoreRepository) Count(fixtureId, teamId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Livescore{}).Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *LiveScoreRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var livescores []*entity.Livescore + err := r.db.Scopes(Paginate(livescores, pagination, r.db)).Find(&livescores).Error + if err != nil { + return nil, err + } + pagination.Rows = livescores + return pagination, nil +} + +func (r *LiveScoreRepository) Get(fixtureId, teamId int) (*entity.Livescore, error) { + var c entity.Livescore + err := r.db.Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *LiveScoreRepository) Save(c *entity.Livescore) (*entity.Livescore, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *LiveScoreRepository) Update(c *entity.Livescore) (*entity.Livescore, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *LiveScoreRepository) Delete(c *entity.Livescore) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/news_repository.go b/internal/domain/repository/news_repository.go index 213100d..d994b45 100644 --- a/internal/domain/repository/news_repository.go +++ b/internal/domain/repository/news_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type NewsRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewNewsRepository(db *gorm.DB) *NewsRepository { } type INewsRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.News, error) + Save(*entity.News) (*entity.News, error) + Update(*entity.News) (*entity.News, error) + Delete(*entity.News) error +} + +func (r *NewsRepository) Count(fixtureId, teamId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.News{}).Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *NewsRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var news []*entity.News + err := r.db.Scopes(Paginate(news, pagination, r.db)).Find(&news).Error + if err != nil { + return nil, err + } + pagination.Rows = news + return pagination, nil +} + +func (r *NewsRepository) Get(fixtureId, teamId int) (*entity.News, error) { + var c entity.News + err := r.db.Where("fixture_id = ?", fixtureId).Where("team_id = ?", teamId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *NewsRepository) Save(c *entity.News) (*entity.News, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *NewsRepository) Update(c *entity.News) (*entity.News, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *NewsRepository) Delete(c *entity.News) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/prediction_repository.go b/internal/domain/repository/prediction_repository.go index f1e1f9d..fef5ab4 100644 --- a/internal/domain/repository/prediction_repository.go +++ b/internal/domain/repository/prediction_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type PredictionRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewPredictionRepository(db *gorm.DB) *PredictionRepository { } type IPredictionRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Prediction, error) + Save(*entity.Prediction) (*entity.Prediction, error) + Update(*entity.Prediction) (*entity.Prediction, error) + Delete(*entity.Prediction) error +} + +func (r *PredictionRepository) Count(fixtureId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Prediction{}).Where("fixture_id = ?", fixtureId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *PredictionRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var news []*entity.News + err := r.db.Scopes(Paginate(news, pagination, r.db)).Find(&news).Error + if err != nil { + return nil, err + } + pagination.Rows = news + return pagination, nil +} + +func (r *PredictionRepository) Get(fixtureId int) (*entity.Prediction, error) { + var c entity.Prediction + err := r.db.Where("fixture_id = ?", fixtureId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *PredictionRepository) Save(c *entity.Prediction) (*entity.Prediction, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *PredictionRepository) Update(c *entity.Prediction) (*entity.Prediction, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *PredictionRepository) Delete(c *entity.Prediction) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/reward_repository.go b/internal/domain/repository/reward_repository.go index 09e3bb4..4c0f801 100644 --- a/internal/domain/repository/reward_repository.go +++ b/internal/domain/repository/reward_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type RewardRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewRewardRepository(db *gorm.DB) *RewardRepository { } type IRewardRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Reward, error) + Save(*entity.Reward) (*entity.Reward, error) + Update(*entity.Reward) (*entity.Reward, error) + Delete(*entity.Reward) error +} + +func (r *RewardRepository) Count(fixtureId, subscriptionId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Reward{}).Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *RewardRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var rewards []*entity.Reward + err := r.db.Scopes(Paginate(rewards, pagination, r.db)).Find(&rewards).Error + if err != nil { + return nil, err + } + pagination.Rows = rewards + return pagination, nil +} + +func (r *RewardRepository) Get(fixtureId, subscriptionId int) (*entity.Reward, error) { + var c entity.Reward + err := r.db.Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *RewardRepository) Save(c *entity.Reward) (*entity.Reward, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *RewardRepository) Update(c *entity.Reward) (*entity.Reward, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *RewardRepository) Delete(c *entity.Reward) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/schedule_repository.go b/internal/domain/repository/schedule_repository.go index aa95d6e..2479950 100644 --- a/internal/domain/repository/schedule_repository.go +++ b/internal/domain/repository/schedule_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type ScheduleRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewScheduleRepository(db *gorm.DB) *ScheduleRepository { } type IScheduleRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Schedule, error) + Save(*entity.Schedule) (*entity.Schedule, error) + Update(*entity.Schedule) (*entity.Schedule, error) + Delete(*entity.Schedule) error +} + +func (r *ScheduleRepository) Count(fixtureId, subscriptionId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Schedule{}).Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *ScheduleRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var schedules []*entity.Schedule + err := r.db.Scopes(Paginate(schedules, pagination, r.db)).Find(&schedules).Error + if err != nil { + return nil, err + } + pagination.Rows = schedules + return pagination, nil +} + +func (r *ScheduleRepository) Get(fixtureId, subscriptionId int) (*entity.Schedule, error) { + var c entity.Schedule + err := r.db.Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *ScheduleRepository) Save(c *entity.Schedule) (*entity.Schedule, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *ScheduleRepository) Update(c *entity.Schedule) (*entity.Schedule, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *ScheduleRepository) Delete(c *entity.Schedule) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/season_repository.go b/internal/domain/repository/season_repository.go index e62665e..8cd9786 100644 --- a/internal/domain/repository/season_repository.go +++ b/internal/domain/repository/season_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type SeasonRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewSeasonRepository(db *gorm.DB) *SeasonRepository { } type ISeasonRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Season, error) + Save(*entity.Season) (*entity.Season, error) + Update(*entity.Season) (*entity.Season, error) + Delete(*entity.Season) error +} + +func (r *SeasonRepository) Count(fixtureId, subscriptionId int) (int64, error) { + var count int64 + err := r.db.Model(&entity.Season{}).Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *SeasonRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var seasons []*entity.Season + err := r.db.Scopes(Paginate(seasons, pagination, r.db)).Find(&seasons).Error + if err != nil { + return nil, err + } + pagination.Rows = seasons + return pagination, nil +} + +func (r *SeasonRepository) Get(fixtureId, subscriptionId int) (*entity.Season, error) { + var c entity.Season + err := r.db.Where("fixture_id = ?", fixtureId).Where("subscription_id = ?", subscriptionId).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *SeasonRepository) Save(c *entity.Season) (*entity.Season, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *SeasonRepository) Update(c *entity.Season) (*entity.Season, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *SeasonRepository) Delete(c *entity.Season) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/service_repository.go b/internal/domain/repository/service_repository.go index 63c0ced..bb2f95b 100644 --- a/internal/domain/repository/service_repository.go +++ b/internal/domain/repository/service_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type ServiceRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewServiceRepository(db *gorm.DB) *ServiceRepository { } type IServiceRepository interface { + Count(string) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Service, error) + Save(*entity.Service) (*entity.Service, error) + Update(*entity.Service) (*entity.Service, error) + Delete(*entity.Service) error +} + +func (r *ServiceRepository) Count(code string) (int64, error) { + var count int64 + err := r.db.Model(&entity.Service{}).Where("code = ?", code).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *ServiceRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var services []*entity.Service + err := r.db.Scopes(Paginate(services, pagination, r.db)).Find(&services).Error + if err != nil { + return nil, err + } + pagination.Rows = services + return pagination, nil +} + +func (r *ServiceRepository) Get(code string) (*entity.Service, error) { + var c entity.Service + err := r.db.Where("code = ?", code).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *ServiceRepository) Save(c *entity.Service) (*entity.Service, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *ServiceRepository) Update(c *entity.Service) (*entity.Service, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *ServiceRepository) Delete(c *entity.Service) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/subscription_respository.go b/internal/domain/repository/subscription_respository.go index 8b190db..fcb51cf 100644 --- a/internal/domain/repository/subscription_respository.go +++ b/internal/domain/repository/subscription_respository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type SubscriptionRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewSubscriptionRepository(db *gorm.DB) *SubscriptionRepository { } type ISubscriptionRepository interface { + Count(int, string) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, string) (*entity.Subscription, error) + Save(*entity.Subscription) (*entity.Subscription, error) + Update(*entity.Subscription) (*entity.Subscription, error) + Delete(*entity.Subscription) error +} + +func (r *SubscriptionRepository) Count(serviceId int, msisdn string) (int64, error) { + var count int64 + err := r.db.Model(&entity.Subscription{}).Where("service_id = ?", serviceId).Where("msisdn = ?", msisdn).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *SubscriptionRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var subscriptions []*entity.Subscription + err := r.db.Scopes(Paginate(subscriptions, pagination, r.db)).Find(&subscriptions).Error + if err != nil { + return nil, err + } + pagination.Rows = subscriptions + return pagination, nil +} + +func (r *SubscriptionRepository) Get(serviceId int, msisdn string) (*entity.Subscription, error) { + var c entity.Subscription + err := r.db.Where("service_id = ?", serviceId).Where("msisdn = ?", msisdn).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *SubscriptionRepository) Save(c *entity.Subscription) (*entity.Subscription, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *SubscriptionRepository) Update(c *entity.Subscription) (*entity.Subscription, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *SubscriptionRepository) Delete(c *entity.Subscription) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/team_repository.go b/internal/domain/repository/team_repository.go index 4921b8b..08eb7e5 100644 --- a/internal/domain/repository/team_repository.go +++ b/internal/domain/repository/team_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type TeamRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewTeamRepository(db *gorm.DB) *TeamRepository { } type ITeamRepository interface { + Count(string) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(string) (*entity.Team, error) + Save(*entity.Team) (*entity.Team, error) + Update(*entity.Team) (*entity.Team, error) + Delete(*entity.Team) error +} + +func (r *TeamRepository) Count(slug string) (int64, error) { + var count int64 + err := r.db.Model(&entity.Team{}).Where("slug = ?", slug).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *TeamRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var teams []*entity.Team + err := r.db.Scopes(Paginate(teams, pagination, r.db)).Find(&teams).Error + if err != nil { + return nil, err + } + pagination.Rows = teams + return pagination, nil +} + +func (r *TeamRepository) Get(slug string) (*entity.Team, error) { + var c entity.Team + err := r.db.Where("slug = ?", slug).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *TeamRepository) Save(c *entity.Team) (*entity.Team, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *TeamRepository) Update(c *entity.Team) (*entity.Team, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *TeamRepository) Delete(c *entity.Team) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/domain/repository/transaction_repository.go b/internal/domain/repository/transaction_repository.go index cfb9a68..6451189 100644 --- a/internal/domain/repository/transaction_repository.go +++ b/internal/domain/repository/transaction_repository.go @@ -1,6 +1,9 @@ package repository -import "gorm.io/gorm" +import ( + "github.com/idprm/go-football-alert/internal/domain/entity" + "gorm.io/gorm" +) type TransactionRepository struct { db *gorm.DB @@ -13,4 +16,62 @@ func NewTransactionRepository(db *gorm.DB) *TransactionRepository { } type ITransactionRepository interface { + Count(int, int) (int64, error) + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, int) (*entity.Transaction, error) + Save(*entity.Transaction) (*entity.Transaction, error) + Update(*entity.Transaction) (*entity.Transaction, error) + Delete(*entity.Transaction) error +} + +func (r *TransactionRepository) Count(slug string) (int64, error) { + var count int64 + err := r.db.Model(&entity.Transaction{}).Where("slug = ?", slug).Count(&count).Error + if err != nil { + return count, err + } + return count, nil +} + +func (r *TransactionRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + var transactions []*entity.Transaction + err := r.db.Scopes(Paginate(transactions, pagination, r.db)).Find(&transactions).Error + if err != nil { + return nil, err + } + pagination.Rows = transactions + return pagination, nil +} + +func (r *TransactionRepository) Get(slug string) (*entity.Transaction, error) { + var c entity.Transaction + err := r.db.Where("slug = ?", slug).Take(&c).Error + if err != nil { + return nil, err + } + return &c, nil +} + +func (r *TransactionRepository) Save(c *entity.Transaction) (*entity.Transaction, error) { + err := r.db.Create(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *TransactionRepository) Update(c *entity.Transaction) (*entity.Transaction, error) { + err := r.db.Where("id = ?", c.ID).Updates(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + +func (r *TransactionRepository) Delete(c *entity.Transaction) error { + err := r.db.Delete(&c, c.ID).Error + if err != nil { + return err + } + return nil } diff --git a/internal/services/away_service.go b/internal/services/away_service.go index 6bc1d01..119276e 100644 --- a/internal/services/away_service.go +++ b/internal/services/away_service.go @@ -1,6 +1,7 @@ package services import ( + "github.com/idprm/go-football-alert/internal/domain/entity" "github.com/idprm/go-football-alert/internal/domain/repository" ) @@ -15,12 +16,35 @@ func NewAwayService(awayRepo repository.IAwayRepository) *AwayService { } type IAwayService interface { - // IsAway(string) bool - // GetAll() (*[]entity.Away, error) - // GetAllPaginate(int, int) (*[]entity.Away, error) - // GetById(int) (*entity.Away, error) - // GetBySlug(string) (*entity.Away, error) - // Save(*entity.Away) (*entity.Away, error) - // Update(*entity.Away) (*entity.Away, error) - // Delete(*entity.Away) error + IsAwayTeamId(int) bool + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + GetByTeamId(int) (*entity.Away, error) + Save(*entity.Away) (*entity.Away, error) + Update(*entity.Away) (*entity.Away, error) + Delete(*entity.Away) error +} + +func (s *AwayService) IsPostBySlug(teamId int) bool { + count, _ := s.awayRepo.CountByTeamId(teamId) + return count > 0 +} + +func (s *AwayService) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + return s.awayRepo.GetAllPaginate(pagination) +} + +func (s *AwayService) GetByTeamId(teamId int) (*entity.Away, error) { + return s.awayRepo.GetByTeamId(teamId) +} + +func (s *AwayService) Save(a *entity.Away) (*entity.Away, error) { + return s.awayRepo.Save(a) +} + +func (s *AwayService) Update(a *entity.Away) (*entity.Away, error) { + return s.awayRepo.Update(a) +} + +func (s *AwayService) Delete(a *entity.Away) error { + return s.awayRepo.Delete(a) } diff --git a/internal/services/content_service.go b/internal/services/content_service.go index 6b0c435..b2e90d1 100644 --- a/internal/services/content_service.go +++ b/internal/services/content_service.go @@ -16,12 +16,35 @@ func NewContentService(contentRepo repository.IContentRepository) *ContentServic } type IContentService interface { - IsAway(string) bool - GetAll() (*[]entity.Content, error) - GetAllPaginate(int, int) (*[]entity.Content, error) - GetById(int) (*entity.Content, error) - GetBySlug(string) (*entity.Content, error) + IsContent(int, string) bool + GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) + Get(int, string) (*entity.Content, error) Save(*entity.Content) (*entity.Content, error) Update(*entity.Content) (*entity.Content, error) Delete(*entity.Content) error } + +func (s *ContentService) IsPostBySlug(servceId int, key string) bool { + count, _ := s.contentRepo.Count(servceId, key) + return count > 0 +} + +func (s *ContentService) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + return s.contentRepo.GetAllPaginate(pagination) +} + +func (s *ContentService) Get(servceId int, key string) (*entity.Content, error) { + return s.contentRepo.Get(servceId, key) +} + +func (s *ContentService) Save(a *entity.Content) (*entity.Content, error) { + return s.contentRepo.Save(a) +} + +func (s *ContentService) Update(a *entity.Content) (*entity.Content, error) { + return s.contentRepo.Update(a) +} + +func (s *ContentService) Delete(a *entity.Content) error { + return s.contentRepo.Delete(a) +} diff --git a/internal/services/league_service.go b/internal/services/league_service.go index 7684e44..16cb755 100644 --- a/internal/services/league_service.go +++ b/internal/services/league_service.go @@ -16,12 +16,35 @@ func NewLeagueService(leagueRepo repository.ILeagueRepository) *LeagueService { } type ILeagueService interface { - IsHome(string) bool - GetAll() (*[]entity.League, error) + IsLeague(string) bool GetAllPaginate(int, int) (*[]entity.League, error) - GetById(int) (*entity.League, error) - GetBySlug(string) (*entity.League, error) + Get(string) (*entity.League, error) Save(*entity.League) (*entity.League, error) Update(*entity.League) (*entity.League, error) Delete(*entity.League) error } + +func (s *LeagueService) IsLeague(key string) bool { + count, _ := s.leagueRepo.Count(key) + return count > 0 +} + +func (s *LeagueService) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) { + return s.leagueRepo.GetAllPaginate(pagination) +} + +func (s *LeagueService) Get(slug string) (*entity.League, error) { + return s.leagueRepo.Get(slug) +} + +func (s *LeagueService) Save(a *entity.League) (*entity.League, error) { + return s.leagueRepo.Save(a) +} + +func (s *LeagueService) Update(a *entity.League) (*entity.League, error) { + return s.leagueRepo.Update(a) +} + +func (s *LeagueService) Delete(a *entity.League) error { + return s.leagueRepo.Delete(a) +}