Skip to content

Commit

Permalink
add new remove character in news
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Oct 20, 2024
1 parent 1554bd2 commit 2daf906
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
image: idprm/fb-alert-ussd-service
- dockerfile: ./Dockerfile.sms
image: idprm/fb-alert-sms-service
- dockerfile: ./Dockerfile.wap
image: idprm/fb-alert-wap-service
- dockerfile: ./Dockerfile.news
image: idprm/fb-alert-news-service
- dockerfile: ./Dockerfile.sms_alerte
Expand Down
3 changes: 3 additions & 0 deletions cmd/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log
smsAlerteService := services.NewSMSAlerteService(smsAlerteRepo)

h := handler.NewIncomingHandler(
rds,
rmq,
logger,
menuService,
Expand Down Expand Up @@ -264,6 +265,8 @@ func routeUrlListener(db *gorm.DB, rds *redis.Client, rmq rmqp.AMQP, logger *log
)

r.Get("/mo", h.MessageOriginated)
r.Post("/sub", h.CreateSub)
r.Post("/otp", h.VerifySub)

lp := r.Group("p")
lp.Get("/:service", h.LandingPage)
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const (
SMS_FLASH_NEWS_SUB string = "FLASH_NEWS_SUB"
SMS_INFO string = "INFO"
SMS_STOP string = "STOP"
SMS_OTP string = "OTP"
)

var (
Expand Down
6 changes: 6 additions & 0 deletions cmd/seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ func seederDB(db *gorm.DB) {
Name: SMS_STOP,
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",
},
{
Category: ACT_CONFIRMATION,
Channel: ACT_SMS,
Name: SMS_OTP,
Value: "Votre code OTP est {pin}. Services FFC",
},
}

var schedules = []entity.Schedule{
Expand Down
5 changes: 5 additions & 0 deletions internal/domain/entity/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ func (e *Content) SetValueCreditGoal(home, away, score, credit, price, currency
"{currency}", url.QueryEscape(currency))
e.Value = replacer.Replace(e.Value)
}

func (e *Content) SetValueOTP(pin string) {
replacer := strings.NewReplacer("{pin}", pin)
e.Value = replacer.Replace(e.Value)
}
1 change: 1 addition & 0 deletions internal/domain/entity/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (e *News) GetId() int64 {
func (e *News) GetTitle() string {
replacer := strings.NewReplacer(
`"`, "",
`’`, "'",
)
return replacer.Replace(e.Title)
}
Expand Down
9 changes: 8 additions & 1 deletion internal/domain/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (s *Service) GetPrice() float64 {
return s.Price
}

func (s *Service) GetDiscount(discountPercentage int) float64 {
return (s.GetPrice() * float64(discountPercentage) / 100)
}

func (s *Service) GetPriceToString() string {
return strconv.FormatFloat(s.GetPrice(), 'f', 0, 64)
}
Expand Down Expand Up @@ -92,7 +96,6 @@ func (e *Service) GetUrlMT() string {
}

func (e *Service) SetUrlMT(smsc, username, password, from, to, content string) {

replacer := strings.NewReplacer(
"{smsc}", url.QueryEscape(smsc),
"{username}", url.QueryEscape(username),
Expand All @@ -103,3 +106,7 @@ func (e *Service) SetUrlMT(smsc, username, password, from, to, content string) {

e.UrlMT = replacer.Replace(e.UrlMT)
}

func (s *Service) SetPriceWithDiscount(discountPercentage int) {
s.Price = s.GetPrice() - (s.GetPrice() * float64(discountPercentage) / 100)
}
7 changes: 6 additions & 1 deletion internal/domain/entity/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type Transaction struct {
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"`
Amount float64 `gorm:"size:10;default:0" json:"amount,omitempty"`
Discount float64 `gorm:"size:10;default:0" json:"discount,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"`
Expand All @@ -37,6 +38,10 @@ func (t *Transaction) SetAmount(v float64) {
t.Amount = v
}

func (t *Transaction) SetDiscount(v float64) {
t.Discount = v
}

func (t *Transaction) SetStatus(v string) {
t.Status = v
}
Expand Down
17 changes: 16 additions & 1 deletion internal/handler/incoming_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/idprm/go-football-alert/internal/logger"
"github.com/idprm/go-football-alert/internal/services"
"github.com/idprm/go-football-alert/internal/utils"
"github.com/redis/go-redis/v9"
"github.com/sirupsen/logrus"
"github.com/wiliehidayat87/rmqp"
)
Expand Down Expand Up @@ -51,13 +52,15 @@ var (
RMQ_USSD_QUEUE string = "Q_USSD"
RMQ_SMS_EXCHANGE string = "E_SMS"
RMQ_SMS_QUEUE string = "Q_SMS"
RMQ_WAP_EXCHANGE string = "E_WAP"
RMQ_WAP_QUEUE string = "Q_WAP"
RMQ_MT_EXCHANGE string = "E_MT"
RMQ_MT_QUEUE string = "Q_MT"
RMQ_NEWS_EXCHANGE string = "E_NEWS"
RMQ_NEWS_QUEUE string = "Q_NEWS"
MT_SMS_ALERTE string = "SMS_ALERTE"
MT_CREDIT_GOAL string = "CREDIT_GOAL"
MT_PREDICTION string = "PREDICTION"
MT_PREDICT_WIN string = "PREDICT_WIN"
MT_FIRSTPUSH string = "FIRSTPUSH"
MT_RENEWAL string = "RENEWAL"
MT_NEWS string = "NEWS"
Expand All @@ -78,9 +81,11 @@ var (
ACT_NEWS string = "NEWS"
CHANNEL_USSD string = "USSD"
CHANNEL_SMS string = "SMS"
CHANNEL_WAP string = "WAP"
)

type IncomingHandler struct {
rds *redis.Client
rmq rmqp.AMQP
logger *logger.Logger
menuService services.IMenuService
Expand All @@ -100,6 +105,7 @@ type IncomingHandler struct {
}

func NewIncomingHandler(
rds *redis.Client,
rmq rmqp.AMQP,
logger *logger.Logger,
menuService services.IMenuService,
Expand All @@ -118,6 +124,7 @@ func NewIncomingHandler(
bettingService services.IBettingService,
) *IncomingHandler {
return &IncomingHandler{
rds: rds,
rmq: rmq,
logger: logger,
menuService: menuService,
Expand Down Expand Up @@ -200,6 +207,14 @@ func (h *IncomingHandler) MessageOriginated(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).SendString("OK")
}

func (h *IncomingHandler) CreateSub(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(fiber.Map{"": ""})
}

func (h *IncomingHandler) VerifySub(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(fiber.Map{"": ""})
}

func (h *IncomingHandler) Main(c *fiber.Ctx) error {
c.Set("Content-type", "text/xml; charset=utf-8")
menu, err := h.menuService.GetBySlug("home")
Expand Down
7 changes: 7 additions & 0 deletions internal/handler/renewal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (h *RenewalHandler) Dailypush() {
)
// is_retry set to false
h.subscriptionService.UpdateNotRetry(sub)
// is_free set to false
h.subscriptionService.UpdateNotFree(sub)

h.transactionService.Save(
&entity.Transaction{
Expand Down Expand Up @@ -148,6 +150,9 @@ func (h *RenewalHandler) Dailypush() {
},
)

// is_free set to false
h.subscriptionService.UpdateNotFree(sub)

h.transactionService.Save(
&entity.Transaction{
TrxId: trxId,
Expand Down Expand Up @@ -180,6 +185,8 @@ func (h *RenewalHandler) Dailypush() {
LatestPayload: string(respBal),
},
)
// is_free set to false
h.subscriptionService.UpdateNotFree(sub)

h.transactionService.Save(
&entity.Transaction{
Expand Down
10 changes: 10 additions & 0 deletions internal/handler/retry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (h *RetryHandler) Firstpush() {
if err != nil {
log.Println(err.Error())
}
// smart billing set discount based on retry
service.SetPriceWithDiscount(0)

summary := &entity.Summary{
ServiceID: service.GetId(),
Expand Down Expand Up @@ -111,6 +113,8 @@ func (h *RetryHandler) Firstpush() {

// is_retry set to false
h.subscriptionService.UpdateNotRetry(sub)
// is_free set to false
h.subscriptionService.UpdateNotFree(sub)

h.transactionService.Update(
&entity.Transaction{
Expand All @@ -119,6 +123,7 @@ func (h *RetryHandler) Firstpush() {
Msisdn: h.sub.GetMsisdn(),
Keyword: sub.GetLatestKeyword(),
Amount: service.GetPrice(),
Discount: 0,
Status: STATUS_SUCCESS,
StatusCode: respDeduct.GetAcctResCode(),
StatusDetail: respDeduct.GetAcctResName(),
Expand Down Expand Up @@ -154,6 +159,8 @@ func (h *RetryHandler) Dailypush() {
if err != nil {
log.Println(err.Error())
}
// smart billing set discount based on retry
service.SetPriceWithDiscount(0)

summary := &entity.Summary{
ServiceID: service.GetId(),
Expand Down Expand Up @@ -201,6 +208,8 @@ func (h *RetryHandler) Dailypush() {

// is_retry set to false
h.subscriptionService.UpdateNotRetry(sub)
// is_free set to false
h.subscriptionService.UpdateNotFree(sub)

h.transactionService.Update(
&entity.Transaction{
Expand All @@ -209,6 +218,7 @@ func (h *RetryHandler) Dailypush() {
Msisdn: h.sub.GetMsisdn(),
Keyword: sub.GetLatestKeyword(),
Amount: service.GetPrice(),
Discount: 0,
Status: STATUS_SUCCESS,
StatusCode: respDeduct.GetAcctResCode(),
StatusDetail: respDeduct.GetAcctResName(),
Expand Down

0 comments on commit 2daf906

Please sign in to comment.