repository

package
v0.0.0-...-3c7e12f Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTable = errors.New("invalid table name")

ErrInvalidTable is returned when attempting to clear a table that is not whitelisted. This prevents SQL injection attacks.

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound is returned when a requested record is not found in the repository. This abstracts away the underlying storage implementation (SQL, NoSQL, etc.) from the service layer.

Functions

This section is empty.

Types

type CarRepository

type CarRepository interface {
	ListCars(ctx context.Context) ([]models.Car, error)
	ListEligibleCars(ctx context.Context) ([]models.Car, error)
	GetCar(ctx context.Context, id int) (*models.Car, error)
	GetCarByDerbyNetID(ctx context.Context, racerID int) (int64, bool, error)
	UpsertCar(ctx context.Context, derbynetRacerID int, carNumber, racerName, carName, photoURL, rank string) error
	CarExists(ctx context.Context, carNumber string) (bool, error)
	CreateCar(ctx context.Context, carNumber, racerName, carName, photoURL string) error
	UpdateCar(ctx context.Context, id int, carNumber, racerName, carName, photoURL, rank string) error
	SetCarEligibility(ctx context.Context, id int, eligible bool) error
	DeleteCar(ctx context.Context, id int) error
	CountVotesForCar(ctx context.Context, carID int) (int, error)
}

CarRepository defines car data operations

type CategoryRepository

type CategoryRepository interface {
	ListCategories(ctx context.Context) ([]models.Category, error)
	ListAllCategories(ctx context.Context) ([]map[string]interface{}, error)
	CreateCategory(ctx context.Context, name string, displayOrder int, groupID *int, allowedVoterTypes []string, allowedRanks []string) (int64, error)
	UpdateCategory(ctx context.Context, id int, name string, displayOrder int, groupID *int, allowedVoterTypes []string, allowedRanks []string, active bool) error
	DeleteCategory(ctx context.Context, id int) error
	CategoryExists(ctx context.Context, name string) (bool, error)
	UpsertCategory(ctx context.Context, name string, displayOrder int, derbynetAwardID *int) (created bool, err error)
	SetManualWinner(ctx context.Context, categoryID, carID int, reason string) error
	ClearManualWinner(ctx context.Context, categoryID int) error
	ListCategoryGroups(ctx context.Context) ([]models.CategoryGroup, error)
	GetCategoryGroup(ctx context.Context, id string) (*models.CategoryGroup, error)
	CreateCategoryGroup(ctx context.Context, name, description string, exclusivityPoolID *int, maxWinsPerCar *int, displayOrder int) (int64, error)
	UpdateCategoryGroup(ctx context.Context, id string, name, description string, exclusivityPoolID *int, maxWinsPerCar *int, displayOrder int) error
	DeleteCategoryGroup(ctx context.Context, id string) error
}

CategoryRepository defines category data operations

type FullRepository

FullRepository combines all repository interfaces Use this when a service needs access to multiple domains

type Repository

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

Repository provides data access methods

func New

func New(dbPath string) (*Repository, error)

New creates a new Repository

func (*Repository) CarExists

func (r *Repository) CarExists(ctx context.Context, carNumber string) (bool, error)

CarExists checks if a car with the given number exists

func (*Repository) CategoryExists

func (r *Repository) CategoryExists(ctx context.Context, name string) (bool, error)

CategoryExists checks if a category with the given name exists

func (*Repository) ClearConflictingVote

func (r *Repository) ClearConflictingVote(ctx context.Context, voterID, categoryID, carID int) error

ClearConflictingVote removes a vote

func (*Repository) ClearManualWinner

func (r *Repository) ClearManualWinner(ctx context.Context, categoryID int) error

ClearManualWinner clears the manual winner override for a category

func (*Repository) ClearTable

func (r *Repository) ClearTable(ctx context.Context, table string) error

ClearTable clears all data from a table Only allows clearing whitelisted tables to prevent SQL injection

func (*Repository) Close

func (r *Repository) Close() error

Close closes the database connection

func (*Repository) CountVotesForCar

func (r *Repository) CountVotesForCar(ctx context.Context, carID int) (int, error)

CountVotesForCar returns the number of votes a car has received

func (*Repository) CountVotesForCategory

func (r *Repository) CountVotesForCategory(ctx context.Context, categoryID int) (int, error)

CountVotesForCategory returns the number of votes in a category

func (*Repository) CreateCar

func (r *Repository) CreateCar(ctx context.Context, carNumber, racerName, carName, photoURL string) error

CreateCar creates a new car

func (*Repository) CreateCategory

func (r *Repository) CreateCategory(ctx context.Context, name string, displayOrder int, groupID *int, allowedVoterTypes []string, allowedRanks []string) (int64, error)

CreateCategory creates a new category

func (*Repository) CreateCategoryGroup

func (r *Repository) CreateCategoryGroup(ctx context.Context, name, description string, exclusivityPoolID *int, maxWinsPerCar *int, displayOrder int) (int64, error)

CreateCategoryGroup creates a new category group

func (*Repository) CreateVoter

func (r *Repository) CreateVoter(ctx context.Context, qrCode string) (int, error)

CreateVoter creates a new voter

func (*Repository) CreateVoterFull

func (r *Repository) CreateVoterFull(ctx context.Context, carID *int, name, email, voterType, qrCode, notes string) (int64, error)

CreateVoterFull creates a voter with all fields

func (*Repository) DB

func (r *Repository) DB() *sql.DB

DB returns the underlying database connection (for transactions)

func (*Repository) DeleteCar

func (r *Repository) DeleteCar(ctx context.Context, id int) error

DeleteCar soft deletes a car

func (*Repository) DeleteCategory

func (r *Repository) DeleteCategory(ctx context.Context, id int) error

DeleteCategory soft-deletes a category

func (*Repository) DeleteCategoryGroup

func (r *Repository) DeleteCategoryGroup(ctx context.Context, id string) error

DeleteCategoryGroup deletes a category group

func (*Repository) DeleteVoter

func (r *Repository) DeleteVoter(ctx context.Context, id int) error

DeleteVoter deletes a voter

func (*Repository) FindConflictingVote

func (r *Repository) FindConflictingVote(ctx context.Context, voterID, carID, categoryID int, poolID int64) (int, string, bool, error)

FindConflictingVote finds a conflicting vote in the same exclusivity pool

func (*Repository) GetCar

func (r *Repository) GetCar(ctx context.Context, id int) (*models.Car, error)

GetCar returns a car by ID

func (*Repository) GetCarByDerbyNetID

func (r *Repository) GetCarByDerbyNetID(ctx context.Context, racerID int) (int64, bool, error)

GetCarByDerbyNetID checks if a car exists by DerbyNet racer ID

func (*Repository) GetCategoryGroup

func (r *Repository) GetCategoryGroup(ctx context.Context, id string) (*models.CategoryGroup, error)

GetCategoryGroup retrieves a category group by ID

func (*Repository) GetExclusivityPoolID

func (r *Repository) GetExclusivityPoolID(ctx context.Context, categoryID int) (int64, bool, error)

GetExclusivityPoolID returns the exclusivity pool ID for a category

func (*Repository) GetSetting

func (r *Repository) GetSetting(ctx context.Context, key string) (string, error)

GetSetting retrieves a setting value

func (*Repository) GetVoteResults

func (r *Repository) GetVoteResults(ctx context.Context) (map[int]map[int]int, error)

GetVoteResults returns vote counts per category and car

func (*Repository) GetVoteResultsWithCars

func (r *Repository) GetVoteResultsWithCars(ctx context.Context) ([]VoteResultRow, error)

GetVoteResultsWithCars returns vote results with car details (only cars with votes)

func (*Repository) GetVoterByQR

func (r *Repository) GetVoterByQR(ctx context.Context, qrCode string) (int, error)

GetVoterByQR retrieves a voter by QR code

func (*Repository) GetVoterByQRCode

func (r *Repository) GetVoterByQRCode(ctx context.Context, qrCode string) (int64, bool, error)

GetVoterByQRCode checks if a voter exists by QR code

func (*Repository) GetVoterQRCode

func (r *Repository) GetVoterQRCode(ctx context.Context, id int) (string, error)

GetVoterQRCode returns the QR code for a voter by ID

func (*Repository) GetVoterType

func (r *Repository) GetVoterType(ctx context.Context, voterID int) (string, error)

GetVoterType returns the voter type for a given voter ID

func (*Repository) GetVoterVotes

func (r *Repository) GetVoterVotes(ctx context.Context, voterID int) (map[int]int, error)

GetVoterVotes returns all votes for a voter

func (*Repository) GetVotingStats

func (r *Repository) GetVotingStats(ctx context.Context) (map[string]interface{}, error)

GetVotingStats returns overall voting statistics

func (*Repository) GetWinnersForDerbyNet

func (r *Repository) GetWinnersForDerbyNet(ctx context.Context) ([]WinnerForDerbyNet, error)

GetWinnersForDerbyNet returns the winner per category with DerbyNet IDs, respecting manual overrides

func (*Repository) InsertVoterIgnore

func (r *Repository) InsertVoterIgnore(ctx context.Context, qrCode string) error

InsertVoterIgnore inserts a voter, ignoring conflicts

func (*Repository) ListAllCategories

func (r *Repository) ListAllCategories(ctx context.Context) ([]map[string]interface{}, error)

ListAllCategories returns all categories (including inactive) with group info

func (*Repository) ListCars

func (r *Repository) ListCars(ctx context.Context) ([]models.Car, error)

ListCars returns all active cars (including ineligible ones, for admin views)

func (*Repository) ListCategories

func (r *Repository) ListCategories(ctx context.Context) ([]models.Category, error)

ListCategories returns all active categories with group info

func (*Repository) ListCategoryGroups

func (r *Repository) ListCategoryGroups(ctx context.Context) ([]models.CategoryGroup, error)

ListCategoryGroups returns all active category groups

func (*Repository) ListEligibleCars

func (r *Repository) ListEligibleCars(ctx context.Context) ([]models.Car, error)

ListEligibleCars returns all active and eligible cars (for voting)

func (*Repository) ListVoters

func (r *Repository) ListVoters(ctx context.Context) ([]map[string]interface{}, error)

ListVoters returns all voters with car info

func (*Repository) Ping

func (r *Repository) Ping(ctx context.Context) error

Ping checks if the database connection is alive

func (*Repository) SaveVote

func (r *Repository) SaveVote(ctx context.Context, voterID, categoryID, carID int) error

SaveVote saves or updates a vote

func (*Repository) SetCarEligibility

func (r *Repository) SetCarEligibility(ctx context.Context, id int, eligible bool) error

SetCarEligibility updates a car's eligibility for voting

func (*Repository) SetManualWinner

func (r *Repository) SetManualWinner(ctx context.Context, categoryID, carID int, reason string) error

SetManualWinner sets the manual winner override for a category

func (*Repository) SetSetting

func (r *Repository) SetSetting(ctx context.Context, key, value string) error

SetSetting updates a setting value

func (*Repository) UpdateCar

func (r *Repository) UpdateCar(ctx context.Context, id int, carNumber, racerName, carName, photoURL, rank string) error

UpdateCar updates a car

func (*Repository) UpdateCategory

func (r *Repository) UpdateCategory(ctx context.Context, id int, name string, displayOrder int, groupID *int, allowedVoterTypes []string, allowedRanks []string, active bool) error

UpdateCategory updates a category including allowed voter types and allowed ranks

func (*Repository) UpdateCategoryGroup

func (r *Repository) UpdateCategoryGroup(ctx context.Context, id string, name, description string, exclusivityPoolID *int, maxWinsPerCar *int, displayOrder int) error

UpdateCategoryGroup updates a category group

func (*Repository) UpdateVoter

func (r *Repository) UpdateVoter(ctx context.Context, id int, carID *int, name, email, voterType, notes string) error

UpdateVoter updates a voter

func (*Repository) UpsertCar

func (r *Repository) UpsertCar(ctx context.Context, derbynetRacerID int, carNumber, racerName, carName, photoURL, rank string) error

UpsertCar creates or updates a car

func (*Repository) UpsertCategory

func (r *Repository) UpsertCategory(ctx context.Context, name string, displayOrder int, derbynetAwardID *int) (bool, error)

UpsertCategory creates or updates a category by name, returns whether it was created Also links to DerbyNet award ID if provided (for bi-directional sync)

func (*Repository) UpsertVoterForCar

func (r *Repository) UpsertVoterForCar(ctx context.Context, carID int64, name, qrCode string) error

UpsertVoterForCar creates or updates a voter for a car

type SettingsRepository

type SettingsRepository interface {
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, key, value string) error
	GetVotingStats(ctx context.Context) (map[string]interface{}, error)
	ClearTable(ctx context.Context, table string) error
}

SettingsRepository defines settings data operations

type VoteRepository

type VoteRepository interface {
	GetVoterVotes(ctx context.Context, voterID int) (map[int]int, error)
	SaveVote(ctx context.Context, voterID, categoryID, carID int) error
	GetExclusivityPoolID(ctx context.Context, categoryID int) (int64, bool, error)
	FindConflictingVote(ctx context.Context, voterID, carID, categoryID int, poolID int64) (int, string, bool, error)
	ClearConflictingVote(ctx context.Context, voterID, categoryID, carID int) error
	GetVoteResults(ctx context.Context) (map[int]map[int]int, error)
	GetVoteResultsWithCars(ctx context.Context) ([]VoteResultRow, error)
	GetWinnersForDerbyNet(ctx context.Context) ([]WinnerForDerbyNet, error)
	CountVotesForCategory(ctx context.Context, categoryID int) (int, error)
}

VoteRepository defines vote data operations

type VoteResultRow

type VoteResultRow struct {
	CategoryID int
	CarID      int
	CarNumber  string
	CarName    string
	RacerName  string
	PhotoURL   string
	VoteCount  int
}

VoteResultRow represents a single vote result with car details

type VoterRepository

type VoterRepository interface {
	ListVoters(ctx context.Context) ([]map[string]interface{}, error)
	GetVoterByQR(ctx context.Context, qrCode string) (int, error)
	GetVoterByQRCode(ctx context.Context, qrCode string) (int64, bool, error)
	GetVoterQRCode(ctx context.Context, id int) (string, error)
	GetVoterType(ctx context.Context, voterID int) (string, error)
	CreateVoter(ctx context.Context, qrCode string) (int, error)
	CreateVoterFull(ctx context.Context, carID *int, name, email, voterType, qrCode, notes string) (int64, error)
	UpdateVoter(ctx context.Context, id int, carID *int, name, email, voterType, notes string) error
	DeleteVoter(ctx context.Context, id int) error
	InsertVoterIgnore(ctx context.Context, qrCode string) error
	UpsertVoterForCar(ctx context.Context, carID int64, name, qrCode string) error
}

VoterRepository defines voter data operations

type WinnerForDerbyNet

type WinnerForDerbyNet struct {
	CategoryID      int
	CategoryName    string
	DerbyNetAwardID *int
	CarID           int
	DerbyNetRacerID *int
	VoteCount       int
}

WinnerForDerbyNet represents a winner with DerbyNet IDs for syncing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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