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

@ -67,12 +67,7 @@
"warn",
"consistent"
],
"camelcase": [
"error",
{
"properties": "always"
}
],
"camelcase": "off",
"comma-spacing": [
"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 (
id serial UNIQUE PRIMARY KEY,
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' )
);
@ -25,33 +26,17 @@ CREATE TABLE IF NOT EXISTS bingo.lobby_players (
CREATE TABLE IF NOT EXISTS bingo.words (
id serial UNIQUE PRIMARY KEY,
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
);
-- 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
CREATE TABLE IF NOT EXISTS bingo.messages (
id serial UNIQUE PRIMARY KEY,
content varchar(255) NOT NULL,
player_id serial references bingo.players(id) ON DELETE SET NULL,
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
type varchar(8),
type varchar(8) DEFAULT 'USER' NOT NULL,
created timestamp DEFAULT NOW()
);
@ -60,10 +45,26 @@ CREATE TABLE IF NOT EXISTS bingo.rounds (
id serial UNIQUE PRIMARY KEY,
start timestamp DEFAULT NOW(),
finish timestamp,
status varchar(8) DEFAULT 'undefined',
status varchar(8) DEFAULT 'ACTIVE',
lobby_id serial references bingo.lobbys(id) ON DELETE CASCADE,
winner serial references bingo.players(id) ON DELETE SET NULL
winner integer
);
-- altering
ALTER TABLE bingo.lobbys ADD COLUMN IF NOT EXISTS current_round serial references bingo.rounds(id) ON DELETE SET 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,
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
# - {Number} - the id of the player
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:
# - {Number} - the id of the player
getPlayerUsername:
sql: SELECT players.username FROM bingo.players WHERE id = $1;
getPlayerInfo:
sql: SELECT * FROM bingo.players WHERE id = $1;
# updates the expiration timestamp of the player
# params:
@ -55,14 +55,14 @@ updateLobbyExpire:
# - {Number} - the id of the player
# - {Number} - the id of the lobby
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
# params:
# - {Number} - the id of the player
# - {Number} - the id of the lobby
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
# params:
@ -71,6 +71,82 @@ removePlayerFromLobby:
getPlayerInLobby:
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
# params:
# - {Number} - the id of the lobby where the word is used
@ -78,18 +154,47 @@ getPlayerInLobby:
addWord:
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)
# params:
# - {Number} - the id of the bingo lobby
getWordsForLobby:
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
# params:
# - {Number} - the id of the player
# - {Number} - the id of the lobby
# - {Number} - the id of the round
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
# params:
@ -100,8 +205,37 @@ addGrid:
addWordToGrid:
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
# params:
# - {Number} - the id of the grid
getWordsForGridId:
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