@@ -5,12 +5,13 @@ import (
55 "errors"
66 "fmt"
77
8- "github.com/hollow-cube/api-server/internal/pkg/model"
98 "github.com/hollow-cube/api-server/internal/pkg/notification"
9+ "github.com/hollow-cube/api-server/internal/playerdb"
1010)
1111
12+ // v4
1213func (s * Server ) DeletePlayerNotification (ctx context.Context , request DeletePlayerNotificationRequestObject ) (DeletePlayerNotificationResponseObject , error ) {
13- if err := s .notificationManager . DeleteNotification (ctx , request .NotificationId , request . PlayerId ); err != nil {
14+ if err := s .notifications . Delete (ctx , request .NotificationId ); err != nil {
1415 if errors .Is (err , notification .ErrNotFound ) {
1516 return DeletePlayerNotification404Response {}, nil
1617 }
@@ -19,6 +20,7 @@ func (s *Server) DeletePlayerNotification(ctx context.Context, request DeletePla
1920 return DeletePlayerNotification200Response {}, nil
2021}
2122
23+ // v4
2224func (s * Server ) GetPlayerNotifications (ctx context.Context , request GetPlayerNotificationsRequestObject ) (GetPlayerNotificationsResponseObject , error ) {
2325 var unreadOnly = request .Params .Unread != nil && * request .Params .Unread
2426
@@ -30,26 +32,29 @@ func (s *Server) GetPlayerNotifications(ctx context.Context, request GetPlayerNo
3032 return GetPlayerNotifications400JSONResponse {Message : "page must be non-negative" }, nil
3133 }
3234
33- result , err := s .notificationManager .GetNotifications (ctx , request .PlayerId , page , unreadOnly )
35+ offset := int32 (page * 21 )
36+ limit := int32 (21 )
37+
38+ result , count , err := s .notifications .List (ctx , request .PlayerId , unreadOnly , offset , limit )
3439 if err != nil {
3540 return nil , err
3641 }
3742
38- results := make ([]PlayerNotification , len (result . Results ))
39- for i , notif := range result . Results {
43+ results := make ([]PlayerNotification , len (result ))
44+ for i , notif := range result {
4045 results [i ] = notificationToApi (notif )
4146 }
4247
4348 return GetPlayerNotifications200JSONResponse {
44- Page : result . Page ,
45- PageCount : result . PageCount ,
49+ Page : int32 ( page ) ,
50+ PageCount : int32 ( count / 21 ) + 1 ,
4651 Results : results ,
4752 }, nil
4853}
4954
50- func notificationToApi (n notification. Notification ) PlayerNotification {
55+ func notificationToApi (n playerdb. PlayerNotification ) PlayerNotification {
5156 return PlayerNotification {
52- Id : n .Id ,
57+ Id : n .ID ,
5358 Type : n .Type ,
5459 Key : n .Key ,
5560 Data : n .Data ,
@@ -59,8 +64,9 @@ func notificationToApi(n notification.Notification) PlayerNotification {
5964 }
6065}
6166
67+ // v4
6268func (s * Server ) UpdatePlayerNotification (ctx context.Context , request UpdatePlayerNotificationRequestObject ) (UpdatePlayerNotificationResponseObject , error ) {
63- if err := s .notificationManager . UpdateNotification (ctx , request .NotificationId , request . PlayerId , request .Body .Read ); err != nil {
69+ if err := s .notifications . SetReadState (ctx , request .NotificationId , request .Body .Read ); err != nil {
6470 if errors .Is (err , notification .ErrNotFound ) {
6571 return UpdatePlayerNotification404Response {}, nil
6672 }
@@ -69,6 +75,7 @@ func (s *Server) UpdatePlayerNotification(ctx context.Context, request UpdatePla
6975 return UpdatePlayerNotification200Response {}, nil
7076}
7177
78+ // v4 removed
7279func (s * Server ) CreatePlayerNotification (ctx context.Context , request CreatePlayerNotificationRequestObject ) (CreatePlayerNotificationResponseObject , error ) {
7380 replaceUnread := false
7481 if request .Params .ReplaceUnread != nil {
@@ -79,23 +86,23 @@ func (s *Server) CreatePlayerNotification(ctx context.Context, request CreatePla
7986 Key : request .Body .Key ,
8087 Type : request .Body .Type ,
8188 ExpiresIn : request .Body .ExpiresIn ,
82- Data : request .Body .Data ,
89+ Data : * request .Body .Data ,
8390 ReplaceUnread : replaceUnread ,
8491 }
85- if err := s .notificationManager .Create (ctx , request .PlayerId , input ); err != nil {
92+ if err := s .notifications .Create (ctx , request .PlayerId , input ); err != nil {
8693 return nil , err
8794 }
8895
8996 return CreatePlayerNotification201Response {}, nil
9097}
9198
9299func (s * Server ) sendNotificationMessage (ctx context.Context , request CreatePlayerNotificationRequestObject ) error {
93- msg := model. NotificationUpdateMessage {
94- Action : model . NotificationCreateAction ,
100+ msg := notification. UpdateMessage {
101+ Action : notification . CreateAction ,
95102 PlayerId : request .PlayerId ,
96103 Type : request .Body .Type ,
97104 Key : request .Body .Key ,
98- Data : request .Body .Data ,
105+ Data : * request .Body .Data ,
99106 }
100107 if err := s .jetStream .PublishJSONAsync (ctx , msg ); err != nil {
101108 return fmt .Errorf ("failed to publish notification message: %w" , err )
0 commit comments