- Migration 017: tabelas notifications e fcm_tokens
- Models: Notification, FCMToken
- NotificationService: CRUD, push notifications helper
- FCMService: Firebase Cloud Messaging integration
- NotificationHandler: endpoints REST
- Rotas autenticadas: /api/v1/notifications/*
Endpoints:
- GET /api/v1/notifications
- GET /api/v1/notifications/unread-count
- PUT /api/v1/notifications/read-all
- PUT /api/v1/notifications/{id}/read
- DELETE /api/v1/notifications/{id}
- POST /api/v1/notifications/fcm-token
- DELETE /api/v1/notifications/fcm-token
59 lines
2.5 KiB
Go
59 lines
2.5 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// Notification represents an in-app notification
|
|
type Notification struct {
|
|
ID int `json:"id" db:"id"`
|
|
UserID int `json:"userId" db:"user_id"`
|
|
TenantID *string `json:"tenantId,omitempty" db:"tenant_id"`
|
|
Title string `json:"title" db:"title"`
|
|
Message string `json:"message" db:"message"`
|
|
Type string `json:"type" db:"type"` // info, success, warning, error, application, job, message
|
|
ActionURL *string `json:"actionUrl,omitempty" db:"action_url"`
|
|
ActionLabel *string `json:"actionLabel,omitempty" db:"action_label"`
|
|
Read bool `json:"read" db:"read"`
|
|
ReadAt *time.Time `json:"readAt,omitempty" db:"read_at"`
|
|
PushSent bool `json:"pushSent" db:"push_sent"`
|
|
PushSentAt *time.Time `json:"pushSentAt,omitempty" db:"push_sent_at"`
|
|
Metadata []byte `json:"metadata,omitempty" db:"metadata"`
|
|
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
|
}
|
|
|
|
// FCMToken represents a Firebase Cloud Messaging device token
|
|
type FCMToken struct {
|
|
ID int `json:"id" db:"id"`
|
|
UserID int `json:"userId" db:"user_id"`
|
|
Token string `json:"token" db:"token"`
|
|
DeviceType *string `json:"deviceType,omitempty" db:"device_type"` // web, android, ios
|
|
DeviceName *string `json:"deviceName,omitempty" db:"device_name"`
|
|
Active bool `json:"active" db:"active"`
|
|
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
|
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
|
}
|
|
|
|
// CreateNotificationRequest for creating a notification
|
|
type CreateNotificationRequest struct {
|
|
UserID int `json:"userId"`
|
|
Title string `json:"title"`
|
|
Message string `json:"message"`
|
|
Type string `json:"type"`
|
|
ActionURL *string `json:"actionUrl,omitempty"`
|
|
ActionLabel *string `json:"actionLabel,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
SendPush bool `json:"sendPush"`
|
|
}
|
|
|
|
// RegisterFCMTokenRequest for registering a device token
|
|
type RegisterFCMTokenRequest struct {
|
|
Token string `json:"token"`
|
|
DeviceType *string `json:"deviceType,omitempty"`
|
|
DeviceName *string `json:"deviceName,omitempty"`
|
|
}
|
|
|
|
// NotificationStats for dashboard
|
|
type NotificationStats struct {
|
|
Total int `json:"total"`
|
|
Unread int `json:"unread"`
|
|
ByType map[string]int `json:"byType"`
|
|
}
|