Skip to content

Commit

Permalink
extend notifications response
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Dec 4, 2024
1 parent 4ac7451 commit aebe143
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion controller/notification_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func sendNotificationForMeeting(c *gin.Context) {
return
}

users, notificationUsers, err := service.SendPushNotificationForMeeting(meeting, request.Title, request.Subtitle, request.Message)
users, notificationUsers, success, err := service.SendPushNotificationForMeeting(meeting, request.Title, request.Subtitle, request.Message)
if err != nil {
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
Expand All @@ -87,6 +87,7 @@ func sendNotificationForMeeting(c *gin.Context) {
c.IndentedJSON(http.StatusOK, dto.NotificationsResponseDto{
UserCount: users,
NotificationUserCount: notificationUsers,
SuccessCount: success,
})
}

Expand Down
1 change: 1 addition & 0 deletions dto/notification_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type NotificationResponseDto struct {
type NotificationsResponseDto struct {
UserCount int `json:"user_count"`
NotificationUserCount int `json:"notification_user_count"`
SuccessCount int `json:"success_count"`
}
10 changes: 5 additions & 5 deletions service/notification_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func SendTestPushNotification(receiver string) error {
return nil
}

func SendPushNotificationForMeeting(meeting string, title string, subtitle string, message string) (int, int, error) {
func SendPushNotificationForMeeting(meeting string, title string, subtitle string, message string) (int, int, int, error) {
athletes, err := ac.GetAthletesByMeeting(meeting)
if err != nil {
return 0, 0, err
return 0, 0, 0, err
}

var athleteIds []primitive.ObjectID
Expand All @@ -76,7 +76,7 @@ func SendPushNotificationForMeeting(meeting string, title string, subtitle strin

users, err := GetUsersByIsFollowerOrMe(athleteIds)
if err != nil {
return 0, 0, err
return 0, 0, 0, err
}

var userIds []primitive.ObjectID
Expand All @@ -86,7 +86,7 @@ func SendPushNotificationForMeeting(meeting string, title string, subtitle strin

notificationUsers, err := GetNotificationUsersByUserIds(userIds)
if err != nil {
return 0, 0, err
return 0, 0, 0, err
}

var wg sync.WaitGroup
Expand All @@ -106,7 +106,7 @@ func SendPushNotificationForMeeting(meeting string, title string, subtitle strin
wg.Wait() // Wait for all goroutines to finish

fmt.Printf("notified %d users with %d/%d devices", len(users), success, len(notificationUsers))
return len(users), success, nil
return len(users), len(notificationUsers), success, nil
}

func SendPushNotification(receiver string, title string, subtitle string, message string) (string, string, int, error) {
Expand Down

0 comments on commit aebe143

Please sign in to comment.