monorepo/cloud/maplepress-backend/internal/domain/site/interface.go

45 lines
1.8 KiB
Go

package site
import (
"context"
"github.com/gocql/gocql"
)
// Repository defines the interface for site data access
type Repository interface {
// Create inserts a new site into all Cassandra tables
Create(ctx context.Context, site *Site) error
// GetByID retrieves a site by tenant_id and site_id
GetByID(ctx context.Context, tenantID, siteID gocql.UUID) (*Site, error)
// GetByDomain retrieves a site by domain name
GetByDomain(ctx context.Context, domain string) (*Site, error)
// GetByAPIKeyHash retrieves a site by API key hash (for authentication)
GetByAPIKeyHash(ctx context.Context, apiKeyHash string) (*Site, error)
// ListByTenant retrieves all sites for a tenant (paginated)
ListByTenant(ctx context.Context, tenantID gocql.UUID, pageSize int, pageState []byte) ([]*Site, []byte, error)
// Update updates a site in all Cassandra tables
Update(ctx context.Context, site *Site) error
// UpdateAPIKey updates the API key for a site (handles sites_by_apikey table correctly)
// Must provide both old and new API key hashes to properly delete old entry and insert new one
UpdateAPIKey(ctx context.Context, site *Site, oldAPIKeyHash string) error
// Delete removes a site from all Cassandra tables
Delete(ctx context.Context, tenantID, siteID gocql.UUID) error
// DomainExists checks if a domain is already registered
DomainExists(ctx context.Context, domain string) (bool, error)
// UpdateUsage updates only usage tracking fields (optimized for frequent updates)
UpdateUsage(ctx context.Context, site *Site) error
// GetAllSitesForUsageReset retrieves all sites for monthly usage counter reset
// This uses ALLOW FILTERING and should only be used for administrative tasks
GetAllSitesForUsageReset(ctx context.Context, pageSize int, pageState []byte) ([]*Site, []byte, error)
}