Skip to content

IsabelG96/capstone_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Art Heist Capstone Project - backend API

Introduction

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:
  1. answer all 10 questions correctly
  2. get 3 questions wrong (3 penalties max)
  3. forfeit the game.

Pre-requisites

Requirements for running back-end game code:

  • 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

Data Structure of project:

The models package consists of 4 POJO classes which are used to define how the classes are mapped to the databaseand 1 ENUM:

  1. A Artwork POJO class for each work properties, including title, rarity level, artist, value etc..
  2. A ArtworkInGame POJO class which tells you the artworks that are being used for each game with properties including stolen, and game_id, artowkr_id
  3. A Game POJO class for the game information
  4. A Player POJO class with properties including: name, list of games
  5. A RarityLevel Enum 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.

UML Diagram

Screenshot 2023-06-19 at 10 05 13

ERD (for database structure)

Screenshot 2023-06-19 at 10 05 34

Installation

  • 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:

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.

Random Artwork Generator

The ArtworkService includes a method entitled generateRandomArtwork which is then used to create the ArtworkInGame objects for each game in the GameService.

  1. First a new empty of Artwork objects is created, artworkList.
  2. Then, the total list of artworks in the repository is called, allArtworks.
  3. The stream method (from java.util) is used to filter artworks by their rarity level enum and collect them to lists by rarity.
  4. After this, the getRandomArtworkSubset method is used to generate a certain number of artworks of each rarity randomly by ID.
  5. These are then added to the artworkList for the game.
  6. 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.

Collaborators

Name: Github Username

  • Kelly Wong: KKLW97
  • Katie Bamford: klb545
  • Hayan Butt: HayanButt
  • Isabel Galwey: IsabelG96
  • Stella Annor: StellaA30

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages