Documentation
¶
Index ¶
- Variables
- type Note
- type NoteCursor
- type NoteResponse
- type NoteTombstone
- type NotesHandler
- type NotesListResponse
- type NotesRepository
- func (r *NotesRepository) CountLiveNotes(ctx context.Context, userID uuid.UUID) (int64, error)
- func (r *NotesRepository) Delete(ctx context.Context, noteID uuid.UUID, userID uuid.UUID) error
- func (r *NotesRepository) FindAll(ctx context.Context, userID uuid.UUID) ([]Note, error)
- func (r *NotesRepository) FindAllPaginated(ctx context.Context, userID uuid.UUID, limit int, afterUpdatedAt time.Time, ...) ([]Note, error)
- func (r *NotesRepository) FindAllTombstones(ctx context.Context, userID uuid.UUID) ([]NoteTombstone, error)
- func (r *NotesRepository) FindByID(ctx context.Context, noteID uuid.UUID, userID uuid.UUID) (*Note, error)
- func (r *NotesRepository) FindTombstonesSince(ctx context.Context, userID uuid.UUID, since time.Time) ([]NoteTombstone, error)
- func (r *NotesRepository) FindUpdatedSince(ctx context.Context, userID uuid.UUID, since time.Time) ([]Note, error)
- func (r *NotesRepository) PurgeExpiredTombstones(ctx context.Context, olderThan time.Time) (int64, error)
- func (r *NotesRepository) Upsert(ctx context.Context, note *Note) error
- type NotesService
- func (s *NotesService) DeleteNote(ctx context.Context, noteID uuid.UUID, userID uuid.UUID) error
- func (s *NotesService) GetNoteByID(ctx context.Context, noteID uuid.UUID, userID uuid.UUID) (*Note, error)
- func (s *NotesService) GetNotesSince(ctx context.Context, userID uuid.UUID, since *time.Time, cursor *NoteCursor, ...) ([]Note, []NoteTombstone, bool, error)
- func (s *NotesService) UpsertNote(ctx context.Context, userID uuid.UUID, noteID uuid.UUID, ...) (*Note, error)
- type TombstoneResponse
- type UpsertNoteRequest
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoteNotFound = errors.New("note not found") ErrConflict = errors.New("conflict: server version is newer") )
Functions ¶
This section is empty.
Types ¶
type Note ¶
type Note struct {
ID uuid.UUID `gorm:"column:note_id;primaryKey;type:uuid"`
UserID uuid.UUID `gorm:"column:user_id;type:uuid;not null;index:idx_user_updated,priority:1"`
EncryptedPayload []byte `gorm:"column:encrypted_payload;type:bytea;not null"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime;index:idx_user_updated,priority:2"`
}
type NoteCursor ¶
type NoteCursor struct {
AfterUpdatedAt time.Time `json:"updated_at"`
AfterNoteID uuid.UUID `json:"note_id"`
}
NoteCursor is the position marker for cursor-based pagination of notes, ordered by (updated_at ASC, note_id ASC).
type NoteResponse ¶
type NoteTombstone ¶
type NotesHandler ¶
type NotesHandler struct {
// contains filtered or unexported fields
}
func NewNotesHandler ¶
func NewNotesHandler(service service) *NotesHandler
type NotesListResponse ¶
type NotesListResponse struct {
Notes []NoteResponse `json:"notes"`
Tombstones []TombstoneResponse `json:"tombstones"`
NextCursor *string `json:"next_cursor"` // non-null when more pages exist
ServerTime *time.Time `json:"server_time"`
}
type NotesRepository ¶
type NotesRepository struct {
// contains filtered or unexported fields
}
func NewNotesRepository ¶
func NewNotesRepository(db *gorm.DB) *NotesRepository
func (*NotesRepository) CountLiveNotes ¶
func (*NotesRepository) FindAllPaginated ¶
func (r *NotesRepository) FindAllPaginated(ctx context.Context, userID uuid.UUID, limit int, afterUpdatedAt time.Time, afterNoteID uuid.UUID) ([]Note, error)
FindAllPaginated returns up to limit notes for the user, ordered by (updated_at ASC, note_id ASC). Pass zero values for afterUpdatedAt and afterNoteID to start from the beginning.
func (*NotesRepository) FindAllTombstones ¶
func (r *NotesRepository) FindAllTombstones(ctx context.Context, userID uuid.UUID) ([]NoteTombstone, error)
func (*NotesRepository) FindTombstonesSince ¶
func (r *NotesRepository) FindTombstonesSince(ctx context.Context, userID uuid.UUID, since time.Time) ([]NoteTombstone, error)
func (*NotesRepository) FindUpdatedSince ¶
func (*NotesRepository) PurgeExpiredTombstones ¶
type NotesService ¶
type NotesService struct {
// contains filtered or unexported fields
}
func NewNotesService ¶
func NewNotesService(repository repository) *NotesService
func (*NotesService) DeleteNote ¶
func (*NotesService) GetNoteByID ¶
func (*NotesService) GetNotesSince ¶
func (s *NotesService) GetNotesSince(ctx context.Context, userID uuid.UUID, since *time.Time, cursor *NoteCursor, limit int) ([]Note, []NoteTombstone, bool, error)
GetNotesSince returns notes and tombstones for the user.
When since is non-nil (delta sync), all notes updated after that time are returned with no pagination — the result set is expected to be small.
When since is nil (full sync), notes are paginated using cursor-based pagination ordered by (updated_at ASC, note_id ASC). Pass a non-nil cursor to continue from a previous page. Tombstones are always returned in full (they carry no payload and are small). hasMore is true when there are additional pages to fetch.