database

package
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDB

func InitDB(ctx context.Context, config Config) (*sql.DB, error)

func NewMagicLinkRepository added in v1.2.1

func NewMagicLinkRepository(db *sql.DB) services.MagicLinkRepository

Types

type AdminRepository

type AdminRepository struct {
	// contains filtered or unexported fields
}

AdminRepository provides read-only access for admin operations

func NewAdminRepository

func NewAdminRepository(db *sql.DB) *AdminRepository

func (*AdminRepository) Close

func (r *AdminRepository) Close() error

Close gracefully terminates the database connection pool to prevent resource leaks

func (*AdminRepository) ListDocumentsWithCounts

func (r *AdminRepository) ListDocumentsWithCounts(ctx context.Context) ([]DocumentAgg, error)

ListDocumentsWithCounts aggregates signature metrics across all documents for admin dashboard

func (*AdminRepository) ListSignaturesByDoc

func (r *AdminRepository) ListSignaturesByDoc(ctx context.Context, docID string) ([]*models.Signature, error)

ListSignaturesByDoc retrieves all signatures for a document in reverse chronological order

func (*AdminRepository) VerifyDocumentChainIntegrity

func (r *AdminRepository) VerifyDocumentChainIntegrity(ctx context.Context, docID string) (*ChainIntegrityResult, error)

VerifyDocumentChainIntegrity validates cryptographic hash chain continuity for all signatures in a document

type ChainIntegrityResult

type ChainIntegrityResult struct {
	IsValid     bool     `json:"is_valid"`
	TotalSigs   int      `json:"total_signatures"`
	ValidSigs   int      `json:"valid_signatures"`
	InvalidSigs int      `json:"invalid_signatures"`
	Errors      []string `json:"errors,omitempty"`
	DocID       string   `json:"doc_id"`
}

ChainIntegrityResult contient le résultat de la vérification d'intégrité

type Config

type Config struct {
	DSN string
}

type DocumentAgg

type DocumentAgg struct {
	DocID           string `json:"doc_id"`
	Count           int    `json:"count"`            // Total signatures
	ExpectedCount   int    `json:"expected_count"`   // Nombre de signataires attendus
	SignedCount     int    `json:"signed_count"`     // Signatures attendues signées
	UnexpectedCount int    `json:"unexpected_count"` // Signatures non attendues
}

type DocumentRepository

type DocumentRepository struct {
	// contains filtered or unexported fields
}

DocumentRepository handles document metadata persistence

func NewDocumentRepository

func NewDocumentRepository(db *sql.DB, tenants tenant.Provider) *DocumentRepository

NewDocumentRepository creates a new DocumentRepository

func (*DocumentRepository) Count added in v1.2.3

func (r *DocumentRepository) Count(ctx context.Context, searchQuery string) (int, error)

Count returns the total number of documents matching the optional search query (excluding soft-deleted)

func (*DocumentRepository) Create

func (r *DocumentRepository) Create(ctx context.Context, docID string, input models.DocumentInput, createdBy string) (*models.Document, error)

Create persists a new document with metadata including optional checksum validation data

func (*DocumentRepository) CreateOrUpdate

func (r *DocumentRepository) CreateOrUpdate(ctx context.Context, docID string, input models.DocumentInput, createdBy string) (*models.Document, error)

CreateOrUpdate performs upsert operation, creating new document or updating existing one atomically

func (*DocumentRepository) Delete

func (r *DocumentRepository) Delete(ctx context.Context, docID string) error

Delete soft-deletes document by setting deleted_at timestamp, preserving metadata and signature history

func (*DocumentRepository) FindByReference

func (r *DocumentRepository) FindByReference(ctx context.Context, ref string, refType string) (*models.Document, error)

FindByReference searches for a document by reference (URL, path, or doc_id)

func (*DocumentRepository) GetByDocID

func (r *DocumentRepository) GetByDocID(ctx context.Context, docID string) (*models.Document, error)

GetByDocID retrieves document metadata by document ID (excluding soft-deleted documents)

func (*DocumentRepository) List

func (r *DocumentRepository) List(ctx context.Context, limit, offset int) ([]*models.Document, error)

List retrieves paginated documents ordered by creation date, newest first (excluding soft-deleted)

func (*DocumentRepository) Search added in v1.2.3

func (r *DocumentRepository) Search(ctx context.Context, query string, limit, offset int) ([]*models.Document, error)

Search retrieves paginated documents matching the search query (excluding soft-deleted) Searches in doc_id, title, url, and description fields using case-insensitive pattern matching

func (*DocumentRepository) Update

Update modifies existing document metadata while preserving creation timestamp and creator

type EmailQueueRepository

type EmailQueueRepository struct {
	// contains filtered or unexported fields
}

EmailQueueRepository handles database operations for the email queue

func NewEmailQueueRepository

func NewEmailQueueRepository(db *sql.DB, tenants tenant.Provider) *EmailQueueRepository

NewEmailQueueRepository creates a new email queue repository

func (*EmailQueueRepository) CancelEmail

func (r *EmailQueueRepository) CancelEmail(ctx context.Context, id int64) error

CancelEmail cancels a pending email

func (*EmailQueueRepository) CleanupOldEmails

func (r *EmailQueueRepository) CleanupOldEmails(ctx context.Context, olderThan time.Duration) (int64, error)

CleanupOldEmails removes old processed emails from the queue

func (*EmailQueueRepository) Enqueue

Enqueue adds a new email to the queue

func (*EmailQueueRepository) GetNextToProcess

func (r *EmailQueueRepository) GetNextToProcess(ctx context.Context, limit int) ([]*models.EmailQueueItem, error)

GetNextToProcess fetches the next email(s) to process from the queue

func (*EmailQueueRepository) GetQueueStats

func (r *EmailQueueRepository) GetQueueStats(ctx context.Context) (*models.EmailQueueStats, error)

GetQueueStats returns statistics about the email queue

func (*EmailQueueRepository) GetRetryableEmails

func (r *EmailQueueRepository) GetRetryableEmails(ctx context.Context, limit int) ([]*models.EmailQueueItem, error)

GetRetryableEmails fetches emails that should be retried

func (*EmailQueueRepository) MarkAsFailed

func (r *EmailQueueRepository) MarkAsFailed(ctx context.Context, id int64, err error, shouldRetry bool) error

MarkAsFailed marks an email as failed with error details This method uses the default PostgreSQL exponential backoff calculation

func (*EmailQueueRepository) MarkAsFailedWithDelay added in v1.2.3

func (r *EmailQueueRepository) MarkAsFailedWithDelay(ctx context.Context, id int64, err error, shouldRetry bool, retryDelay time.Duration) error

MarkAsFailedWithDelay marks an email as failed with error details and custom retry delay

func (*EmailQueueRepository) MarkAsSent

func (r *EmailQueueRepository) MarkAsSent(ctx context.Context, id int64) error

MarkAsSent marks an email as successfully sent

type ExpectedSignerRepository

type ExpectedSignerRepository struct {
	// contains filtered or unexported fields
}

ExpectedSignerRepository handles database operations for expected signers

func NewExpectedSignerRepository

func NewExpectedSignerRepository(db *sql.DB, tenants tenant.Provider) *ExpectedSignerRepository

NewExpectedSignerRepository creates a new expected signer repository

func (*ExpectedSignerRepository) AddExpected

func (r *ExpectedSignerRepository) AddExpected(ctx context.Context, docID string, contacts []models.ContactInfo, addedBy string) error

AddExpected batch-inserts multiple expected signers with conflict-safe deduplication on (doc_id, email)

func (*ExpectedSignerRepository) GetStats

GetStats calculates signature completion metrics including percentage progress for a document

func (*ExpectedSignerRepository) IsExpected

func (r *ExpectedSignerRepository) IsExpected(ctx context.Context, docID, email string) (bool, error)

IsExpected efficiently verifies if an email address is in the expected signer list for a document

func (*ExpectedSignerRepository) ListByDocID

func (r *ExpectedSignerRepository) ListByDocID(ctx context.Context, docID string) ([]*models.ExpectedSigner, error)

ListByDocID retrieves all expected signers for a document, ordered chronologically by when they were added

func (*ExpectedSignerRepository) ListWithStatusByDocID

func (r *ExpectedSignerRepository) ListWithStatusByDocID(ctx context.Context, docID string) ([]*models.ExpectedSignerWithStatus, error)

ListWithStatusByDocID enriches signer data with signature completion status and reminder tracking metrics

func (*ExpectedSignerRepository) Remove

func (r *ExpectedSignerRepository) Remove(ctx context.Context, docID, email string) error

Remove deletes a specific expected signer by document ID and email address

func (*ExpectedSignerRepository) RemoveAllForDoc

func (r *ExpectedSignerRepository) RemoveAllForDoc(ctx context.Context, docID string) error

RemoveAllForDoc purges all expected signers associated with a document in a single operation

type OAuthSessionRepository

type OAuthSessionRepository struct {
	// contains filtered or unexported fields
}

OAuthSessionRepository implements the OAuth session repository

func NewOAuthSessionRepository

func NewOAuthSessionRepository(db *sql.DB, tenants tenant.Provider) *OAuthSessionRepository

NewOAuthSessionRepository creates a new OAuth session repository

func (*OAuthSessionRepository) Create

Create creates a new OAuth session

func (*OAuthSessionRepository) DeleteBySessionID

func (r *OAuthSessionRepository) DeleteBySessionID(ctx context.Context, sessionID string) error

DeleteBySessionID deletes an OAuth session by session ID

func (*OAuthSessionRepository) DeleteExpired

func (r *OAuthSessionRepository) DeleteExpired(ctx context.Context, olderThan time.Duration) (int64, error)

DeleteExpired deletes OAuth sessions older than the specified duration

func (*OAuthSessionRepository) GetBySessionID

func (r *OAuthSessionRepository) GetBySessionID(ctx context.Context, sessionID string) (*models.OAuthSession, error)

GetBySessionID retrieves an OAuth session by session ID

func (*OAuthSessionRepository) UpdateRefreshToken

func (r *OAuthSessionRepository) UpdateRefreshToken(ctx context.Context, sessionID string, encryptedToken []byte, expiresAt time.Time) error

UpdateRefreshToken updates the refresh token and expiration time

type ReminderRepository

type ReminderRepository struct {
	// contains filtered or unexported fields
}

ReminderRepository handles database operations for reminder logs

func NewReminderRepository

func NewReminderRepository(db *sql.DB, tenants tenant.Provider) *ReminderRepository

NewReminderRepository creates a new reminder repository

func (*ReminderRepository) GetLastReminderByEmail

func (r *ReminderRepository) GetLastReminderByEmail(ctx context.Context, docID, email string) (*models.ReminderLog, error)

GetLastReminderByEmail retrieves the most recent reminder sent to a specific recipient for throttling logic

func (*ReminderRepository) GetReminderCount

func (r *ReminderRepository) GetReminderCount(ctx context.Context, docID, email string) (int, error)

GetReminderCount tallies successfully delivered reminders to a recipient for rate limiting

func (*ReminderRepository) GetReminderHistory

func (r *ReminderRepository) GetReminderHistory(ctx context.Context, docID string) ([]*models.ReminderLog, error)

GetReminderHistory retrieves complete reminder audit trail for a document, ordered by send time descending

func (*ReminderRepository) GetReminderStats

func (r *ReminderRepository) GetReminderStats(ctx context.Context, docID string) (*models.ReminderStats, error)

GetReminderStats aggregates reminder metrics including pending signers and last send timestamp

func (*ReminderRepository) LogReminder

func (r *ReminderRepository) LogReminder(ctx context.Context, log *models.ReminderLog) error

LogReminder records an email reminder event with delivery status for audit tracking

type SignatureRepository

type SignatureRepository struct {
	// contains filtered or unexported fields
}

SignatureRepository handles PostgreSQL persistence for cryptographic signatures

func NewSignatureRepository

func NewSignatureRepository(db *sql.DB, tenants tenant.Provider) *SignatureRepository

NewSignatureRepository initializes a signature repository with the given database connection

func (*SignatureRepository) CheckUserSignatureStatus

func (r *SignatureRepository) CheckUserSignatureStatus(ctx context.Context, docID, userIdentifier string) (bool, error)

CheckUserSignatureStatus verifies if a user has signed, accepting either OAuth subject or email as identifier

func (*SignatureRepository) Create

func (r *SignatureRepository) Create(ctx context.Context, signature *models.Signature) error

Create persists a new signature record to PostgreSQL with UNIQUE constraint enforcement on (doc_id, user_sub)

func (*SignatureRepository) ExistsByDocAndUser

func (r *SignatureRepository) ExistsByDocAndUser(ctx context.Context, docID, userSub string) (bool, error)

ExistsByDocAndUser efficiently checks if a signature already exists without retrieving full record data

func (*SignatureRepository) GetAllSignaturesOrdered

func (r *SignatureRepository) GetAllSignaturesOrdered(ctx context.Context) ([]*models.Signature, error)

GetAllSignaturesOrdered retrieves all signatures in chronological order for chain integrity verification

func (*SignatureRepository) GetByDoc

func (r *SignatureRepository) GetByDoc(ctx context.Context, docID string) ([]*models.Signature, error)

GetByDoc retrieves all signatures for a specific document, ordered by creation timestamp descending

func (*SignatureRepository) GetByDocAndUser

func (r *SignatureRepository) GetByDocAndUser(ctx context.Context, docID, userSub string) (*models.Signature, error)

GetByDocAndUser retrieves a specific signature by document ID and user OAuth subject identifier

func (*SignatureRepository) GetByUser

func (r *SignatureRepository) GetByUser(ctx context.Context, userSub string) ([]*models.Signature, error)

GetByUser retrieves all signatures created by a specific user, ordered by creation timestamp descending

func (*SignatureRepository) GetLastSignature

func (r *SignatureRepository) GetLastSignature(ctx context.Context, docID string) (*models.Signature, error)

GetLastSignature retrieves the most recent signature for hash chain linking (returns nil if no signatures exist)

func (*SignatureRepository) UpdatePrevHash

func (r *SignatureRepository) UpdatePrevHash(ctx context.Context, id int64, prevHash *string) error

UpdatePrevHash modifies the previous hash pointer for chain reconstruction operations

type WebhookDeliveryItem

type WebhookDeliveryItem struct {
	ID            int64
	WebhookID     int64
	EventType     string
	EventID       string
	Payload       []byte
	Status        string
	RetryCount    int
	MaxRetries    int
	Priority      int
	ScheduledFor  time.Time
	TargetURL     string
	Secret        string
	CustomHeaders map[string]string
}

Joined view of a delivery with webhook send data

type WebhookDeliveryRepository

type WebhookDeliveryRepository struct {
	// contains filtered or unexported fields
}

func NewWebhookDeliveryRepository

func NewWebhookDeliveryRepository(db *sql.DB, tenants tenant.Provider) *WebhookDeliveryRepository

func (*WebhookDeliveryRepository) CleanupOld

func (r *WebhookDeliveryRepository) CleanupOld(ctx context.Context, olderThan time.Duration) (int64, error)

func (*WebhookDeliveryRepository) Enqueue

func (*WebhookDeliveryRepository) GetNextToProcess

func (r *WebhookDeliveryRepository) GetNextToProcess(ctx context.Context, limit int) ([]*WebhookDeliveryItem, error)

GetNextToProcess fetches deliveries and moves them to processing; joins webhooks data

func (*WebhookDeliveryRepository) GetRetryable

func (r *WebhookDeliveryRepository) GetRetryable(ctx context.Context, limit int) ([]*WebhookDeliveryItem, error)

func (*WebhookDeliveryRepository) ListByWebhook

func (r *WebhookDeliveryRepository) ListByWebhook(ctx context.Context, webhookID int64, limit, offset int) ([]*models.WebhookDelivery, error)

func (*WebhookDeliveryRepository) MarkDelivered

func (r *WebhookDeliveryRepository) MarkDelivered(ctx context.Context, id int64, responseStatus int, responseHeaders map[string]string, responseBody string) error

func (*WebhookDeliveryRepository) MarkFailed

func (r *WebhookDeliveryRepository) MarkFailed(ctx context.Context, id int64, err error, shouldRetry bool) error

type WebhookRepository

type WebhookRepository struct {
	// contains filtered or unexported fields
}

func NewWebhookRepository

func NewWebhookRepository(db *sql.DB, tenants tenant.Provider) *WebhookRepository

func (*WebhookRepository) Create

func (*WebhookRepository) Delete

func (r *WebhookRepository) Delete(ctx context.Context, id int64) error

func (*WebhookRepository) GetByID

func (r *WebhookRepository) GetByID(ctx context.Context, id int64) (*models.Webhook, error)

func (*WebhookRepository) List

func (r *WebhookRepository) List(ctx context.Context, limit, offset int) ([]*models.Webhook, error)

func (*WebhookRepository) ListActiveByEvent

func (r *WebhookRepository) ListActiveByEvent(ctx context.Context, event string) ([]*models.Webhook, error)

ListActiveByEvent returns active webhooks subscribed to a given event type

func (*WebhookRepository) SetActive

func (r *WebhookRepository) SetActive(ctx context.Context, id int64, active bool) error

func (*WebhookRepository) Update

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL