Files
lincodex/backend/internal/port/outbound/needs.go
T

51 lines
1.9 KiB
Go

package outbound
import (
"context"
"errors"
"github.com/google/uuid"
"lincodex/backend/internal/domain"
)
var (
// ErrNeedNotFound reports that the need does not exist in organizationID.
ErrNeedNotFound = errors.New("organization need not found")
// ErrNeedAlreadyExists reports that a need with the supplied ID is already
// stored. Creation idempotency is handled by the application usecase.
ErrNeedAlreadyExists = errors.New("organization need already exists")
// ErrNeedVersionConflict reports a stale expected need version. The
// surrounding transaction remains safe to roll back and the API maps the
// conflict to its current 412 contract.
ErrNeedVersionConflict = errors.New("organization need changed concurrently")
)
// NeedRepositories exposes tenant-scoped need storage bound to one
// UnitOfWork transaction.
type NeedRepositories interface {
Needs() NeedRepository
}
// NeedRepository stores the current organization need and its immutable
// version snapshots. Every operation scopes by both organization and need ID.
type NeedRepository interface {
// Create inserts version 1 and its initial snapshot in the surrounding
// transaction. The organization must already exist.
Create(ctx context.Context, need domain.Need) error
// Get returns the current snapshot in organizationID, or ErrNeedNotFound.
Get(ctx context.Context, organizationID, needID uuid.UUID) (domain.Need, error)
// GetVersion returns one immutable historical snapshot scoped to its
// organization and need. It returns ErrNeedNotFound for a missing version.
GetVersion(ctx context.Context, organizationID, needID uuid.UUID, version int64) (domain.Need, error)
// Save appends the single next version and atomically advances the current
// pointer when it still equals expectedVersion. The caller's transaction
// rolls back both writes if either write fails.
Save(ctx context.Context, organizationID, needID uuid.UUID, expectedVersion int64, next domain.Need) error
}