Broken frontend, working backend

- completed backend database migration
- added backend-functions and changed structure
- frontend broken at this moment
pull/15/head
Trivernis 6 years ago
parent 70fa701fda
commit 9b31ac80e0

@ -1,111 +1,162 @@
type BingoMutation { type BingoMutation {
"creates a lobby for a game and returns the lobby id"
createLobby: ID
"joins a lobby and returns the connection" "creates a lobby for a game and returns the lobby"
joinLobby(input: joinLobbyInput): PlayerLobbyConnection createLobby(gridSize: Int = 3): BingoLobby
"creates a game of bingo and returns the game" "lobby mutations"
createGame(input: CreateGameInput!): BingoGame mutateLobby(id: ID!): LobbyMutation
"submit a bingo to the active game session" "sets the username of a player"
submitBingo: BingoGame setUsername(username: String): BingoPlayer
}
"toggle a word (heared or not) on the sessions grid" type LobbyMutation {
toggleWord(input: WordInput!): BingoGrid
"set the username of the current session" "joins the lobby"
setUsername(input: UsernameInput!): BingoUser join: BingoLobby
"recreates the active game to a follow-up" "leaves the lobby"
createFollowupGame: BingoGame leave: Boolean
"sends a message to the current sessions chat" "kicks a player from the lobby"
sendChatMessage(input: MessageInput!): ChatMessage kickPlayer(playerId: ID!): BingoLobby
}
type BingoQuery { "starts a round in a lobby if the user is the admin"
startRound: BingoRound
"sets the new gridsize for the lobby"
setGridSize(gridSize: Int!): BingoLobby
"returns the currently active bingo game" "sets the words of a lobby"
gameInfo(input: IdInput): BingoGame setWords(words: [String]): BingoLobby
"if there is a bingo in the fields." "sends a message to the lobby"
checkBingo: Boolean sendMessage(message: String): ChatMessage
"returns the grid of the active bingo game" "submits bingo"
activeGrid: BingoGrid submitBingo: BingoRound
"submits a click on a word and returns the field"
toggleGridField(location: GridCoordinates!): GridField
} }
type PlayerLobbyConnection { type BingoQuery {
"the id of the player" "returns information about a lobby with a specific id"
playerId: ID! lobby(id: ID!): BingoLobby
"the id of the lobby" "returns information about a player (if no id is set, its the sessions player)"
lobbyId: ID! player(id: ID): BingoPlayer
} }
type BingoGame { type BingoLobby {
"the id of the bingo game" "the id of the lobby"
id: ID! id: ID!
"the words used in the bingo game" "the grid size of the lobby"
words: [String]! gridSize: Int!
"the size of the square-grid" "all players in the lobby"
gridSize: Int players: [BingoPlayer]
"an array of players active in the bingo game" "the admin of the lobby"
players(input: IdInput): [BingoUser] admin: BingoPlayer
# the player-ids that scored a bingo "the active bingo round"
bingos: [String]! currentRound: BingoRound
"if the game has already finished" "all rounds the game had"
finished: Boolean rounds: [BingoRound]
"the id of the followup game if it has been created" "the messages send in the lobby"
followup: ID messages(limit: Int): [ChatMessage!]
"returns the last n chat-messages" "the words used in the lobby"
getMessages(input: MessageQueryInput): [ChatMessage!] words: [BingoWord]
} }
type BingoUser { type BingoPlayer {
"the id of the bingo user" "the id of the player"
id: ID! id: ID!
"the id of the currently active bingo game" "the username of the player"
game: ID
"the name of the user"
username: String username: String
"the grid of the player with the given lobby-id"
grid(lobbyId: ID!): BingoGrid
"the number of wins the user had in the lobby"
wins(lobbyId: ID!): Int
}
type BingoRound {
"the id of the bingo round"
id: ID!
"the winner of the round (if exists)"
winner: BingoPlayer
"start time of the round"
start: String!
"finish time of the round"
finish: String
"the status of the bingo round"
status: RoundStatus
"the lobby of the bingo round"
lobby: BingoLobby
} }
type BingoGrid { type BingoGrid {
"the grid represented as string matrix" "the id of the grid"
wordGrid: [[String]]! id: ID!
"the grid represented as bingo field matrix" "the grid represented as bingo field matrix"
fieldGrid: [[BingoField]]! fields: [GridField]!
"if there is a bingo" "if there is a bingo"
bingo: Boolean bingo: Boolean
"the size of the grid"
size: Int
} }
type BingoField { type GridField {
"the word contained in the bingo field" "the word contained in the bingo field"
word: String word: BingoWord
"if the word was already heared" "if the word was already heared"
submitted: Boolean! submitted: Boolean!
"the base64 encoded word" "the row of the field"
base64Word: String row: Int!
"the column of the field"
column: Int!
}
type BingoWord {
"the id of the word"
id: ID!
"the word itself"
content: String!
"the number of players that heared this word"
heared: Int!
"the lobby where the word is used"
lobby: BingoLobby
"if the word was actually heared"
confirmed: Boolean
} }
type ChatMessage { type ChatMessage {
@ -116,72 +167,33 @@ type ChatMessage {
"the content of the message" "the content of the message"
content: String! content: String!
# the content of the message rendered by markdown-it "the content rendered by markdown-it"
htmlContent: String htmlContent: String
"the type of the message" "the type of the message"
type: MessageType! type: MessageType!
"the username of the sender" "the username of the sender"
username: String author: BingoPlayer
"the lobby where the message was send in"
lobby: BingoLobby
# the time the message was send (in milliseconds) "the time the message was created"
datetime: String! created: String!
} }
# # # #
# input Types # # input Types #
# # # #
input joinLobbyInput { input GridCoordinates {
"the id of the lobby to join"
lobbyId: ID!
}
input CreateGameInput { "the grid row"
row: Int!
"the words used to fill the bingo grid" "the grid column"
words: [String!]! column: Int!
"the size of the bingo grid"
size: Int! = 3
}
input WordInput {
"the normal word string"
word: String
# the base64-encoded word
base64Word: String
}
input UsernameInput {
"the username string"
username: String!
}
input IdInput {
"the id"
id: ID!
}
input MessageInput {
"the message"
message: String!
}
input MessageQueryInput {
"search for a specific id"
id: ID
"get the last n messages"
last: Int = 10
} }
# # # #
@ -193,3 +205,9 @@ enum MessageType {
ERROR ERROR
INFO INFO
} }
enum RoundStatus {
ACTIVE
FINISHED
PAUSED
}

@ -67,12 +67,7 @@
"warn", "warn",
"consistent" "consistent"
], ],
"camelcase": [ "camelcase": "off",
"error",
{
"properties": "always"
}
],
"comma-spacing": [ "comma-spacing": [
"error", "error",
{ {

File diff suppressed because it is too large Load Diff

@ -9,7 +9,8 @@ CREATE TABLE IF NOT EXISTS bingo.players (
CREATE TABLE IF NOT EXISTS bingo.lobbys ( CREATE TABLE IF NOT EXISTS bingo.lobbys (
id serial UNIQUE PRIMARY KEY, id serial UNIQUE PRIMARY KEY,
admin_id serial references bingo.players(id) ON DELETE SET NULL, admin_id serial references bingo.players(id) ON DELETE SET NULL,
grid_size integer DEFAULT 3, grid_size integer DEFAULT 3 NOT NULL,
current_round integer,
expire timestamp DEFAULT (NOW() + interval '1 hour' ) expire timestamp DEFAULT (NOW() + interval '1 hour' )
); );
@ -25,33 +26,17 @@ CREATE TABLE IF NOT EXISTS bingo.lobby_players (
CREATE TABLE IF NOT EXISTS bingo.words ( CREATE TABLE IF NOT EXISTS bingo.words (
id serial UNIQUE PRIMARY KEY, id serial UNIQUE PRIMARY KEY,
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE, lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
heared integer DEFAULT 0, heared integer DEFAULT 0 NOT NULL,
content varchar(254) NOT NULL content varchar(254) NOT NULL
); );
-- grids table
CREATE TABLE IF NOT EXISTS bingo.grids (
id serial UNIQUE PRIMARY KEY,
player_id serial references bingo.players(id) ON DELETE CASCADE,
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE
);
-- grids_words table
CREATE TABLE IF NOT EXISTS bingo.grid_words (
grid_id serial references bingo.grids(id) ON DELETE CASCADE,
word_id serial references bingo.words(id) ON DELETE CASCADE,
grid_row integer NOT NULL,
grid_column integer NOT NULL,
PRIMARY KEY (grid_id, word_id)
);
-- messages table -- messages table
CREATE TABLE IF NOT EXISTS bingo.messages ( CREATE TABLE IF NOT EXISTS bingo.messages (
id serial UNIQUE PRIMARY KEY, id serial UNIQUE PRIMARY KEY,
content varchar(255) NOT NULL, content varchar(255) NOT NULL,
player_id serial references bingo.players(id) ON DELETE SET NULL, player_id serial references bingo.players(id) ON DELETE SET NULL,
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE, lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
type varchar(8), type varchar(8) DEFAULT 'USER' NOT NULL,
created timestamp DEFAULT NOW() created timestamp DEFAULT NOW()
); );
@ -60,10 +45,26 @@ CREATE TABLE IF NOT EXISTS bingo.rounds (
id serial UNIQUE PRIMARY KEY, id serial UNIQUE PRIMARY KEY,
start timestamp DEFAULT NOW(), start timestamp DEFAULT NOW(),
finish timestamp, finish timestamp,
status varchar(8) DEFAULT 'undefined', status varchar(8) DEFAULT 'ACTIVE',
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE, lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
winner serial references bingo.players(id) ON DELETE SET NULL winner integer
); );
-- altering -- grids table
ALTER TABLE bingo.lobbys ADD COLUMN IF NOT EXISTS current_round serial references bingo.rounds(id) ON DELETE SET NULL; CREATE TABLE IF NOT EXISTS bingo.grids (
id serial UNIQUE PRIMARY KEY,
player_id serial references bingo.players(id) ON DELETE CASCADE,
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
round_id serial references bingo.rounds(id) ON DELETE CASCADE,
UNIQUE(player_id, lobby_id, round_id)
);
-- grids_words table
CREATE TABLE IF NOT EXISTS bingo.grid_words (
grid_id serial references bingo.grids(id) ON DELETE CASCADE,
word_id serial references bingo.words(id) ON DELETE CASCADE,
grid_row integer NOT NULL,
grid_column integer NOT NULL,
submitted boolean DEFAULT false,
PRIMARY KEY (grid_id, grid_row, grid_column)
);

@ -23,13 +23,13 @@ addPlayer:
# - {String} - the new username of the player # - {String} - the new username of the player
# - {Number} - the id of the player # - {Number} - the id of the player
updatePlayerUsername: updatePlayerUsername:
sql: UPDATE bingo.players SET players.username = $1 WHERE players.id = $2 RETURNING *; sql: UPDATE bingo.players SET username = $1 WHERE id = $2 RETURNING *;
# Selects the username for a player id # Selects the row for a player id
# params: # params:
# - {Number} - the id of the player # - {Number} - the id of the player
getPlayerUsername: getPlayerInfo:
sql: SELECT players.username FROM bingo.players WHERE id = $1; sql: SELECT * FROM bingo.players WHERE id = $1;
# updates the expiration timestamp of the player # updates the expiration timestamp of the player
# params: # params:
@ -55,14 +55,14 @@ updateLobbyExpire:
# - {Number} - the id of the player # - {Number} - the id of the player
# - {Number} - the id of the lobby # - {Number} - the id of the lobby
addPlayerToLobby: addPlayerToLobby:
sql: INSERT INTO bingo.lobby_players (player_id, lobby_id) VALUES ($1, $2); sql: INSERT INTO bingo.lobby_players (player_id, lobby_id) VALUES ($1, $2) RETURNING *;
# removes a player from a lobby # removes a player from a lobby
# params: # params:
# - {Number} - the id of the player # - {Number} - the id of the player
# - {Number} - the id of the lobby # - {Number} - the id of the lobby
removePlayerFromLobby: removePlayerFromLobby:
sql: REMOVE FROM bingo.lobby_players WHERE player_id = $1 AND lobby_id = $2; sql: DELETE FROM bingo.lobby_players WHERE player_id = $1 AND lobby_id = $2;
# returns the entry of the player and lobby # returns the entry of the player and lobby
# params: # params:
@ -71,6 +71,82 @@ removePlayerFromLobby:
getPlayerInLobby: getPlayerInLobby:
sql: SELECT * FROM bingo.lobby_players lp WHERE lp.player_id = $1 AND lp.lobby_id = $2; sql: SELECT * FROM bingo.lobby_players lp WHERE lp.player_id = $1 AND lp.lobby_id = $2;
# returns all players in a lobby
# params:
# - {Number} - the id of the lobby
getLobbyPlayers:
sql: SELECT * FROM bingo.lobby_players WHERE lobby_players.lobby_id = $1;
# returns all direct information about the lobby
# params:
# - {Number} - the id of the lobby
getLobbyInfo:
sql: SELECT * FROM bingo.lobbys WHERE lobbys.id = $1;
# returns the last $2 messages for a lobby
# params:
# - {Number} - the id of the lobby
# - {Number} - the limit of messages to fetch
getLobbyMessages:
sql: SELECT * FROM bingo.messages WHERE messages.lobby_id = $1 ORDER BY messages.created DESC LIMIT $2;
# returns the number of wins a user had in a lobby
# - {Number} - the id of the lobby
# - {Number} - the id of the player
getLobbyPlayerWins:
sql: SELECT COUNT(*) wins FROM bingo.rounds WHERE rounds.lobby_id = $1 AND rounds.winner = $2;
# returns all rounds of a lobby
# params:
# - {Number} - the id of the lobby
getLobbyRounds:
sql: SELECT * FROM bingo.rounds WHERE rounds.lobby_id = $1;
# creates a round entry
# params:
# - {Number} - the id of the lobby
addRound:
sql: INSERT INTO bingo.rounds (lobby_id) VALUES ($1) RETURNING *;
# updates the status of a round
# params:
# - {Number} - the id of the round
# - {Number} - the new status
updateRoundStatus:
sql: UPDATE bingo.rounds SET status = $2 WHERE id = $1 RETURNING *;
# updates the status of the round to finished
# params:
# - {Number} - the id of the round
setRoundFinished:
sql: UPDATE bingo.rounds SET status = 'FINISHED', finish = NOW() WHERE id = $1 RETURNING *;
# updates the winner of the round
# params:
# - {Number} - the id of the winner
setRoundWinner:
sql: UPDATE bingo.rounds SET winner = $2 WHERE id = $1 RETURNING *;
# sets the current round of a lobby
# params:
# - {Number} - the id of the lobby
# - {Number} - the id of the round
setLobbyCurrentRound:
sql: UPDATE bingo.lobbys SET current_round = $2 WHERE id = $1 RETURNING *;
# sets the grid size of a lobby
# params:
# - {Number} - the id of the lobby
# - {Number} - the new grid size
setLobbyGridSize:
sql: UPDATE bingo.lobbys SET grid_size = $2 WHERE id = $1 RETURNING *;
# returns information about a round
# params:
# - {Number} - the id of the round
getRoundInfo:
sql: SELECT * FROM bingo.rounds WHERE rounds.id = $1;
# adds a word to the database # adds a word to the database
# params: # params:
# - {Number} - the id of the lobby where the word is used # - {Number} - the id of the lobby where the word is used
@ -78,18 +154,47 @@ getPlayerInLobby:
addWord: addWord:
sql: INSERT INTO bingo.words (lobby_id, content) VALUES ($1, $2) RETURNING *; sql: INSERT INTO bingo.words (lobby_id, content) VALUES ($1, $2) RETURNING *;
# deletes all words of a lobby
# params:
# - {Number} - the id of the lobby
clearLobbyWords:
sql: DELETE FROM bingo.words WHERE lobby_id = $1;
# returns all words for a bingo game (lobby) # returns all words for a bingo game (lobby)
# params: # params:
# - {Number} - the id of the bingo lobby # - {Number} - the id of the bingo lobby
getWordsForLobby: getWordsForLobby:
sql: SELECT * FROM bingo.words WHERE words.lobby_id = $1; sql: SELECT * FROM bingo.words WHERE words.lobby_id = $1;
# returns the word row for an id
# params:
# - {Number} - the id of the word
getWordInfo:
sql: SELECT * FROM bingo.words WHERE words.id = $1;
# adds a grid to the database # adds a grid to the database
# params: # params:
# - {Number} - the id of the player # - {Number} - the id of the player
# - {Number} - the id of the lobby # - {Number} - the id of the lobby
# - {Number} - the id of the round
addGrid: addGrid:
sql: INSERT INTO bingo.grids (player_id, lobby_id) VALUES ($1, $2) RETURNING *; sql: INSERT INTO bingo.grids (player_id, lobby_id, round_id) VALUES ($1, $2, $3) RETURNING *;
# returns the grid entry for a player and lobby id
# params:
# - {Number} - the id of the player
# - {Number} - the id of the lobby
# - {Number} - the id of the round
getGridByPlayerLobbyRound:
sql: SELECT * FROM bingo.grids WHERE player_id = $1 AND lobby_id = $2 AND round_id = $3;
# returns the grid row
# params:
# - {Number} - the id of the grid
getGridInfo:
sql: >
SELECT grids.id, grids.player_id, grids.lobby_id, lobbys.grid_size FROM bingo.grids, bingo.lobbys
WHERE grids.id = $1 AND grids.lobby_id = lobbys.id;
# inserts grid-word connections into the database # inserts grid-word connections into the database
# params: # params:
@ -100,8 +205,37 @@ addGrid:
addWordToGrid: addWordToGrid:
sql: INSERT INTO bingo.grid_words (grid_id, word_id, grid_row, grid_column) VALUES ($1, $2, $3, $4) RETURNING *; sql: INSERT INTO bingo.grid_words (grid_id, word_id, grid_row, grid_column) VALUES ($1, $2, $3, $4) RETURNING *;
# sets a bingo field to submitted = not submitted
# params:
# - {Number} - the id of the grid
# - {Number} - the row of the field
# - {Number} - the column of the field
toggleGridFieldSubmitted:
sql: >
UPDATE bingo.grid_words gw SET submitted = not submitted
WHERE gw.grid_id = $1
AND gw.grid_row = $2
AND gw.grid_column = $3
RETURNING *;
# selects a single field from grid_words
# params:
# - {Number} - the id of the grid
# - {Number} - the row of the field
# - {Number} - the column of the field
getGriedField:
sql: SELECT * FROM bingo.grid_words WHERE grid_words.grid_id = $1 AND grid_words.row = $2 and grid_words.column = $3;
# returns all words for a players grid # returns all words for a players grid
# params: # params:
# - {Number} - the id of the grid # - {Number} - the id of the grid
getWordsForGridId: getWordsForGridId:
sql: SELECT * FROM bingo.grid_words, bingo.words WHERE grid_words.grid_id = $1 AND words.id = grid_words.word_id; sql: SELECT * FROM bingo.grid_words, bingo.words WHERE grid_words.grid_id = $1 AND words.id = grid_words.word_id;
# inserts a user message
# params:
# - {Number} - the id of the user
# - {Number} - the id of the lobby
# - {String} - the content of the message
addUserMessage:
sql: INSERT INTO bingo.messages (player_id, lobby_id, content) VALUES ($1, $2, $3) RETURNING *;

Loading…
Cancel
Save