Skip to content

Commit

Permalink
add send notification for meeting and athlete to client
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Dec 6, 2024
1 parent a31d0b8 commit 11a9e6e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions client/notification_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/swimresults/service-core/client"
"github.com/swimresults/user-service/dto"
"go.mongodb.org/mongo-driver/bson/primitive"
"net/http"
)

Expand Down Expand Up @@ -44,6 +45,35 @@ func (c *NotificationClient) SendNotification(key string, meeting string, title
return responseDto, nil
}

func (c *NotificationClient) SendNotificationForMeetingAndAthlete(key string, meeting string, athleteId primitive.ObjectID, subtitle string, message string, messageType string, interruptionLevel string) (*dto.NotificationResponseDto, error) {
request := dto.MeetingNotificationRequestDto{
Subtitle: subtitle,
Message: message,
MessageType: messageType,
InterruptionLevel: interruptionLevel,
}

header := http.Header{}
header.Set("X-SWIMRESULTS-SERVICE", key)

res, err := client.Post(c.apiUrl, "/notification/meet/"+meeting+"/athlete/"+athleteId.Hex(), request, &header)
if err != nil {
return nil, err
}
defer res.Body.Close()

responseDto := &dto.NotificationResponseDto{}
err = json.NewDecoder(res.Body).Decode(responseDto)
if err != nil {
return nil, err
}

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("notification request for meeting and athlete returned: %d", res.StatusCode)
}
return responseDto, nil
}

func (c *NotificationClient) SendMeetingBroadcastNotification(key string, meeting string, body interface{}) (*dto.BroadcastResponseDto, error) {
fmt.Printf("sending meeting broadcast request to: '%s'\n", "notification/broadcast/meeting/"+meeting)

Expand Down

0 comments on commit 11a9e6e

Please sign in to comment.