From 21a0d86e1c2dc9eeb18815f3b22ab0158e36141c Mon Sep 17 00:00:00 2001 From: Indra Pramana Date: Thu, 19 Dec 2024 20:35:57 +0700 Subject: [PATCH] add new --- cmd/listener.go | 4 ++++ internal/domain/model/request.go | 4 ++++ internal/domain/repository/league_repository.go | 10 ++++++++++ internal/handler/incoming_handler.go | 11 +++++++++++ internal/handler/scraper_handler.go | 2 +- internal/services/league_service.go | 5 +++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/cmd/listener.go b/cmd/listener.go index 31f52aa..21ee568 100644 --- a/cmd/listener.go +++ b/cmd/listener.go @@ -177,6 +177,9 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log livescoreRepo := repository.NewLiveScoreRepository(db) livescoreService := services.NewLiveScoreService(livescoreRepo) + standingRepo := repository.NewStandingRepository(db) + standingService := services.NewStandingService(standingRepo) + predictionRepo := repository.NewPredictionRepository(db) predictionService := services.NewPredictionService(predictionRepo) @@ -239,6 +242,7 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log fixtureService, livematchService, livescoreService, + standingService, predictionService, newsService, scheduleService, diff --git a/internal/domain/model/request.go b/internal/domain/model/request.go index 1f632f4..612cce7 100644 --- a/internal/domain/model/request.go +++ b/internal/domain/model/request.go @@ -340,6 +340,10 @@ func (m *UssdRequest) IsLmLiveMatchLater() bool { return m.GetSlug() == "lm-live-match-later" } +func (m *UssdRequest) IsLmStanding() bool { + return m.GetSlug() == "lm-standing" +} + func (m *UssdRequest) IsLmSchedule() bool { return m.GetSlug() == "lm-schedule" } diff --git a/internal/domain/repository/league_repository.go b/internal/domain/repository/league_repository.go index 1b067fe..a363461 100644 --- a/internal/domain/repository/league_repository.go +++ b/internal/domain/repository/league_repository.go @@ -22,6 +22,7 @@ type ILeagueRepository interface { CountByName(string) (int64, error) GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) GetAllByActive() ([]*entity.League, error) + GetAllUSSDByActive() ([]*entity.League, error) GetOnlyWorldByActive() ([]*entity.League, error) GetAllUSSD(int) ([]*entity.League, error) GetAllEuropeUSSD(int) ([]*entity.League, error) @@ -94,6 +95,15 @@ func (r *LeagueRepository) GetAllByActive() ([]*entity.League, error) { return c, nil } +func (r *LeagueRepository) GetAllUSSDByActive() ([]*entity.League, error) { + var c []*entity.League + err := r.db.Where("is_active = true AND sort <> 0").Where("country IN('England', 'Belgium', 'Portugal', 'France', 'Italy', 'Spain', 'Germany', 'World')").Find(&c).Error + if err != nil { + return nil, err + } + return c, nil +} + func (r *LeagueRepository) GetOnlyWorldByActive() ([]*entity.League, error) { var c []*entity.League err := r.db.Where(&entity.League{IsActive: true, Country: "World", Code: "UEFA"}).Find(&c).Error diff --git a/internal/handler/incoming_handler.go b/internal/handler/incoming_handler.go index b4002b0..1474cd5 100644 --- a/internal/handler/incoming_handler.go +++ b/internal/handler/incoming_handler.go @@ -104,6 +104,7 @@ type IncomingHandler struct { fixtureService services.IFixtureService livematchService services.ILiveMatchService livescoreService services.ILiveScoreService + standingService services.IStandingService predictionService services.IPredictionService newsService services.INewsService scheduleService services.IScheduleService @@ -125,6 +126,7 @@ func NewIncomingHandler( fixtureService services.IFixtureService, livematchService services.ILiveMatchService, livescoreService services.ILiveScoreService, + standingService services.IStandingService, predictionService services.IPredictionService, newsService services.INewsService, scheduleService services.IScheduleService, @@ -145,6 +147,7 @@ func NewIncomingHandler( fixtureService: fixtureService, livematchService: livematchService, livescoreService: livescoreService, + standingService: standingService, predictionService: predictionService, newsService: newsService, scheduleService: scheduleService, @@ -378,6 +381,10 @@ func (h *IncomingHandler) Menu(c *fiber.Ctx) error { data = h.LiveMatchesLater(c.BaseURL(), true, req.GetPage()+1) } + if req.IsLmStanding() { + + } + if req.IsLmSchedule() { data = h.Schedules(c.BaseURL(), req.GetPage()+1) } @@ -949,6 +956,10 @@ func (h *IncomingHandler) LiveMatchesLater(baseUrl string, isActive bool, page i return liveMatchsString } +func (h *IncomingHandler) StandingByLeague(baseUrl string, page int) string { + return "" +} + func (h *IncomingHandler) Schedules(baseUrl string, page int) string { schedules, err := h.fixtureService.GetAllScheduleUSSD(page) if err != nil { diff --git a/internal/handler/scraper_handler.go b/internal/handler/scraper_handler.go index 00459f7..63f5615 100644 --- a/internal/handler/scraper_handler.go +++ b/internal/handler/scraper_handler.go @@ -390,7 +390,7 @@ func (h *ScraperHandler) Predictions() { func (h *ScraperHandler) Standings() { fb := apifb.NewApiFb() - leagues, err := h.leagueService.GetOnlyWorldByActive() + leagues, err := h.leagueService.GetAllUSSDByActive() if err != nil { log.Println(err.Error()) } diff --git a/internal/services/league_service.go b/internal/services/league_service.go index 6d3d784..3fcada9 100644 --- a/internal/services/league_service.go +++ b/internal/services/league_service.go @@ -22,6 +22,7 @@ type ILeagueService interface { IsLeagueByName(string) bool GetAllPaginate(*entity.Pagination) (*entity.Pagination, error) GetAllByActive() ([]*entity.League, error) + GetAllUSSDByActive() ([]*entity.League, error) GetOnlyWorldByActive() ([]*entity.League, error) GetAllUSSD(int) ([]*entity.League, error) GetAllEuropeUSSD(int) ([]*entity.League, error) @@ -74,6 +75,10 @@ func (s *LeagueService) GetAllByActive() ([]*entity.League, error) { return s.leagueRepo.GetAllByActive() } +func (s *LeagueService) GetAllUSSDByActive() ([]*entity.League, error) { + return s.leagueRepo.GetAllUSSDByActive() +} + func (s *LeagueService) GetOnlyWorldByActive() ([]*entity.League, error) { return s.leagueRepo.GetOnlyWorldByActive() }