Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Oct 8, 2024
1 parent af388ee commit 3dc57df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions internal/domain/repository/subscription_respository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ISubscriptionRepository interface {
CountActive(int, string) (int64, error)
CountActiveByCategory(string, string) (int64, error)
GetAllPaginate(*entity.Pagination) (*entity.Pagination, error)
GetByCategory(string, string) (*entity.Subscription, error)
Get(int, string) (*entity.Subscription, error)
Save(*entity.Subscription) (*entity.Subscription, error)
Update(*entity.Subscription) (*entity.Subscription, error)
Expand Down Expand Up @@ -77,6 +78,15 @@ func (r *SubscriptionRepository) GetAllPaginate(pagination *entity.Pagination) (
return pagination, nil
}

func (r *SubscriptionRepository) GetByCategory(category, msisdn string) (*entity.Subscription, error) {
var c entity.Subscription
err := r.db.Where("category = ?", category).Where("msisdn = ?", msisdn).Take(&c).Error
if err != nil {
return nil, err
}
return &c, nil
}

func (r *SubscriptionRepository) Get(serviceId int, msisdn string) (*entity.Subscription, error) {
var c entity.Subscription
err := r.db.Where("service_id = ?", serviceId).Where("msisdn = ?", msisdn).Take(&c).Error
Expand Down
22 changes: 14 additions & 8 deletions internal/handler/sms_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,19 @@ func (h *SMSHandler) Registration() {
h.SMSAlerte()
}

func (h *SMSHandler) Confirmation(v string) {

}

func (h *SMSHandler) SMSAlerte() {
// user choose 1, 2, 3 package
if h.leagueService.IsLeagueByName(h.req.GetSMS()) {
if !h.IsActiveSubByCategory(CATEGORY_SMSALERTE) {
h.Confirmation(SUBCATEGORY_FOLLOW_COMPETITION)
h.Subscription(SUBCATEGORY_FOLLOW_COMPETITION)
} else {
// SMS-Alerte Competition
h.AlerteCompetition()
// SMS-Alerte Matchs
}
} else if h.teamService.IsTeamByName(h.req.GetSMS()) {
if !h.IsActiveSubByCategory(CATEGORY_SMSALERTE) {
h.Confirmation(SUBCATEGORY_FOLLOW_TEAM)
h.Subscription(SUBCATEGORY_FOLLOW_TEAM)
} else {
// SMS-Alerte Equipe
h.AlerteEquipe()
Expand Down Expand Up @@ -454,15 +450,25 @@ func (h *SMSHandler) Info() {
func (h *SMSHandler) Stop() {
trxId := utils.GenerateTrxId()

sub, err := h.subscriptionService.GetByCategory(CATEGORY_SMSALERTE, h.req.GetMsisdn())
if err != nil {
log.Println(err.Error())
}

service, err := h.serviceService.GetById(sub.GetServiceId())
if err != nil {
log.Println(err.Error())
}

content, err := h.getContent(SMS_STOP)
if err != nil {
log.Println(err.Error())
}

mt := &model.MTRequest{
Smsc: h.req.GetTo(),
Service: &entity.Service{},
Subscription: &entity.Subscription{Msisdn: h.req.GetMsisdn()},
Service: service,
Subscription: sub,
Content: content,
}
mt.SetTrxId(trxId)
Expand Down
5 changes: 5 additions & 0 deletions internal/services/subscription_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ISubscriptionService interface {
IsActiveSubscription(int, string) bool
IsActiveSubscriptionByCategory(string, string) bool
GetAllPaginate(*entity.Pagination) (*entity.Pagination, error)
GetByCategory(string, string) (*entity.Subscription, error)
Get(int, string) (*entity.Subscription, error)
Save(*entity.Subscription) (*entity.Subscription, error)
Update(*entity.Subscription) (*entity.Subscription, error)
Expand Down Expand Up @@ -60,6 +61,10 @@ func (s *SubscriptionService) GetAllPaginate(pagination *entity.Pagination) (*en
return s.subscriptionRepo.GetAllPaginate(pagination)
}

func (s *SubscriptionService) GetByCategory(category, msisdn string) (*entity.Subscription, error) {
return s.subscriptionRepo.GetByCategory(category, msisdn)
}

func (s *SubscriptionService) Get(serviceId int, msisdn string) (*entity.Subscription, error) {
return s.subscriptionRepo.Get(serviceId, msisdn)
}
Expand Down

0 comments on commit 3dc57df

Please sign in to comment.