-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from SwimResults/develop
Develop
- Loading branch information
Showing
17 changed files
with
644 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/swimresults/service-core/client" | ||
"github.com/swimresults/user-service/dto" | ||
"net/http" | ||
) | ||
|
||
type NotificationClient struct { | ||
apiUrl string | ||
} | ||
|
||
func NewNotificationClient(url string) *NotificationClient { | ||
return &NotificationClient{apiUrl: url} | ||
} | ||
|
||
func (c *NotificationClient) SendNotification(key string, meeting string, title string, subtitle string, message string) (*dto.NotificationResponseDto, error) { | ||
request := dto.NotificationRequestDto{ | ||
Title: title, | ||
Subtitle: subtitle, | ||
Message: message, | ||
} | ||
|
||
header := http.Header{} | ||
header.Set("X-SWIMRESULTS-SERVICE", key) | ||
|
||
res, err := client.Post(c.apiUrl, "notification/import", 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 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) | ||
|
||
header := http.Header{} | ||
header.Set("X-SWIMRESULTS-SERVICE", key) | ||
|
||
res, err := client.Post(c.apiUrl, "notification/broadcast/meeting/"+meeting, body, &header) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
responseDto := &dto.BroadcastResponseDto{} | ||
err = json.NewDecoder(res.Body).Decode(responseDto) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("meeting broadcast request returned: %d", res.StatusCode) | ||
} | ||
return responseDto, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package client | ||
|
||
// | ||
//import ( | ||
// "fmt" | ||
// "testing" | ||
//) | ||
// | ||
//func TestNotificationClient_SendMeetingBroadcastNotification(t *testing.T) { | ||
// client := NewNotificationClient("http://localhost:8090/") | ||
// | ||
// r, e := client.SendMeetingBroadcastNotification("12345678", "IESC", `"test": {}`) | ||
// if e != nil { | ||
// fmt.Printf(e.Error()) | ||
// } | ||
// fmt.Println(r) | ||
// //fmt.Printf("id: %s, number: %d, start: %s", r.Identifier.String(), r.Number, r.StartEstimation.Format("15:04")) | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.