Documentation
¶
Index ¶
- Variables
- type CarRepository
- type CategoryRepository
- type FullRepository
- type Repository
- func (r *Repository) CarExists(ctx context.Context, carNumber string) (bool, error)
- func (r *Repository) CategoryExists(ctx context.Context, name string) (bool, error)
- func (r *Repository) ClearConflictingVote(ctx context.Context, voterID, categoryID, carID int) error
- func (r *Repository) ClearManualWinner(ctx context.Context, categoryID int) error
- func (r *Repository) ClearTable(ctx context.Context, table string) error
- func (r *Repository) Close() error
- func (r *Repository) CountVotesForCar(ctx context.Context, carID int) (int, error)
- func (r *Repository) CountVotesForCategory(ctx context.Context, categoryID int) (int, error)
- func (r *Repository) CreateCar(ctx context.Context, carNumber, racerName, carName, photoURL string) error
- func (r *Repository) CreateCategory(ctx context.Context, name string, displayOrder int, groupID *int, ...) (int64, error)
- func (r *Repository) CreateCategoryGroup(ctx context.Context, name, description string, exclusivityPoolID *int, ...) (int64, error)
- func (r *Repository) CreateVoter(ctx context.Context, qrCode string) (int, error)
- func (r *Repository) CreateVoterFull(ctx context.Context, carID *int, name, email, voterType, qrCode, notes string) (int64, error)
- func (r *Repository) DB() *sql.DB
- func (r *Repository) DeleteCar(ctx context.Context, id int) error
- func (r *Repository) DeleteCategory(ctx context.Context, id int) error
- func (r *Repository) DeleteCategoryGroup(ctx context.Context, id string) error
- func (r *Repository) DeleteVoter(ctx context.Context, id int) error
- func (r *Repository) FindConflictingVote(ctx context.Context, voterID, carID, categoryID int, poolID int64) (int, string, bool, error)
- func (r *Repository) GetCar(ctx context.Context, id int) (*models.Car, error)
- func (r *Repository) GetCarByDerbyNetID(ctx context.Context, racerID int) (int64, bool, error)
- func (r *Repository) GetCategoryGroup(ctx context.Context, id string) (*models.CategoryGroup, error)
- func (r *Repository) GetExclusivityPoolID(ctx context.Context, categoryID int) (int64, bool, error)
- func (r *Repository) GetSetting(ctx context.Context, key string) (string, error)
- func (r *Repository) GetVoteResults(ctx context.Context) (map[int]map[int]int, error)
- func (r *Repository) GetVoteResultsWithCars(ctx context.Context) ([]VoteResultRow, error)
- func (r *Repository) GetVoterByQR(ctx context.Context, qrCode string) (int, error)
- func (r *Repository) GetVoterByQRCode(ctx context.Context, qrCode string) (int64, bool, error)
- func (r *Repository) GetVoterQRCode(ctx context.Context, id int) (string, error)
- func (r *Repository) GetVoterType(ctx context.Context, voterID int) (string, error)
- func (r *Repository) GetVoterVotes(ctx context.Context, voterID int) (map[int]int, error)
- func (r *Repository) GetVotingStats(ctx context.Context) (map[string]interface{}, error)
- func (r *Repository) GetWinnersForDerbyNet(ctx context.Context) ([]WinnerForDerbyNet, error)
- func (r *Repository) InsertVoterIgnore(ctx context.Context, qrCode string) error
- func (r *Repository) ListAllCategories(ctx context.Context) ([]map[string]interface{}, error)
- func (r *Repository) ListCars(ctx context.Context) ([]models.Car, error)
- func (r *Repository) ListCategories(ctx context.Context) ([]models.Category, error)
- func (r *Repository) ListCategoryGroups(ctx context.Context) ([]models.CategoryGroup, error)
- func (r *Repository) ListEligibleCars(ctx context.Context) ([]models.Car, error)
- func (r *Repository) ListVoters(ctx context.Context) ([]map[string]interface{}, error)
- func (r *Repository) Ping(ctx context.Context) error
- func (r *Repository) SaveVote(ctx context.Context, voterID, categoryID, carID int) error
- func (r *Repository) SetCarEligibility(ctx context.Context, id int, eligible bool) error
- func (r *Repository) SetManualWinner(ctx context.Context, categoryID, carID int, reason string) error
- func (r *Repository) SetSetting(ctx context.Context, key, value string) error
- func (r *Repository) UpdateCar(ctx context.Context, id int, ...) error
- func (r *Repository) UpdateCategory(ctx context.Context, id int, name string, displayOrder int, groupID *int, ...) error
- func (r *Repository) UpdateCategoryGroup(ctx context.Context, id string, name, description string, ...) error
- func (r *Repository) UpdateVoter(ctx context.Context, id int, carID *int, name, email, voterType, notes string) error
- func (r *Repository) UpsertCar(ctx context.Context, derbynetRacerID int, ...) error
- func (r *Repository) UpsertCategory(ctx context.Context, name string, displayOrder int, derbynetAwardID *int) (bool, error)
- func (r *Repository) UpsertVoterForCar(ctx context.Context, carID int64, name, qrCode string) error
- type SettingsRepository
- type VoteRepository
- type VoteResultRow
- type VoterRepository
- type WinnerForDerbyNet
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
type FullRepository interface {
CategoryRepository
VoterRepository
CarRepository
VoteRepository
SettingsRepository
}
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 (*Repository) CategoryExists ¶
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) CountVotesForCar ¶
CountVotesForCar returns the number of votes a car has received
func (*Repository) CountVotesForCategory ¶
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 ¶
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) GetCarByDerbyNetID ¶
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 ¶
GetExclusivityPoolID returns the exclusivity pool ID for a category
func (*Repository) GetSetting ¶
GetSetting retrieves a setting value
func (*Repository) GetVoteResults ¶
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 ¶
GetVoterByQR retrieves a voter by QR code
func (*Repository) GetVoterByQRCode ¶
GetVoterByQRCode checks if a voter exists by QR code
func (*Repository) GetVoterQRCode ¶
GetVoterQRCode returns the QR code for a voter by ID
func (*Repository) GetVoterType ¶
GetVoterType returns the voter type for a given voter ID
func (*Repository) GetVoterVotes ¶
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 ¶
ListCars returns all active cars (including ineligible ones, for admin views)
func (*Repository) ListCategories ¶
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 ¶
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 ¶
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 ¶
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