Skip to content

Commit

Permalink
add new service
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Oct 11, 2024
1 parent 3b1a059 commit f0e893e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 39 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const (
SMS_FOLLOW_COMPETITION_ALREADY_SUB string = "FOLLOW_COMPETITION_ALREADY_SUB"
SMS_FOLLOW_COMPETITION_UNVALID_SUB string = "FOLLOW_COMPETITION_UNVALID_SUB"
SMS_FOLLOW_COMPETITION_EXPIRE_SUB string = "FOLLOW_COMPETITION_EXPIRE_SUB"
SMS_FOLLOW_UNVALID_SUB string = "FOLLOW_UNVALID_SUB"
SMS_INFO string = "INFO"
SMS_STOP string = "STOP"
)
Expand Down
12 changes: 9 additions & 3 deletions cmd/seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func seederDB(db *gorm.DB) {
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_FOLLOW_COMPETITION_UNVALID_SUB,
Value: "SMS Alerte: Desole, mais votre choix n est pas valide. Renvoyez au {sc} la competition que vous voulez suivre en direct. {price}{currency}/SMS",
Value: "SMS Alerte: Desole, mais votre choix n est pas valide. Renvoyez au 37405 la competition que vous voulez suivre en direct. {price}{currency}/SMS",
},
{
Category: ACT_NOTIFICATION,
Expand Down Expand Up @@ -404,17 +404,23 @@ func seederDB(db *gorm.DB) {
Name: SMS_PREDICT_MATCH_END_LOSER_NOTIF,
Value: "Prono: Desole! Votre pronostic n a pas ete le bon pour le match {home}-{away}. Retentez votre chance pour les prochains matchs .Bonne chance!",
},
{
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_FOLLOW_UNVALID_SUB,
Value: "Alerte SMS : Désolé, votre sélection n'est pas valide. Soumettez votre compétition ou le nom de votre équipe à {sc} pour obtenir toutes les informations. {price}{currency}/souscription",
},
{
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_INFO,
Value: "Info Services FFC: [#157#] USSD /[981] SMS Alerte Equipe /[9009] - SMS Alerte Competition /[###] SMS Alerte a la demande /[944]",
Value: "Info Services FFC: [#101#36#] USSD /SMS Alerte Equipe /SMS Alerte Competition",
},
{
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_STOP,
Value: "Services FFC: Vous venez d envoyer STOP. Orange vous remercie d avoir utiliser nos services! Visitez www.orange.cm pour en savoir plus sur Football Fan Club",
Value: "Services FFC: Vous venez d envoyer STOP. Orange vous remercie d avoir utiliser nos services! Visitez www.orangemali.com pour en savoir plus sur Football Fan Club",
},
}

Expand Down
31 changes: 15 additions & 16 deletions internal/domain/entity/transaction.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package entity

import (
"time"
"gorm.io/gorm"
)

type Transaction struct {
ID int64 `gorm:"primaryKey" json:"id"`
TrxId string `gorm:"size:100" json:"trx_id,omitempty"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
Keyword string `gorm:"size:50" json:"keyword,omitempty"`
Amount float64 `gorm:"default:0" json:"amount,omitempty"`
Status string `gorm:"size:25" json:"status,omitempty"`
StatusCode string `gorm:"size:85" json:"status_code,omitempty"`
StatusDetail string `gorm:"size:85" json:"status_detail,omitempty"`
Subject string `gorm:"size:25" json:"subject,omitempty"`
IpAddress string `gorm:"size:30" json:"ip_address,omitempty"`
Payload string `gorm:"type:text" json:"payload,omitempty"`
CreatedAt time.Time `gorm:"type:TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"type:TIMESTAMP;null;default:null" json:"updated_at"`
ID int64 `gorm:"primaryKey" json:"id"`
TrxId string `gorm:"size:100" json:"trx_id,omitempty"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
Keyword string `gorm:"size:50" json:"keyword,omitempty"`
Amount float64 `gorm:"default:0" json:"amount,omitempty"`
Status string `gorm:"size:25" json:"status,omitempty"`
StatusCode string `gorm:"size:85" json:"status_code,omitempty"`
StatusDetail string `gorm:"size:85" json:"status_detail,omitempty"`
Subject string `gorm:"size:25" json:"subject,omitempty"`
IpAddress string `gorm:"size:30" json:"ip_address,omitempty"`
Payload string `gorm:"type:text" json:"payload,omitempty"`
gorm.Model `json:"-`
}

func (e *Transaction) GetId() int64 {
Expand Down
14 changes: 13 additions & 1 deletion internal/domain/model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ func (m *MORequest) IsInfo() bool {
}

func (m *MORequest) IsStop() bool {
return m.GetSMS() == "STOP"
return strings.Contains(m.GetSMS(), "STOP")
}

func (m *MORequest) IsStopAlive() bool {
return strings.Contains(m.GetSMS(), "STOP ALIVE")
}

func (m *MORequest) IsStopFlashNews() bool {
return strings.Contains(m.GetSMS(), "STOP FLASH")
}

func (m *MORequest) IsStopAlerte() bool {
return strings.Contains(m.GetSMS(), "STOP ALERTE")
}

func (m *MORequest) IsCreditGoal(s *entity.Service) bool {
Expand Down
2 changes: 0 additions & 2 deletions internal/handler/prediction_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"encoding/json"
"log"
"time"

"github.com/gofiber/fiber/v2"
"github.com/idprm/go-football-alert/internal/domain/entity"
Expand Down Expand Up @@ -82,7 +81,6 @@ func (h *PredictionHandler) Prediction() {
StatusDetail: "",
Subject: SUBJECT_PREDICTION,
Payload: "-",
CreatedAt: time.Now(),
},
)

Expand Down
2 changes: 0 additions & 2 deletions internal/handler/renewal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (h *RenewalHandler) Dailypush() {
StatusDetail: respDeduct.GetFaultString(),
Subject: SUBJECT_RENEWAL,
Payload: string(resp),
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -140,7 +139,6 @@ func (h *RenewalHandler) Dailypush() {
StatusDetail: "",
Subject: SUBJECT_RENEWAL,
Payload: string(resp),
CreatedAt: time.Now(),
},
)

Expand Down
2 changes: 0 additions & 2 deletions internal/handler/retry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (h *RetryHandler) Firstpush() {
StatusDetail: "",
Subject: SUBJECT_FIRSTPUSH,
Payload: string(resp),
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -202,7 +201,6 @@ func (h *RetryHandler) Dailypush() {
StatusDetail: "",
Subject: SUBJECT_RENEWAL,
Payload: string(resp),
CreatedAt: time.Now(),
},
)

Expand Down
2 changes: 0 additions & 2 deletions internal/handler/sms_alerte_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"encoding/json"
"log"
"time"

"github.com/idprm/go-football-alert/internal/domain/entity"
"github.com/idprm/go-football-alert/internal/domain/model"
Expand Down Expand Up @@ -81,7 +80,6 @@ func (h *SMSAlerteHandler) SMSAlerte() {
StatusDetail: "",
Subject: SUBJECT_NEWS,
Payload: "-",
CreatedAt: time.Now(),
},
)

Expand Down
56 changes: 45 additions & 11 deletions internal/handler/sms_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const (
SMS_FOLLOW_COMPETITION_ALREADY_SUB string = "FOLLOW_COMPETITION_ALREADY_SUB"
SMS_FOLLOW_COMPETITION_UNVALID_SUB string = "FOLLOW_COMPETITION_UNVALID_SUB"
SMS_FOLLOW_COMPETITION_EXPIRE_SUB string = "FOLLOW_COMPETITION_EXPIRE_SUB"
SMS_FOLLOW_UNVALID_SUB string = "FOLLOW_UNVALID_SUB"
SMS_CONFIRMATION string = "CONFIRMATION"
SMS_INFO string = "INFO"
SMS_STOP string = "STOP"
Expand Down Expand Up @@ -153,11 +154,26 @@ func (h *SMSHandler) SMSAlerte() {
} else if h.req.IsInfo() {
h.Info()
} else if h.req.IsStop() {
if h.IsActiveSubByCategory(CATEGORY_SMSALERTE) {
h.Stop()
if h.req.IsStopAlerte() {
if h.IsActiveSubByCategory(CATEGORY_SMSALERTE) {
h.Stop(CATEGORY_SMSALERTE)
}
}

if h.req.IsStopAlive() {
if h.IsActiveSubByCategory(CATEGORY_LIVEMATCH) {
h.Stop(CATEGORY_LIVEMATCH)
}
}

if h.req.IsStopFlashNews() {
if h.IsActiveSubByCategory(CATEGORY_FLASHNEWS) {
h.Stop(CATEGORY_FLASHNEWS)
}
}

} else {
h.Unvalid(SMS_FOLLOW_COMPETITION_UNVALID_SUB)
h.Unvalid(SMS_FOLLOW_UNVALID_SUB)
}

}
Expand All @@ -170,7 +186,7 @@ func (h *SMSHandler) SubAlerteCompetition(category string, league *entity.League
log.Println(err.Error())
}

content, err := h.getContent(SMS_FOLLOW_COMPETITION_SUB)
content, err := h.getContentFollowCompetition(SMS_FOLLOW_COMPETITION_SUB, service, league)
if err != nil {
log.Println(err)
}
Expand Down Expand Up @@ -239,7 +255,6 @@ func (h *SMSHandler) SubAlerteCompetition(category string, league *entity.League
StatusDetail: "",
Subject: SUBJECT_FREEPUSH,
Payload: "-",
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -343,7 +358,6 @@ func (h *SMSHandler) SubAlerteCompetition(category string, league *entity.League
StatusDetail: "",
Subject: SUBJECT_FIRSTPUSH,
Payload: string(deductFee),
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -470,7 +484,6 @@ func (h *SMSHandler) SubAlerteEquipe(category string, team *entity.Team) {
StatusDetail: "",
Subject: SUBJECT_FREEPUSH,
Payload: "-",
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -574,7 +587,6 @@ func (h *SMSHandler) SubAlerteEquipe(category string, team *entity.Team) {
StatusDetail: "",
Subject: SUBJECT_FIRSTPUSH,
Payload: string(deductFee),
CreatedAt: time.Now(),
},
)

Expand Down Expand Up @@ -740,10 +752,10 @@ func (h *SMSHandler) Info() {
)
}

func (h *SMSHandler) Stop() {
func (h *SMSHandler) Stop(category string) {
trxId := utils.GenerateTrxId()

sub, err := h.subscriptionService.GetByCategory(CATEGORY_SMSALERTE, h.req.GetMsisdn())
sub, err := h.subscriptionService.GetByCategory(category, h.req.GetMsisdn())
if err != nil {
log.Println(err.Error())
}
Expand All @@ -758,6 +770,29 @@ func (h *SMSHandler) Stop() {
log.Println(err.Error())
}

h.subscriptionService.Update(
&entity.Subscription{
ServiceID: sub.ServiceID,
Msisdn: sub.Msisdn,
Channel: CHANNEL_SMS,
LatestTrxId: trxId,
LatestKeyword: h.req.GetSMS(),
LatestSubject: SUBJECT_UNSUB,
UnsubAt: time.Now(),
TotalUnsub: sub.TotalUnsub + 1,
},
)

h.transactionService.Save(
&entity.Transaction{
ServiceID: sub.ServiceID,
Msisdn: sub.Msisdn,
Keyword: h.req.GetSMS(),
Amount: 0,
Subject: SUBJECT_UNSUB,
},
)

mt := &model.MTRequest{
Smsc: h.req.GetTo(),
Keyword: h.req.GetSMS(),
Expand Down Expand Up @@ -882,7 +917,6 @@ func (h *SMSHandler) Unsub() {
Subject: SUBJECT_UNSUB,
IpAddress: h.req.GetIpAddress(),
Payload: "",
CreatedAt: time.Now(),
},
)

Expand Down

0 comments on commit f0e893e

Please sign in to comment.