/ internal / gtsclient / notifications.go
notifications.go
 1  package gtsclient
 2  
 3  import (
 4  	"fmt"
 5  	"net/http"
 6  
 7  	"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
 8  )
 9  
10  const baseNotificationsPath string = "/api/v1/notifications"
11  
12  func (g *GTSClient) GetNotification(notificationID string, notification *model.Notification) error {
13  	params := requestParameters{
14  		httpMethod:  http.MethodGet,
15  		url:         g.authentication.Instance + baseNotificationsPath + "/" + notificationID,
16  		requestBody: nil,
17  		contentType: "",
18  		output:      notification,
19  	}
20  
21  	if err := g.sendRequest(params); err != nil {
22  		return fmt.Errorf(
23  			"received an error after sending the request to get the notification: %w",
24  			err,
25  		)
26  	}
27  
28  	return nil
29  }
30  
31  type GetNotificationListArgs struct {
32  	Limit        int
33  	IncludeTypes []string
34  	ExcludeTypes []string
35  }
36  
37  func (g *GTSClient) GetNotificationList(args GetNotificationListArgs, notifications *[]model.Notification) error {
38  	query := fmt.Sprintf("?limit=%d", args.Limit)
39  
40  	for _, include := range args.IncludeTypes {
41  		query = query + "&types[]=" + include
42  	}
43  
44  	for _, exclude := range args.ExcludeTypes {
45  		query = query + "&exclude_types[]=" + exclude
46  	}
47  
48  	params := requestParameters{
49  		httpMethod:  http.MethodGet,
50  		url:         g.authentication.Instance + baseNotificationsPath + query,
51  		requestBody: nil,
52  		contentType: "",
53  		output:      &notifications,
54  	}
55  
56  	if err := g.sendRequest(params); err != nil {
57  		return fmt.Errorf(
58  			"received an error after sending the request to get the list of notifications: %w",
59  			err,
60  		)
61  	}
62  
63  	return nil
64  }
65  
66  func (g *GTSClient) DeleteNotifications(_ NoRPCArgs, _ *NoRPCResults) error {
67  	params := requestParameters{
68  		httpMethod:  http.MethodPost,
69  		url:         g.authentication.Instance + baseNotificationsPath + "/clear",
70  		requestBody: nil,
71  		contentType: "",
72  		output:      nil,
73  	}
74  
75  	if err := g.sendRequest(params); err != nil {
76  		return fmt.Errorf(
77  			"received an error after sending the request to delete the notifications: %w",
78  			err,
79  		)
80  	}
81  
82  	return nil
83  }