oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package personapi
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/kernel"
5 "context"
6 "errors"
7 "time"
8)
9
10var ErrSubscriptionExpired = errors.New("notifications.subscription_expired")
11
12type 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}
21type 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}
29type SubscribeNotificationsInput struct {
30 DeviceID string `json:"device_id"`
31}
32type AcknowledgeNotificationInput struct {
33 NotificationID string `json:"notification_id"`
34}
35type 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
43func 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