This is a game where the player has to answer art related multiple choice questions. Based on the rarity level (common, rare or legendary) of the artwork displayed, the randomly generated MCQ can be easy, medium or hard. The rules of the game
- Answer a question right, and steal the artwork and increase your score
- the game ends when you:
- answer all 10 questions correctly
- get 3 questions wrong (3 penalties max)
- forfeit the game.
- Download intellij/VSCode for editing/displaying back-end code (intellij preferrable)
- For Command Line Tools, it's recommended to download:
- Xcode Command line tools (easier terminal control)
- Postgres + SQL(for the Game Database and its language)
- Git (for version control)
- HomeBrew 15.2 (ease of package management)
- Other recommended off-the-web downloads include:
- Java 17 (back-end code language)
- Postman(for the API to mimic the front-end responses and test different API requests)
- Postico (for the viewing of Game database information)
- Using Spring initializr, the recommended dependencies that were incorporated in the back-end code design were:
- Spring Web
- Spring Boot DevTools
- PostgreSQL Driver
- Spring Data JPA
The models package consists of 4 POJO classes which are used to define how the classes are mapped to the databaseand 1 ENUM:
- A
ArtworkPOJO class for each work properties, includingtitle,rarity level,artist,valueetc..- A
ArtworkInGamePOJO class which tells you the artworks that are being used for each game with properties includingstolen, andgame_id,artowkr_id- A
GamePOJO class for the game information- A
PlayerPOJO class with properties including:name, list ofgames- A
RarityLevelEnum for the rarity level of each artwork
The repositories package consists of 4 repositories including ArtworkRepository, ArtworkInRepository, GameRepository, PlayerRepository.
The services package has 4 classes, namely ArtworkInGameService, ArtworkService, PlayerService, GameService to handle game logic.
The controllers package consists of 4 classes PlayerController, GameController, ArtworkInGameController and ArtworkController which enables you to perform different requests corresponding to the CRUD functionalities
The DataLoader in the components package is used to pre-populate the artworks table and added a few players in the database.You may wish to connect to Postico to view/inspect the tables.
-
To run the code, you will need:
Java 17 Postico (for Mac) or pgAdmin (for Windows) for the PostgreSQL database IntelliJ IDEA Postman
-
Follow these steps to install and run the code:
- Clone the repositories to your local machine: git clone from https://github.com/IsabelG96/capstone_backend (backend) and https://github.com/KKLW97/capstone_front_end.
- Create a new database in your terminal called
capstone_backend. - Open the file in IntelliJ IDEA.
- Update the application.properties file with your database credentials.
- Run the `CapstoneBackendApplicatio
| Request | URL path: localhost:8080 | Body | Functionality | Information Returned |
|---|---|---|---|---|
| POST | /players | Object: Player JSON: {
"name": "[insert player name]"
} |
Creates a new player | The Player object that was created. |
| GET | /players | Gets all players. | List of all Player objects which consists of player id, player name, and list of games. |
|
| GET | /players/{id} | Gets the player of the Id specified. | The Player object with the specified Id, which consists of player id, player name, and list of games |
|
| GET | Default: /artworksInGame, For specified game id: /artworksInGame?game_id={gameId}, for specified stolen boolean: /artworksInGame?stolen={true/false}, for both game id and boolean: /artworksInGame?game_id={gameId}&stolen={true/false} |
Gets all artworks in games. | Returns by default List of all ArtworkInGame objects which consists of an id,stolen boolean, game and artwork objects. When with the @RequestParams game_id or stolen boolean, it returns the information based on what is specified in the @RequestParam. For example, if you want all artworks in gamr for game id 1, then write http://localhost:8080/artworksInGame?game_id=1, for all artworks in game that are stolen , write http://localhost:8080/artworksInGame?stolen=true. |
|
| GET | /artworksInGame/{id} | Gets the ArtworkInGame object of the Id specified. | Returns ArtworkInGame object of the specified id, which consists of an id,stolen boolean, game and artwork objects. |
|
| PATCH | /artworksInGame/{id}?stolen={true} | Update the property `stolen` for a specified artork in game by Id. | The artworkInGame object with the specified Id, which consists of an id,stolen boolean, game and artwork objects |
|
| GET | /artworks | Get all artworks. | List of all artwork | |
| GET | /games OR /games?player_id=1 OR /games?complete=false OR /games?player_id=1&complete=false | Gets all games. Option to filter by player id, by complete status, or both. | List of all games | |
| GET | /games/{gameId} | Gets a specific game by its id. | The Game object with the specified id. | |
| POST | /games?playerId=1 | Creates a game for the player of player id passed into the param. | The new Game object that has been created. |
|
| PUT | /games/{gameId} | Object: Game JSON: {
"player": "[insert player name]"
} |
Updates a game of the specified id. | Returns the Game object. |
The ArtworkService includes a method entitled generateRandomArtwork which is then used to create the ArtworkInGame objects for each game in the GameService.
- First a new empty of Artwork objects is created,
artworkList. - Then, the total list of artworks in the repository is called,
allArtworks. - The
streammethod (fromjava.util) is used to filter artworks by their rarity level enum and collect them to lists by rarity. - After this, the
getRandomArtworkSubsetmethod is used to generate a certain number of artworks of each rarity randomly by ID. - These are then added to the
artworkListfor the game. - This then affects the number of easy, medium and hard questions the player will get in each game, as well as the number of points they can win overall.
- Kelly Wong: KKLW97
- Katie Bamford: klb545
- Hayan Butt: HayanButt
- Isabel Galwey: IsabelG96
- Stella Annor: StellaA30

