- pluggable per-domain Repository interfaces; PostgreSQL and SQLite impls - SQLite on modernc.org/sqlite (WAL, busy_timeout, foreign_keys, immediate tx) - separate migrations/sqlite and db.MigrateSQLite; store.NewPostgres/NewSQLite - cmd/reconcile compares object storage with the journal (report, then --delete) - storage.Backend.List and photos.Repository.AllStorageKeys - DB_BACKEND/SQLITE_PATH and STORAGE_BACKEND/FS_ROOT selectable; local defaults (sqlite ./galo.db, fs ./data) - Makefile reconcile/reconcile-delete; docs and .env.example updated
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package notifications
|
|
|
|
import (
|
|
"context"
|
|
|
|
"shared-album/internal/auth"
|
|
"shared-album/internal/httpx"
|
|
"shared-album/internal/models"
|
|
"shared-album/internal/sse"
|
|
)
|
|
|
|
type Service struct {
|
|
store Repository
|
|
hub *sse.Hub
|
|
}
|
|
|
|
func NewService(store Repository, hub *sse.Hub) *Service {
|
|
return &Service{store: store, hub: hub}
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, userID, typ string, payload map[string]any) error {
|
|
n := &models.Notification{
|
|
ID: auth.NewID(),
|
|
UserID: userID,
|
|
Type: typ,
|
|
PayloadJSON: payload,
|
|
}
|
|
if err := s.store.Create(ctx, n); err != nil {
|
|
return err
|
|
}
|
|
s.hub.PublishUser(userID, "notification", n)
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context, userID string, limit int) ([]models.Notification, error) {
|
|
return s.store.List(ctx, userID, limit)
|
|
}
|
|
|
|
func (s *Service) MarkRead(ctx context.Context, id, userID string) error {
|
|
if err := s.store.MarkRead(ctx, id, userID); err != nil {
|
|
return httpx.NotFound("notification_not_found", "notification not found")
|
|
}
|
|
return nil
|
|
}
|