Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Oct 12, 2024
1 parent 1570387 commit b6b6baa
Show file tree
Hide file tree
Showing 31 changed files with 537 additions and 408 deletions.
11 changes: 1 addition & 10 deletions cmd/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ var listenerCmd = &cobra.Command{
&entity.News{},
&entity.NewsLeagues{},
&entity.NewsTeams{},
&entity.FollowLeague{},
&entity.FollowTeam{},
&entity.Schedule{},
&entity.Service{},
&entity.Content{},
Expand All @@ -80,6 +78,7 @@ var listenerCmd = &cobra.Command{
&entity.SubscriptionPredict{},
&entity.SubscriptionFollowLeague{},
&entity.SubscriptionFollowTeam{},
&entity.SMSAlerte{},
&entity.Transaction{},
&entity.History{},
&entity.Reward{},
Expand Down Expand Up @@ -158,12 +157,6 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log
newsRepo := repository.NewNewsRepository(db)
newsService := services.NewNewsService(newsRepo)

FollowLeagueRepo := repository.NewFollowLeagueRepository(db)
FollowLeagueService := services.NewFollowLeagueService(FollowLeagueRepo)

followTeamRepo := repository.NewFollowTeamRepository(db)
followTeamService := services.NewFollowTeamService(followTeamRepo)

scheduleRepo := repository.NewScheduleRepository(db)
scheduleService := services.NewScheduleService(scheduleRepo)

Expand Down Expand Up @@ -223,8 +216,6 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log
leagueService,
teamService,
newsService,
FollowLeagueService,
followTeamService,
&entity.News{},
)

Expand Down
21 changes: 9 additions & 12 deletions cmd/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ func (p *Processor) News(wg *sync.WaitGroup, message []byte) {
teamService := services.NewTeamService(teamRepo)
newsRepo := repository.NewNewsRepository(p.db)
newsService := services.NewNewsService(newsRepo)
FollowLeagueRepo := repository.NewFollowLeagueRepository(p.db)
FollowLeagueService := services.NewFollowLeagueService(FollowLeagueRepo)
followTeamRepo := repository.NewFollowTeamRepository(p.db)
followTeamService := services.NewFollowTeamService(followTeamRepo)

// parsing json to string
var news *entity.News
Expand All @@ -177,8 +173,6 @@ func (p *Processor) News(wg *sync.WaitGroup, message []byte) {
leagueService,
teamService,
newsService,
FollowLeagueService,
followTeamService,
news,
)

Expand All @@ -193,14 +187,16 @@ func (p *Processor) SMSAlerte(wg *sync.WaitGroup, message []byte) {
*/
serviceRepo := repository.NewServiceRepository(p.db)
serviceService := services.NewServiceService(serviceRepo)
contentRepo := repository.NewContentRepository(p.db)
contentService := services.NewContentService(contentRepo)
subscriptionRepo := repository.NewSubscriptionRepository(p.db)
subscriptionService := services.NewSubscriptionService(subscriptionRepo)
transactionRepo := repository.NewTransactionRepository(p.db)
transactionService := services.NewTransactionService(transactionRepo)
newsRepo := repository.NewNewsRepository(p.db)
newsService := services.NewNewsService(newsRepo)
subscriptionFollowLeagueRepo := repository.NewSubscriptionFollowLeagueRepository(p.db)
subscriptionFollowLeagueService := services.NewSubscriptionFollowLeagueService(subscriptionFollowLeagueRepo)
subscriptionFollowTeamRepo := repository.NewSubscriptionFollowTeamRepository(p.db)
subscriptionFollowTeamService := services.NewSubscriptionFollowTeamService(subscriptionFollowTeamRepo)
smsAlerteRepo := repository.NewSMSAlerteRespository(p.db)
smsAlerteService := services.NewSMSAlerteService(smsAlerteRepo)

// parsing json to string
var sub *entity.Subscription
Expand All @@ -211,10 +207,11 @@ func (p *Processor) SMSAlerte(wg *sync.WaitGroup, message []byte) {
p.logger,
sub,
serviceService,
contentService,
subscriptionService,
transactionService,
newsService,
subscriptionFollowLeagueService,
subscriptionFollowTeamService,
smsAlerteService,
)

// Send SMS Alerte
Expand Down
30 changes: 17 additions & 13 deletions cmd/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"encoding/json"
"log"
"time"

"github.com/idprm/go-football-alert/internal/domain/entity"
Expand Down Expand Up @@ -59,9 +60,9 @@ var publisherRenewalCmd = &cobra.Command{
)

/**
* Looping schedule
* Looping schedule per 10 minutes
*/
timeDuration := time.Duration(30)
timeDuration := time.Duration(10)

for {

Expand Down Expand Up @@ -107,7 +108,7 @@ var publisherRetryCmd = &cobra.Command{
)

/**
* Looping schedule
* Looping schedule per 30 minutes
*/
timeDuration := time.Duration(30)

Expand Down Expand Up @@ -394,11 +395,14 @@ var publisherSMSAlerteCmd = &cobra.Command{
for {
timeNow := time.Now().Format("15:04")

log.Println(timeNow)
scheduleRepo := repository.NewScheduleRepository(db)
scheduleService := services.NewScheduleService(scheduleRepo)

if scheduleService.IsUnlocked(ACT_SMS_ALERTE, timeNow) {

log.Println(timeNow)

scheduleService.UpdateLocked(
&entity.Schedule{
Name: ACT_SMS_ALERTE,
Expand Down Expand Up @@ -468,13 +472,13 @@ func populateRetry(db *gorm.DB, rmq rmqp.AMQP) {
}
}

func populatePrediction(db *gorm.DB, rmq rmqp.AMQP) {
func populateSMSAlerte(db *gorm.DB, rmq rmqp.AMQP) {
subscriptionRepo := repository.NewSubscriptionRepository(db)
subscriptionService := services.NewSubscriptionService(subscriptionRepo)

subs := subscriptionService.Prediction()
followsLeague := subscriptionService.Follow()

for _, s := range *subs {
for _, s := range *followsLeague {
var sub entity.Subscription

sub.ID = s.ID
Expand All @@ -488,17 +492,17 @@ func populatePrediction(db *gorm.DB, rmq rmqp.AMQP) {

json, _ := json.Marshal(sub)

rmq.IntegratePublish(RMQ_PREDICTION_EXCHANGE, RMQ_PREDICTION_QUEUE, RMQ_DATA_TYPE, "", string(json))
rmq.IntegratePublish(RMQ_SMS_ALERTE_EXCHANGE, RMQ_SMS_ALERTE_QUEUE, RMQ_DATA_TYPE, "", string(json))

time.Sleep(100 * time.Microsecond)
}
}

func populateGoalCredit(db *gorm.DB, rmq rmqp.AMQP) {
func populatePrediction(db *gorm.DB, rmq rmqp.AMQP) {
subscriptionRepo := repository.NewSubscriptionRepository(db)
subscriptionService := services.NewSubscriptionService(subscriptionRepo)

subs := subscriptionService.Renewal()
subs := subscriptionService.Prediction()

for _, s := range *subs {
var sub entity.Subscription
Expand All @@ -514,17 +518,17 @@ func populateGoalCredit(db *gorm.DB, rmq rmqp.AMQP) {

json, _ := json.Marshal(sub)

rmq.IntegratePublish(RMQ_CREDIT_EXCHANGE, RMQ_CREDIT_QUEUE, RMQ_DATA_TYPE, "", string(json))
rmq.IntegratePublish(RMQ_PREDICTION_EXCHANGE, RMQ_PREDICTION_QUEUE, RMQ_DATA_TYPE, "", string(json))

time.Sleep(100 * time.Microsecond)
}
}

func populateSMSAlerte(db *gorm.DB, rmq rmqp.AMQP) {
func populateGoalCredit(db *gorm.DB, rmq rmqp.AMQP) {
subscriptionRepo := repository.NewSubscriptionRepository(db)
subscriptionService := services.NewSubscriptionService(subscriptionRepo)

subs := subscriptionService.FollowLeague()
subs := subscriptionService.Renewal()

for _, s := range *subs {
var sub entity.Subscription
Expand All @@ -540,7 +544,7 @@ func populateSMSAlerte(db *gorm.DB, rmq rmqp.AMQP) {

json, _ := json.Marshal(sub)

rmq.IntegratePublish(RMQ_SMS_ALERTE_EXCHANGE, RMQ_SMS_ALERTE_QUEUE, RMQ_DATA_TYPE, "", string(json))
rmq.IntegratePublish(RMQ_CREDIT_EXCHANGE, RMQ_CREDIT_QUEUE, RMQ_DATA_TYPE, "", string(json))

time.Sleep(100 * time.Microsecond)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func seederDB(db *gorm.DB) {
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_FOLLOW_TEAM_SUB,
Value: "SMS Alerte: Vous avez souscrit avec succes pour suivre votre equipe favorite! Jusqu au {date}/{month} vous recevrez toutes les infos en direct. {price}{currency}/souscription",
Value: "SMS Alerte: Vous avez souscrit avec succes pour suivre votre equipe favorite! Jusqu au {day}/{month} vous recevrez toutes les infos en direct. {price}{currency}/souscription",
},
{
Category: ACT_CONFIRMATION,
Expand Down
8 changes: 4 additions & 4 deletions internal/domain/entity/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ func (e *Content) GetValue() string {
return e.Value
}

func (e *Content) SetValueSubFollowCompetition(league, date, month, price, currency string) {
func (e *Content) SetValueSubFollowCompetition(league, day, month, price, currency string) {
replacer := strings.NewReplacer(
"{league}", league,
"{date}", date,
"{day}", day,
"{month}", month,
"{price}", price,
"{currency}", url.QueryEscape(currency))
e.Value = replacer.Replace(e.Value)
}

func (e *Content) SetValueSubFollowTeam(team, date, month, price, currency string) {
func (e *Content) SetValueSubFollowTeam(team, day, month, price, currency string) {
replacer := strings.NewReplacer(
"{team}", team,
"{date}", date,
"{day}", day,
"{month}", month,
"{price}", price,
"{currency}", url.QueryEscape(currency))
Expand Down
12 changes: 0 additions & 12 deletions internal/domain/entity/follow_league.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package entity

import "gorm.io/gorm"

type FollowTeam struct {
type SMSAlerte struct {
ID int64 `gorm:"primaryKey" json:"id"`
SubscriptionID int64 `json:"subscription_id"`
Subscription *Subscription `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"subscription,omitempty"`
TeamID int64 `json:"team_id"`
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"team,omitempty"`
NewsID int64 `json:"news_id"`
News *News `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"news,omitempty"`
gorm.Model `json:"-"`
}
83 changes: 43 additions & 40 deletions internal/domain/entity/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,49 @@ import (
)

type Subscription struct {
ID int64 `gorm:"primaryKey" json:"id"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Category string `gorm:"size:20" json:"category"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
Channel string `gorm:"size:15" json:"channel,omitempty"`
LatestTrxId string `gorm:"size:100" json:"trx_id,omitempty"`
LatestKeyword string `gorm:"size:50" json:"latest_keyword,omitempty"`
LatestSubject string `gorm:"size:25" json:"latest_subject,omitempty"`
LatestStatus string `gorm:"size:25" json:"latest_status,omitempty"`
LatestPayload string `gorm:"type:text" json:"latest_payload,omitempty"`
RenewalAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"renewal_at,omitempty"`
UnsubAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"unsub_at,omitempty"`
ChargeAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"charge_at,omitempty"`
RetryAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"retry_at,omitempty"`
FreeAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"free_at,omitempty"`
FollowAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"follow_at,omitempty"`
PredictionAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"prediction_at,omitempty"`
CreditGoalAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"credit_goal_at,omitempty"`
FirstSuccessAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"first_success_at,omitempty"`
TotalSuccess int `gorm:"default:0" json:"total_success,omitempty"`
TotalFailed int `gorm:"default:0" json:"total_failed,omitempty"`
TotalAmount float64 `gorm:"default:0" json:"total_amount,omitempty"`
TotalFirstpush int `gorm:"default:0" json:"total_firstpush,omitempty"`
TotalRenewal int `gorm:"default:0" json:"total_renewal,omitempty"`
TotalSub int `gorm:"default:0" json:"total_sub,omitempty"`
TotalUnsub int `gorm:"default:0" json:"total_unsub,omitempty"`
TotalAmountFirstpush float64 `gorm:"default:0" json:"total_amount_firstpush,omitempty"`
TotalAmountRenewal float64 `gorm:"default:0" json:"total_amount_renewal,omitempty"`
BeforeBalance float64 `gorm:"default:0" json:"before_balance,omitempty"`
AfterBalance float64 `gorm:"default:0" json:"after_balance,omitempty"`
ExpireAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"expire_at,omitempty"`
IpAddress string `gorm:"size:25" json:"ip_address,omitempty"`
IsFollowTeam bool `gorm:"type:boolean;column:is_follow_team" json:"is_follow_team,omitempty"`
IsFollowLeague bool `gorm:"type:boolean;column:is_follow_competition" json:"is_follow_competition,omitempty"`
IsPrediction bool `gorm:"type:boolean;column:is_prediction" json:"is_prediction,omitempty"`
IsCreditGoal bool `gorm:"type:boolean;column:is_credit_goal" json:"is_credit_goal,omitempty"`
IsRetry bool `gorm:"type:boolean;column:is_retry" json:"is_retry,omitempty"`
IsFree bool `gorm:"type:boolean;column:is_free" json:"is_free,omitempty"`
IsActive bool `gorm:"type:boolean;column:is_active" json:"is_active,omitempty"`
ID int64 `gorm:"primaryKey" json:"id"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Category string `gorm:"size:20" json:"category"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
Channel string `gorm:"size:15" json:"channel,omitempty"`
LatestTrxId string `gorm:"size:100" json:"trx_id,omitempty"`
LatestKeyword string `gorm:"size:50" json:"latest_keyword,omitempty"`
LatestSubject string `gorm:"size:25" json:"latest_subject,omitempty"`
LatestStatus string `gorm:"size:25" json:"latest_status,omitempty"`
LatestPayload string `gorm:"type:text" json:"latest_payload,omitempty"`
RenewalAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"renewal_at,omitempty"`
UnsubAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"unsub_at,omitempty"`
ChargeAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"charge_at,omitempty"`
RetryAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"retry_at,omitempty"`
FreeAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"free_at,omitempty"`
FollowAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"follow_at,omitempty"`
PredictionAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"prediction_at,omitempty"`
CreditGoalAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"credit_goal_at,omitempty"`
FirstSuccessAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"first_success_at,omitempty"`
TotalSuccess int `gorm:"default:0" json:"total_success,omitempty"`
TotalFailed int `gorm:"default:0" json:"total_failed,omitempty"`
TotalAmount float64 `gorm:"default:0" json:"total_amount,omitempty"`
TotalFirstpush int `gorm:"default:0" json:"total_firstpush,omitempty"`
TotalRenewal int `gorm:"default:0" json:"total_renewal,omitempty"`
TotalSub int `gorm:"default:0" json:"total_sub,omitempty"`
TotalUnsub int `gorm:"default:0" json:"total_unsub,omitempty"`
TotalAmountFirstpush float64 `gorm:"default:0" json:"total_amount_firstpush,omitempty"`
TotalAmountRenewal float64 `gorm:"default:0" json:"total_amount_renewal,omitempty"`
BeforeBalance float64 `gorm:"default:0" json:"before_balance,omitempty"`
AfterBalance float64 `gorm:"default:0" json:"after_balance,omitempty"`
ExpireAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"expire_at,omitempty"`
IpAddress string `gorm:"size:25" json:"ip_address,omitempty"`
IsFollowTeam bool `gorm:"type:boolean;column:is_follow_team" json:"is_follow_team,omitempty"`
IsFollowLeague bool `gorm:"type:boolean;column:is_follow_competition" json:"is_follow_competition,omitempty"`
IsPrediction bool `gorm:"type:boolean;column:is_prediction" json:"is_prediction,omitempty"`
IsCreditGoal bool `gorm:"type:boolean;column:is_credit_goal" json:"is_credit_goal,omitempty"`
IsRetry bool `gorm:"type:boolean;column:is_retry" json:"is_retry,omitempty"`
IsFree bool `gorm:"type:boolean;column:is_free" json:"is_free,omitempty"`
IsActive bool `gorm:"type:boolean;column:is_active" json:"is_active,omitempty"`
League *League `gorm:"many2many:subscription_follow_leagues" json:"league"`
Team *Team `gorm:"many2many:subscription_follow_teams" json:"team"`
Prediction *Prediction `gorm:"many2many:subscription_predict" json:"prediction"`
gorm.Model `json:"-"`
}

Expand Down
1 change: 1 addition & 0 deletions internal/domain/entity/subscription_follow_league.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ type SubscriptionFollowLeague struct {
LeagueID int64 `json:"league_id"`
League *League `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"league,omitempty"`
LimitPerDay int `json:"limit_by_day"`
IsActive bool `gorm:"type:boolean;column:is_active" json:"is_active,omitempty"`
gorm.Model `json:"-"`
}
1 change: 1 addition & 0 deletions internal/domain/entity/subscription_follow_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ type SubscriptionFollowTeam struct {
TeamID int64 `json:"team_id"`
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"team,omitempty"`
LimitPerDay int `json:"limit_by_day"`
IsActive bool `gorm:"type:boolean;column:is_active" json:"is_active,omitempty"`
gorm.Model `json:"-"`
}
Loading

0 comments on commit b6b6baa

Please sign in to comment.