Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Aug 9, 2024
1 parent dfd55ef commit 93165a8
Show file tree
Hide file tree
Showing 17 changed files with 902 additions and 33 deletions.
12 changes: 9 additions & 3 deletions internal/domain/entity/news.go
Original file line number Diff line number Diff line change
@@ -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"`
}
63 changes: 62 additions & 1 deletion internal/domain/repository/fixture_repository.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
63 changes: 62 additions & 1 deletion internal/domain/repository/home_repository.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
63 changes: 62 additions & 1 deletion internal/domain/repository/league_repository.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
63 changes: 62 additions & 1 deletion internal/domain/repository/livescore_repository.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
63 changes: 62 additions & 1 deletion internal/domain/repository/news_repository.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Loading

0 comments on commit 93165a8

Please sign in to comment.