domain

package
v0.0.0-...-1b54e00 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound indicates that the requested user email was not found in the database
	ErrUserNotFound = errors.New("user email not found in database")

	// ErrDatabaseUnavailable indicates a temporary issue with accessing the database
	ErrDatabaseUnavailable = errors.New("database is temporarily unavailable, try later")

	// ErrInvalidEmail indicates the provided email has invalid format
	ErrInvalidEmail = errors.New("invalid email format")

	// ErrRateLimitExceeded indicates a user has made too many requests
	ErrRateLimitExceeded = errors.New("rate limit exceeded")

	// ErrAlreadyRedeemed indicates a user has already redeemed their cocktail
	ErrAlreadyRedeemed = errors.New("cocktail already redeemed")

	// ErrInvalidCredentials indicates invalid authentication credentials
	ErrInvalidCredentials = errors.New("invalid credentials")

	// ErrInternalServer indicates a generic internal server error
	ErrInternalServer = errors.New("internal server error")
)

Standard domain errors - these are sentinel error values that can be compared directly

Functions

func IsAlreadyRedeemed

func IsAlreadyRedeemed(err error) bool

IsAlreadyRedeemed returns true if the error indicates already redeemed status

func IsDatabaseError

func IsDatabaseError(err error) bool

IsDatabaseError returns true if the error is a database error

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error indicates a not-found condition

func IsRateLimited

func IsRateLimited(err error) bool

IsRateLimited returns true if the error indicates rate limiting

func IsUnavailable

func IsUnavailable(err error) bool

IsUnavailable returns true if the error indicates the database is unavailable

func IsValidationError

func IsValidationError(err error) bool

IsValidationError returns true if the error is a validation error

Types

type DatabaseError

type DatabaseError struct {
	OrigErr  error  // Original error from database driver
	Op       string // Operation being performed
	Database string // Database system being used
	Message  string // Human-readable message
}

DatabaseError provides additional context for database related errors

func NewDatabaseError

func NewDatabaseError(origErr error, database, op, msg string) *DatabaseError

NewDatabaseError creates a new database error

func (*DatabaseError) Error

func (e *DatabaseError) Error() string

Error implements the error interface

func (*DatabaseError) Unwrap

func (e *DatabaseError) Unwrap() error

Unwrap returns the original error for compatibility with errors.Is/As

type ReportParams

type ReportParams struct {
	Type ReportType
	From time.Time
	To   time.Time
}

ReportParams holds parameters for generating reports

type ReportType

type ReportType string

ReportType defines the type of report to generate

const (
	// ReportTypeRedeemed represents a report of redeemed cocktails
	ReportTypeRedeemed ReportType = "redeemed"
	// ReportTypeAdded represents a report of added users
	ReportTypeAdded ReportType = "added"
	// ReportTypeAll represents a report of all users
	ReportTypeAll ReportType = "all"
)

func ValidateReportType

func ValidateReportType(reportType string) (ReportType, error)

ValidateReportType checks if the provided string is a valid report type

type Repository

type Repository interface {
	FindByEmail(ctx any, email string) (*User, error)
	UpdateUser(ctx any, user *User) error
	AddUser(ctx any, user *User) error
	GetReport(ctx any, params ReportParams) ([]*User, error)
	Close() error
}

Repository is the interface that all database implementations must satisfy

type User

type User struct {
	ID        string
	Email     string
	DateAdded time.Time
	Redeemed  *time.Time
}

func (*User) IsRedeemed

func (u *User) IsRedeemed() bool

IsRedeemed returns true if the user has already redeemed their cocktail

func (*User) Redeem

func (u *User) Redeem()

Redeem marks the user as having redeemed their cocktail with the current time

type ValidationError

type ValidationError struct {
	Field   string // Field that failed validation
	Value   string // Value that was invalid (may be omitted for privacy)
	Message string // Human-readable error message
}

ValidationError represents errors related to input validation

func NewValidationError

func NewValidationError(field, message string, value ...string) *ValidationError

NewValidationError creates a new validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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