db

package
v0.0.0-...-8fa2ce1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptFriendRequestParams

type AcceptFriendRequestParams struct {
	FriendeeID   int64 `json:"friendee_id"`
	FriendshipID int64 `json:"friendship_id"`
}

type AcceptGameInvitationParams

type AcceptGameInvitationParams struct {
	ID     int64 `json:"id"`
	GameID int64 `json:"game_id"`
}

type ActivationToken

type ActivationToken struct {
	UserID          int64     `json:"user_id"`
	ActivationToken string    `json:"activation_token"`
	IsBlocked       bool      `json:"is_blocked"`
	ExpiresAt       time.Time `json:"expires_at"`
	CreatedAt       time.Time `json:"created_at"`
}

type AddCardToPlayerHandParams

type AddCardToPlayerHandParams struct {
	PlayerGameID int64 `json:"player_game_id"`
	CardID       int64 `json:"card_id"`
}

type AddPlayerToGameParams

type AddPlayerToGameParams struct {
	PlayerID int64 `json:"player_id"`
	GameID   int64 `json:"game_id"`
}

type Card

type Card struct {
	CardID int64  `json:"card_id"`
	Type   string `json:"type"`
	Name   string `json:"name"`
}

Details of each card used in the game

type CreateFriendshipParams

type CreateFriendshipParams struct {
	FrienderID int64  `json:"friender_id"`
	Username   string `json:"username"`
}

type CreateGameInvitationWithUsernameParams

type CreateGameInvitationWithUsernameParams struct {
	InviterPlayerID int64  `json:"inviter_player_id"`
	Username        string `json:"username"`
	GameID          int64  `json:"game_id"`
}

type CreateSessionParams

type CreateSessionParams struct {
	ID           uuid.UUID `json:"id"`
	Username     string    `json:"username"`
	RefreshToken string    `json:"refresh_token"`
	UserAgent    string    `json:"user_agent"`
	ClientIp     string    `json:"client_ip"`
	IsBlocked    bool      `json:"is_blocked"`
	ExpiresAt    time.Time `json:"expires_at"`
}

type CreateUserParams

type CreateUserParams struct {
	Username string `json:"username"`
	Password []byte `json:"password"`
	Email    string `json:"email"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type DeclareWinnerRow

type DeclareWinnerRow struct {
	PlayerGameID int64         `json:"player_game_id"`
	PlayerNumber sql.NullInt32 `json:"player_number"`
	PlayerScore  int32         `json:"player_score"`
}

type DeleteGameInvitationParams

type DeleteGameInvitationParams struct {
	InviteePlayerID int64 `json:"invitee_player_id"`
	GameID          int64 `json:"game_id"`
}

type Dessert

type Dessert struct {
	DessertID int64  `json:"dessert_id"`
	Name      string `json:"name"`
	Points    int32  `json:"points"`
}

type DessertPlayed

type DessertPlayed struct {
	DessertPlayedID int64          `json:"dessert_played_id"`
	PlayerGameID    int64          `json:"player_game_id"`
	DessertID       int64          `json:"dessert_id"`
	IconPath        sql.NullString `json:"icon_path"`
	Timestamp       time.Time      `json:"timestamp"`
}

type DoesInvitationExistParams

type DoesInvitationExistParams struct {
	InviteePlayerID int64 `json:"invitee_player_id"`
	GameID          int64 `json:"game_id"`
}

type DrawCardTxParams

type DrawCardTxParams struct {
	GameID       int64 `json:"game_id"`
	PlayerID     int64 `json:"player_id"`
	PlayerNumber int32 `json:"player_number"`
}

DrawTxParams holds parameters for the StartGameTx function

type DrawCardTxResult

type DrawCardTxResult struct {
	CardID       int64  `json:"card_id"`
	CardName     string `json:"name"`
	PlayerGameID int64  `json:"player_game_id"`
	PlayerHandID int64  `json:"player_hand_id"`
}

type EndTurnTxResult

type EndTurnTxResult struct {
	Game Game `json:"game"`
}

type Friend

type Friend struct {
	FriendshipID int64     `json:"friendship_id"`
	FrienderID   int64     `json:"friender_id"`
	FriendeeID   int64     `json:"friendee_id"`
	Status       string    `json:"status"`
	FriendedAt   time.Time `json:"friended_at"`
	AcceptedAt   time.Time `json:"accepted_at"`
}

type Game

type Game struct {
	GameID              int64         `json:"game_id"`
	Status              string        `json:"status"`
	CreatedBy           int64         `json:"created_by"`
	NumberOfPlayers     int32         `json:"number_of_players"`
	CurrentTurn         int32         `json:"current_turn"`
	CurrentPlayerNumber sql.NullInt32 `json:"current_player_number"`
	StartTime           time.Time     `json:"start_time"`
	LastActionTime      sql.NullTime  `json:"last_action_time"`
	EndTime             sql.NullTime  `json:"end_time"`
}

Represents a game session

type GameDeck

type GameDeck struct {
	GameDeckID int64 `json:"game_deck_id"`
	GameID     int64 `json:"game_id"`
	CardID     int64 `json:"card_id"`
	OrderIndex int32 `json:"order_index"`
}

type GameInvitation

type GameInvitation struct {
	GameInvitationID int64     `json:"game_invitation_id"`
	InviterPlayerID  int64     `json:"inviter_player_id"`
	InviteePlayerID  int64     `json:"invitee_player_id"`
	GameID           int64     `json:"game_id"`
	InvitationStatus string    `json:"invitation_status"`
	Timestamp        time.Time `json:"timestamp"`
}

type GetGameByPlayerGameIDRow

type GetGameByPlayerGameIDRow struct {
	GameID              int64         `json:"game_id"`
	Status              string        `json:"status"`
	CreatedBy           int64         `json:"created_by"`
	NumberOfPlayers     int32         `json:"number_of_players"`
	CurrentTurn         int32         `json:"current_turn"`
	CurrentPlayerNumber sql.NullInt32 `json:"current_player_number"`
	StartTime           time.Time     `json:"start_time"`
	LastActionTime      sql.NullTime  `json:"last_action_time"`
	EndTime             sql.NullTime  `json:"end_time"`
	PlayerGameID        int64         `json:"player_game_id"`
	PlayerID            int64         `json:"player_id"`
	GameID_2            int64         `json:"game_id_2"`
	PlayerNumber        sql.NullInt32 `json:"player_number"`
	PlayerScore         int32         `json:"player_score"`
	PlayerStatus        string        `json:"player_status"`
}

type GetGameScoresRow

type GetGameScoresRow struct {
	ID          int64  `json:"id"`
	Username    string `json:"username"`
	PlayerScore int32  `json:"player_score"`
}

type GetPlayerHandRow

type GetPlayerHandRow struct {
	PlayerHandID int64  `json:"player_hand_id"`
	PlayerGameID int64  `json:"player_game_id"`
	CardID       int64  `json:"card_id"`
	Name         string `json:"name"`
}

type InsertActivationTokenParams

type InsertActivationTokenParams struct {
	UserID          int64     `json:"user_id"`
	ActivationToken string    `json:"activation_token"`
	ExpiresAt       time.Time `json:"expires_at"`
}

type InsertIntoGameDeckParams

type InsertIntoGameDeckParams struct {
	GameID     int64 `json:"game_id"`
	CardID     int64 `json:"card_id"`
	OrderIndex int32 `json:"order_index"`
}

type IsCardInPlayerHandParams

type IsCardInPlayerHandParams struct {
	PlayerGameID int64 `json:"player_game_id"`
	CardID       int64 `json:"card_id"`
}

type IsUserGameCreatorParams

type IsUserGameCreatorParams struct {
	CreatedBy int64 `json:"created_by"`
	GameID    int64 `json:"game_id"`
}

type ListActiveGamesParams

type ListActiveGamesParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListActivePlayerGamesRow

type ListActivePlayerGamesRow struct {
	PlayerGameID        int64         `json:"player_game_id"`
	PlayerID            int64         `json:"player_id"`
	GameID              int64         `json:"game_id"`
	NumberOfPlayers     int32         `json:"number_of_players"`
	PlayerNumber        sql.NullInt32 `json:"player_number"`
	PlayerScore         int32         `json:"player_score"`
	PlayerStatus        string        `json:"player_status"`
	Status              string        `json:"status"`
	CreatedBy           int64         `json:"created_by"`
	CurrentTurn         int32         `json:"current_turn"`
	CurrentPlayerNumber sql.NullInt32 `json:"current_player_number"`
}

type ListGamePlayersParams

type ListGamePlayersParams struct {
	GameID int64 `json:"game_id"`
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListPendingFriendRequestsRow

type ListPendingFriendRequestsRow struct {
	ID           int64     `json:"id"`
	Username     string    `json:"username"`
	FriendshipID int64     `json:"friendship_id"`
	FriendedAt   time.Time `json:"friended_at"`
}

type ListUserFriendsParams

type ListUserFriendsParams struct {
	FrienderID int64 `json:"friender_id"`
	Limit      int32 `json:"limit"`
	Offset     int32 `json:"offset"`
}

type ListUsersParams

type ListUsersParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type PlayDessertTxParams

type PlayDessertTxParams struct {
	PlayerGameID    int64
	DessertName     string
	Cards           []Card
	SpecialCardUsed bool
	Score           int32
}

type PlayedCard

type PlayedCard struct {
	PlayedCardID int64     `json:"played_card_id"`
	PlayerGameID int64     `json:"player_game_id"`
	CardID       int64     `json:"card_id"`
	PlayTime     time.Time `json:"play_time"`
}

type PlayerGame

type PlayerGame struct {
	PlayerGameID int64         `json:"player_game_id"`
	PlayerID     int64         `json:"player_id"`
	GameID       int64         `json:"game_id"`
	PlayerNumber sql.NullInt32 `json:"player_number"`
	PlayerScore  int32         `json:"player_score"`
	PlayerStatus string        `json:"player_status"`
}

Associates users with their game sessions and tracks their progress

type PlayerHand

type PlayerHand struct {
	PlayerHandID int64 `json:"player_hand_id"`
	PlayerGameID int64 `json:"player_game_id"`
	CardID       int64 `json:"card_id"`
}

type PlayerTurnAction

type PlayerTurnAction struct {
	PlayerGameID      int64 `json:"player_game_id"`
	CardDrawn         bool  `json:"card_drawn"`
	DessertPlayed     bool  `json:"dessert_played"`
	SpecialCardPlayed bool  `json:"special_card_played"`
}

type Querier

type Querier interface {
	AcceptFriendRequest(ctx context.Context, arg AcceptFriendRequestParams) error
	AcceptGameInvitation(ctx context.Context, arg AcceptGameInvitationParams) error
	ActivateUser(ctx context.Context, id int64) error
	AddCardToPlayerHand(ctx context.Context, arg AddCardToPlayerHandParams) (int64, error)
	AddPlayerToGame(ctx context.Context, arg AddPlayerToGameParams) error
	BlockSession(ctx context.Context, id uuid.UUID) error
	// Checks if all actions for a turn are completed for a player
	CheckAllActionsCompleted(ctx context.Context, playerGameID int64) (sql.NullBool, error)
	// Checks if draw card action for a turn has been completed for a player
	CheckCardDrawn(ctx context.Context, playerGameID int64) (bool, error)
	// Checks if play dessert card action for a turn has been completed for a player
	CheckDessertPlayed(ctx context.Context, playerGameID int64) (bool, error)
	// Checks if play special card action for a turn has been completed for a player
	CheckSpecialCardPlayed(ctx context.Context, playerGameID int64) (bool, error)
	CreateFriendship(ctx context.Context, arg CreateFriendshipParams) (Friend, error)
	CreateGame(ctx context.Context, createdBy int64) (Game, error)
	CreateGameInvitationWithUsername(ctx context.Context, arg CreateGameInvitationWithUsernameParams) error
	CreatePlayerTurnActions(ctx context.Context, playerGameID int64) error
	CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)
	CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
	// Declare the winner of the game
	DeclareWinner(ctx context.Context, gameID int64) (DeclareWinnerRow, error)
	DeleteActivationToken(ctx context.Context, userID int64) error
	DeleteFriendship(ctx context.Context, friendshipID int64) error
	DeleteGameInvitation(ctx context.Context, arg DeleteGameInvitationParams) error
	DeleteUser(ctx context.Context, id int64) error
	DoesInvitationExist(ctx context.Context, arg DoesInvitationExistParams) (bool, error)
	DrawTopCard(ctx context.Context, gameID int64) (int64, error)
	EndGame(ctx context.Context, gameID int64) error
	GetActivationToken(ctx context.Context, activationToken string) (ActivationToken, error)
	// Get card by ID
	GetCardByID(ctx context.Context, cardID int64) (Card, error)
	// Get card by Name
	GetCardByName(ctx context.Context, name string) (Card, error)
	GetDessertByName(ctx context.Context, name string) (Dessert, error)
	GetDessertIDByName(ctx context.Context, name string) (int64, error)
	GetDessertsPlayedByPlayer(ctx context.Context, playerGameID int64) ([]int64, error)
	GetFriendshipByID(ctx context.Context, friendshipID int64) (Friend, error)
	GetGameByID(ctx context.Context, gameID int64) (Game, error)
	GetGameByPlayerGameID(ctx context.Context, playerGameID int64) (GetGameByPlayerGameIDRow, error)
	GetGameDeck(ctx context.Context, gameID int64) (GameDeck, error)
	GetGameScores(ctx context.Context, gameID int64) ([]GetGameScoresRow, error)
	GetPlayedCards(ctx context.Context, playerGameID int64) ([]PlayedCard, error)
	GetPlayerGame(ctx context.Context, playerGameID int64) (PlayerGame, error)
	GetPlayerHand(ctx context.Context, playerGameID int64) ([]GetPlayerHandRow, error)
	GetSession(ctx context.Context, id uuid.UUID) (Session, error)
	GetUserByEmail(ctx context.Context, email string) (User, error)
	GetUserByID(ctx context.Context, id int64) (User, error)
	GetUserByUsername(ctx context.Context, username string) (User, error)
	InsertActivationToken(ctx context.Context, arg InsertActivationTokenParams) (ActivationToken, error)
	InsertIntoGameDeck(ctx context.Context, arg InsertIntoGameDeckParams) (int64, error)
	IsCardInPlayerHand(ctx context.Context, arg IsCardInPlayerHandParams) (bool, error)
	IsDeckEmpty(ctx context.Context, gameID int64) (bool, error)
	// Check if a player has reached the winning condition
	IsGameWon(ctx context.Context, playerGameID int64) (sql.NullBool, error)
	IsUserGameCreator(ctx context.Context, arg IsUserGameCreatorParams) (bool, error)
	ListActiveGames(ctx context.Context, arg ListActiveGamesParams) ([]Game, error)
	ListActivePlayerGames(ctx context.Context, playerID int64) ([]ListActivePlayerGamesRow, error)
	// List all cards
	ListCardIDs(ctx context.Context) ([]int64, error)
	// List all cards
	ListCards(ctx context.Context) ([]Card, error)
	// List cards by type
	ListCardsByType(ctx context.Context, type_ string) ([]Card, error)
	ListGameInvitationsForUser(ctx context.Context, inviteePlayerID int64) ([]GameInvitation, error)
	ListGamePlayers(ctx context.Context, arg ListGamePlayersParams) ([]PlayerGame, error)
	ListPendingFriendRequests(ctx context.Context, friendeeID int64) ([]ListPendingFriendRequestsRow, error)
	ListPlayerGames(ctx context.Context, playerID int64) ([]PlayerGame, error)
	ListUserFriends(ctx context.Context, arg ListUserFriendsParams) ([]Friend, error)
	ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error)
	RecordDessertPlayed(ctx context.Context, arg RecordDessertPlayedParams) error
	RecordPlayedCard(ctx context.Context, arg RecordPlayedCardParams) error
	RemoveCardFromDeck(ctx context.Context, arg RemoveCardFromDeckParams) error
	RemoveCardFromPlayerHand(ctx context.Context, arg RemoveCardFromPlayerHandParams) error
	// Resets the turn actions for a player after their turn
	ResetTurnActions(ctx context.Context, playerGameID int64) error
	StartGame(ctx context.Context, arg StartGameParams) error
	// Updates the card drawn status for a player
	UpdateCardDrawnStatus(ctx context.Context, playerGameID int64) error
	// Updates the dessert played status for a player
	UpdateDessertPlayedStatus(ctx context.Context, playerGameID int64) error
	UpdateGameState(ctx context.Context, arg UpdateGameStateParams) error
	UpdateGameStatus(ctx context.Context, arg UpdateGameStatusParams) error
	UpdatePlayerNumber(ctx context.Context, arg UpdatePlayerNumberParams) error
	UpdatePlayerScore(ctx context.Context, arg UpdatePlayerScoreParams) (PlayerGame, error)
	UpdatePlayerStatus(ctx context.Context, arg UpdatePlayerStatusParams) error
	// Updates the special card played status for a player
	UpdateSpecialCardPlayedStatus(ctx context.Context, playerGameID int64) error
	UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AcceptFriendRequest

func (q *Queries) AcceptFriendRequest(ctx context.Context, arg AcceptFriendRequestParams) error

func (*Queries) AcceptGameInvitation

func (q *Queries) AcceptGameInvitation(ctx context.Context, arg AcceptGameInvitationParams) error

func (*Queries) ActivateUser

func (q *Queries) ActivateUser(ctx context.Context, id int64) error

func (*Queries) AddCardToPlayerHand

func (q *Queries) AddCardToPlayerHand(ctx context.Context, arg AddCardToPlayerHandParams) (int64, error)

func (*Queries) AddPlayerToGame

func (q *Queries) AddPlayerToGame(ctx context.Context, arg AddPlayerToGameParams) error

func (*Queries) BlockSession

func (q *Queries) BlockSession(ctx context.Context, id uuid.UUID) error

func (*Queries) CheckAllActionsCompleted

func (q *Queries) CheckAllActionsCompleted(ctx context.Context, playerGameID int64) (sql.NullBool, error)

Checks if all actions for a turn are completed for a player

func (*Queries) CheckCardDrawn

func (q *Queries) CheckCardDrawn(ctx context.Context, playerGameID int64) (bool, error)

Checks if draw card action for a turn has been completed for a player

func (*Queries) CheckDessertPlayed

func (q *Queries) CheckDessertPlayed(ctx context.Context, playerGameID int64) (bool, error)

Checks if play dessert card action for a turn has been completed for a player

func (*Queries) CheckSpecialCardPlayed

func (q *Queries) CheckSpecialCardPlayed(ctx context.Context, playerGameID int64) (bool, error)

Checks if play special card action for a turn has been completed for a player

func (*Queries) CreateFriendship

func (q *Queries) CreateFriendship(ctx context.Context, arg CreateFriendshipParams) (Friend, error)

func (*Queries) CreateGame

func (q *Queries) CreateGame(ctx context.Context, createdBy int64) (Game, error)

func (*Queries) CreateGameInvitationWithUsername

func (q *Queries) CreateGameInvitationWithUsername(ctx context.Context, arg CreateGameInvitationWithUsernameParams) error

func (*Queries) CreatePlayerTurnActions

func (q *Queries) CreatePlayerTurnActions(ctx context.Context, playerGameID int64) error

func (*Queries) CreateSession

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)

func (*Queries) DeclareWinner

func (q *Queries) DeclareWinner(ctx context.Context, gameID int64) (DeclareWinnerRow, error)

Declare the winner of the game

func (*Queries) DeleteActivationToken

func (q *Queries) DeleteActivationToken(ctx context.Context, userID int64) error

func (*Queries) DeleteFriendship

func (q *Queries) DeleteFriendship(ctx context.Context, friendshipID int64) error

func (*Queries) DeleteGameInvitation

func (q *Queries) DeleteGameInvitation(ctx context.Context, arg DeleteGameInvitationParams) error

func (*Queries) DeleteUser

func (q *Queries) DeleteUser(ctx context.Context, id int64) error

func (*Queries) DoesInvitationExist

func (q *Queries) DoesInvitationExist(ctx context.Context, arg DoesInvitationExistParams) (bool, error)

func (*Queries) DrawTopCard

func (q *Queries) DrawTopCard(ctx context.Context, gameID int64) (int64, error)

func (*Queries) EndGame

func (q *Queries) EndGame(ctx context.Context, gameID int64) error

func (*Queries) GetActivationToken

func (q *Queries) GetActivationToken(ctx context.Context, activationToken string) (ActivationToken, error)

func (*Queries) GetCardByID

func (q *Queries) GetCardByID(ctx context.Context, cardID int64) (Card, error)

Get card by ID

func (*Queries) GetCardByName

func (q *Queries) GetCardByName(ctx context.Context, name string) (Card, error)

Get card by Name

func (*Queries) GetDessertByName

func (q *Queries) GetDessertByName(ctx context.Context, name string) (Dessert, error)

func (*Queries) GetDessertIDByName

func (q *Queries) GetDessertIDByName(ctx context.Context, name string) (int64, error)

func (*Queries) GetDessertsPlayedByPlayer

func (q *Queries) GetDessertsPlayedByPlayer(ctx context.Context, playerGameID int64) ([]int64, error)

func (*Queries) GetFriendshipByID

func (q *Queries) GetFriendshipByID(ctx context.Context, friendshipID int64) (Friend, error)

func (*Queries) GetGameByID

func (q *Queries) GetGameByID(ctx context.Context, gameID int64) (Game, error)

func (*Queries) GetGameByPlayerGameID

func (q *Queries) GetGameByPlayerGameID(ctx context.Context, playerGameID int64) (GetGameByPlayerGameIDRow, error)

func (*Queries) GetGameDeck

func (q *Queries) GetGameDeck(ctx context.Context, gameID int64) (GameDeck, error)

func (*Queries) GetGameScores

func (q *Queries) GetGameScores(ctx context.Context, gameID int64) ([]GetGameScoresRow, error)

func (*Queries) GetPlayedCards

func (q *Queries) GetPlayedCards(ctx context.Context, playerGameID int64) ([]PlayedCard, error)

func (*Queries) GetPlayerGame

func (q *Queries) GetPlayerGame(ctx context.Context, playerGameID int64) (PlayerGame, error)

func (*Queries) GetPlayerHand

func (q *Queries) GetPlayerHand(ctx context.Context, playerGameID int64) ([]GetPlayerHandRow, error)

func (*Queries) GetSession

func (q *Queries) GetSession(ctx context.Context, id uuid.UUID) (Session, error)

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error)

func (*Queries) GetUserByID

func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error)

func (*Queries) GetUserByUsername

func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error)

func (*Queries) InsertActivationToken

func (q *Queries) InsertActivationToken(ctx context.Context, arg InsertActivationTokenParams) (ActivationToken, error)

func (*Queries) InsertIntoGameDeck

func (q *Queries) InsertIntoGameDeck(ctx context.Context, arg InsertIntoGameDeckParams) (int64, error)

func (*Queries) IsCardInPlayerHand

func (q *Queries) IsCardInPlayerHand(ctx context.Context, arg IsCardInPlayerHandParams) (bool, error)

func (*Queries) IsDeckEmpty

func (q *Queries) IsDeckEmpty(ctx context.Context, gameID int64) (bool, error)

func (*Queries) IsGameWon

func (q *Queries) IsGameWon(ctx context.Context, playerGameID int64) (sql.NullBool, error)

Check if a player has reached the winning condition

func (*Queries) IsUserGameCreator

func (q *Queries) IsUserGameCreator(ctx context.Context, arg IsUserGameCreatorParams) (bool, error)

func (*Queries) ListActiveGames

func (q *Queries) ListActiveGames(ctx context.Context, arg ListActiveGamesParams) ([]Game, error)

func (*Queries) ListActivePlayerGames

func (q *Queries) ListActivePlayerGames(ctx context.Context, playerID int64) ([]ListActivePlayerGamesRow, error)

func (*Queries) ListCardIDs

func (q *Queries) ListCardIDs(ctx context.Context) ([]int64, error)

List all cards

func (*Queries) ListCards

func (q *Queries) ListCards(ctx context.Context) ([]Card, error)

List all cards

func (*Queries) ListCardsByType

func (q *Queries) ListCardsByType(ctx context.Context, type_ string) ([]Card, error)

List cards by type

func (*Queries) ListGameInvitationsForUser

func (q *Queries) ListGameInvitationsForUser(ctx context.Context, inviteePlayerID int64) ([]GameInvitation, error)

func (*Queries) ListGamePlayers

func (q *Queries) ListGamePlayers(ctx context.Context, arg ListGamePlayersParams) ([]PlayerGame, error)

func (*Queries) ListPendingFriendRequests

func (q *Queries) ListPendingFriendRequests(ctx context.Context, friendeeID int64) ([]ListPendingFriendRequestsRow, error)

func (*Queries) ListPlayerGames

func (q *Queries) ListPlayerGames(ctx context.Context, playerID int64) ([]PlayerGame, error)

func (*Queries) ListUserFriends

func (q *Queries) ListUserFriends(ctx context.Context, arg ListUserFriendsParams) ([]Friend, error)

func (*Queries) ListUsers

func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error)

func (*Queries) RecordDessertPlayed

func (q *Queries) RecordDessertPlayed(ctx context.Context, arg RecordDessertPlayedParams) error

func (*Queries) RecordPlayedCard

func (q *Queries) RecordPlayedCard(ctx context.Context, arg RecordPlayedCardParams) error

func (*Queries) RemoveCardFromDeck

func (q *Queries) RemoveCardFromDeck(ctx context.Context, arg RemoveCardFromDeckParams) error

func (*Queries) RemoveCardFromPlayerHand

func (q *Queries) RemoveCardFromPlayerHand(ctx context.Context, arg RemoveCardFromPlayerHandParams) error

func (*Queries) ResetTurnActions

func (q *Queries) ResetTurnActions(ctx context.Context, playerGameID int64) error

Resets the turn actions for a player after their turn

func (*Queries) StartGame

func (q *Queries) StartGame(ctx context.Context, arg StartGameParams) error

func (*Queries) UpdateCardDrawnStatus

func (q *Queries) UpdateCardDrawnStatus(ctx context.Context, playerGameID int64) error

Updates the card drawn status for a player

func (*Queries) UpdateDessertPlayedStatus

func (q *Queries) UpdateDessertPlayedStatus(ctx context.Context, playerGameID int64) error

Updates the dessert played status for a player

func (*Queries) UpdateGameState

func (q *Queries) UpdateGameState(ctx context.Context, arg UpdateGameStateParams) error

func (*Queries) UpdateGameStatus

func (q *Queries) UpdateGameStatus(ctx context.Context, arg UpdateGameStatusParams) error

func (*Queries) UpdatePlayerNumber

func (q *Queries) UpdatePlayerNumber(ctx context.Context, arg UpdatePlayerNumberParams) error

func (*Queries) UpdatePlayerScore

func (q *Queries) UpdatePlayerScore(ctx context.Context, arg UpdatePlayerScoreParams) (PlayerGame, error)

func (*Queries) UpdatePlayerStatus

func (q *Queries) UpdatePlayerStatus(ctx context.Context, arg UpdatePlayerStatusParams) error

func (*Queries) UpdateSpecialCardPlayedStatus

func (q *Queries) UpdateSpecialCardPlayedStatus(ctx context.Context, playerGameID int64) error

Updates the special card played status for a player

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type RecordDessertPlayedParams

type RecordDessertPlayedParams struct {
	PlayerGameID int64 `json:"player_game_id"`
	DessertID    int64 `json:"dessert_id"`
}

type RecordPlayedCardParams

type RecordPlayedCardParams struct {
	PlayerGameID int64 `json:"player_game_id"`
	CardID       int64 `json:"card_id"`
}

type RegisterTxResult

type RegisterTxResult struct {
	User User `json:"user"`
}

type RemoveCardFromDeckParams

type RemoveCardFromDeckParams struct {
	GameID int64 `json:"game_id"`
	CardID int64 `json:"card_id"`
}

type RemoveCardFromPlayerHandParams

type RemoveCardFromPlayerHandParams struct {
	PlayerGameID int64 `json:"player_game_id"`
	CardID       int64 `json:"card_id"`
}

type SQLStore

type SQLStore struct {
	*Queries
	// contains filtered or unexported fields
}

SQLStore provides all functions to execute SQL queries and transactions

func (*SQLStore) DrawCard

func (store *SQLStore) DrawCard(ctx context.Context, arg DrawCardTxParams) (DrawCardTxResult, error)

DrawCard draws the top card from the deck for a given game.

func (*SQLStore) EndTurnTx

func (store *SQLStore) EndTurnTx(ctx context.Context, gameID int64, playerGameID int64) (EndTurnTxResult, error)

EndTurnTx ends the current turn and updates the game to the next turn

func (*SQLStore) InitializeDeck

func (store *SQLStore) InitializeDeck(ctx context.Context, gameID int64, cardIDs []int64) (int64, error)

InitializeDeck initializes the deck for a game.

func (*SQLStore) PlayDessertTx

func (store *SQLStore) PlayDessertTx(ctx context.Context, arg PlayDessertTxParams) (PlayerGame, error)

Handles the database transactions related to playing a dessert

func (*SQLStore) RefreshPlayerPantryTx

func (store *SQLStore) RefreshPlayerPantryTx(ctx context.Context, playerGameID int64, cardID int64) error

RefreshPlayerHand discards the player's hand and draws the same number of new cards.

func (*SQLStore) RegisterTx

func (store *SQLStore) RegisterTx(ctx context.Context, arg CreateUserParams) (RegisterTxResult, error)

RegisterTx performs a new user registration. It creates a new user only, so there is no reason to actually use this besides getting practice for now, and adding new multi-operation database transaction features later **RegisterTxResult is also rather useless for now, but will be useful when we have actual transcations occuring.

func (*SQLStore) StartGameTx

func (store *SQLStore) StartGameTx(ctx context.Context, arg StartGameTxParams) (StartGameTxResult, error)

StartGameTx starts a game and initializes the deck in a transaction

func (*SQLStore) StealRandomCardFromPlayerTx

func (store *SQLStore) StealRandomCardFromPlayerTx(ctx context.Context, playerGameID int64, cardID int64) (StealRandomCardFromPlayerTxResult, error)

type Session

type Session struct {
	ID           uuid.UUID `json:"id"`
	Username     string    `json:"username"`
	RefreshToken string    `json:"refresh_token"`
	UserAgent    string    `json:"user_agent"`
	ClientIp     string    `json:"client_ip"`
	IsBlocked    bool      `json:"is_blocked"`
	ExpiresAt    time.Time `json:"expires_at"`
	CreatedAt    time.Time `json:"created_at"`
}

type StartGameParams

type StartGameParams struct {
	NumberOfPlayers int32 `json:"number_of_players"`
	GameID          int64 `json:"game_id"`
}

type StartGameTxParams

type StartGameTxParams struct {
	GameID    int64   `json:"game_id"`
	CreatedBy int64   `json:"created_by"`
	PlayerIDs []int64 `json:"player_ids"`
	CardIDs   []int64 `json:"card_ids"`
}

StartGameTxParams holds parameters for the StartGameTx function

type StartGameTxResult

type StartGameTxResult struct {
	Game Game `json:"game"`
}

StartGameTxResult holds the result for the StartGameTx function

type StealRandomCardFromPlayerTxResult

type StealRandomCardFromPlayerTxResult struct {
	TargetPlayerID int64 `json:"target_player_id"`
	StolenCardID   int64 `json:"stolen_card_id"`
}

type Store

type Store interface {
	Querier
	RegisterTx(ctx context.Context, arg CreateUserParams) (RegisterTxResult, error)
	StartGameTx(ctx context.Context, arg StartGameTxParams) (StartGameTxResult, error)
	InitializeDeck(ctx context.Context, gameID int64, cardIDs []int64) (int64, error)
	DrawCard(ctx context.Context, arg DrawCardTxParams) (DrawCardTxResult, error)
	PlayDessertTx(ctx context.Context, arg PlayDessertTxParams) (PlayerGame, error)
	RefreshPlayerPantryTx(ctx context.Context, playerGameID int64, cardID int64) error
	StealRandomCardFromPlayerTx(ctx context.Context, playerGameID int64, cardID int64) (StealRandomCardFromPlayerTxResult, error)
	EndTurnTx(ctx context.Context, gameID int64, playerGameID int64) (EndTurnTxResult, error)
}

Store provides all functions to execure db queries and transactions Uses composition and extending the functionality of queries for single db operations

func NewStore

func NewStore(db *sql.DB) Store

NewStore creates a new Store

type UpdateGameStateParams

type UpdateGameStateParams struct {
	GameID              int64         `json:"game_id"`
	CurrentTurn         int32         `json:"current_turn"`
	CurrentPlayerNumber sql.NullInt32 `json:"current_player_number"`
}

type UpdateGameStatusParams

type UpdateGameStatusParams struct {
	Status string `json:"status"`
	GameID int64  `json:"game_id"`
}

type UpdatePlayerNumberParams

type UpdatePlayerNumberParams struct {
	PlayerNumber sql.NullInt32 `json:"player_number"`
	PlayerGameID int64         `json:"player_game_id"`
}

type UpdatePlayerScoreParams

type UpdatePlayerScoreParams struct {
	PlayerScore  int32 `json:"player_score"`
	PlayerGameID int64 `json:"player_game_id"`
}

type UpdatePlayerStatusParams

type UpdatePlayerStatusParams struct {
	PlayerStatus string `json:"player_status"`
	PlayerGameID int64  `json:"player_game_id"`
}

type UpdateUserParams

type UpdateUserParams struct {
	Email             sql.NullString `json:"email"`
	Password          []byte         `json:"password"`
	PasswordChangedAt sql.NullTime   `json:"password_changed_at"`
	Username          string         `json:"username"`
}

type User

type User struct {
	ID                int64     `json:"id"`
	Username          string    `json:"username"`
	Email             string    `json:"email"`
	Password          []byte    `json:"password"`
	Activated         bool      `json:"activated"`
	PasswordChangedAt time.Time `json:"password_changed_at"`
	CreatedAt         time.Time `json:"created_at"`
	TotalScore        int32     `json:"total_score"`
	TotalWins         int32     `json:"total_wins"`
	TotalLosses       int32     `json:"total_losses"`
}

Stores user account information

Jump to

Keyboard shortcuts

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