| 1 | package personapi |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/kernel" |
| 5 | "context" |
| 6 | "errors" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | var ErrSubscriptionExpired = errors.New("notifications.subscription_expired") |
| 11 | |
| 12 | type Notification struct { |
| 13 | ID string `json:"id"` |
| 14 | Kind string `json:"kind"` |
| 15 | ResourceID string `json:"resource_id"` |
| 16 | DeepLink string `json:"deep_link"` |
| 17 | ResourceRevision int64 `json:"resource_revision"` |
| 18 | CreatedAt time.Time `json:"created_at"` |
| 19 | State string `json:"state"` |
| 20 | } |
| 21 | type NotificationSubscription struct { |
| 22 | ID string `json:"id"` |
| 23 | DeviceID string `json:"device_id"` |
| 24 | Cursor string `json:"cursor"` |
| 25 | Revision int64 `json:"revision"` |
| 26 | Active bool `json:"active"` |
| 27 | ExpiresAt time.Time `json:"expires_at"` |
| 28 | } |
| 29 | type SubscribeNotificationsInput struct { |
| 30 | DeviceID string `json:"device_id"` |
| 31 | } |
| 32 | type AcknowledgeNotificationInput struct { |
| 33 | NotificationID string `json:"notification_id"` |
| 34 | } |
| 35 | type NotificationOperations interface { |
| 36 | Notifications(context.Context, kernel.Actor, string, int) (Page[Notification], error) |
| 37 | SubscribeNotifications(context.Context, kernel.Actor, string, kernel.Mutation) (NotificationSubscription, error) |
| 38 | AcknowledgeNotification(context.Context, kernel.Actor, string, string, kernel.Mutation) error |
| 39 | UnsubscribeNotifications(context.Context, kernel.Actor, string, kernel.Mutation) error |
| 40 | NotificationSubscription(context.Context, kernel.Actor, string) (NotificationSubscription, error) |
| 41 | } |
| 42 | |
| 43 | func init() { |
| 44 | Routes = append(Routes, |
| 45 | Route{"GET", "/notifications", "notifications", false, nil}, |
| 46 | Route{"POST", "/notification-subscriptions", "subscribe_notifications", false, func() any { return &SubscribeNotificationsInput{} }}, |
| 47 | Route{"DELETE", "/notification-subscriptions/{id}", "unsubscribe_notifications", true, func() any { return &struct{}{} }}, |
| 48 | Route{"POST", "/notification-subscriptions/{id}/ack", "ack_notification", true, func() any { return &AcknowledgeNotificationInput{} }}) |
| 49 | } |
| 50 | |