Skip to content
Djontleman edited this page Nov 25, 2021 · 5 revisions

About

Welcome to the Moop City Server-Side Project wiki! This wiki contains documentation for the project.

API Endpoints

URL: localhost:8080{+ endpoints below}

Allotments

A class with an x-coordinate (int) and y-coordinate (String), to build a city grid. Allotments can have one building (see further down).

CRUD URL Endpoint Input Output Errors
GET /allotments None A list of all the allotments None
GET /allotments/{id} Desired allotment ID in URL Allotment object Resource Not Found (404) if no allotment with ID
POST /allotments Allotment object None None

Sample Allotment object:

  {
    "id": 1,
    "x_coordinate": 1,
    "y_coordinate": "A"
  }

Buildings

An abstract class with a building name (String), capacity (int) and allotment ID (int). An allotment can only have one building on it. Buildings can either be a house or a workplace. A house and a workplace can have the same ID. These are shown further down.

CRUD URL Endpoint Input Output Errors
GET /buildings None A list of all buildings. The list shows all houses followed by all workplaces None

For sample objects, see either houses or workplaces below.


Houses

A subclass of buildings. Each house has a capacity which shows how many citizens can be assigned to it. Each house is assigned an allotment. An allotment can only have one house/building on it.

CRUD URL Endpoint Input Output Errors
GET /buildings/houses None A list of all the houses None
GET /buildings/houses/{id} Desired house ID in URL House object Resource Not Found (404) if no house with ID
POST /buildings/houses House object. Capacity cannot be null None. Creates house in database Illegal State (500) if allotment not available. Internal Server (500) if capacity is null
DELETE /buildings/houses/{id} Desired house ID in URL None. Deletes house from database Resource Not Found (404) if no house with ID
PUT /buildings/houses/{id} Desired house ID in URL. Property to be updated with updated value. Building name will not be updated if null/has length of 0. Capacity will not be updated if null. Cannot update ID or allotment ID. To update allotment ID, delete house and create a new house. None. Updates house Resource Not Found (404) if no house with ID. Illegal State (500) if no content passed in. Not Modified (304) if nothing would be changed by the update. Illegal State (500) if capacity would be less than citizens assigned to house

Sample House object:

  {
    "id": 1,
    "buildingName": "3 Mansfield Lane",
    "capacity": 131,
    "allotment_id": 1
  }

Workplaces

A subclass of buildings. Each workplace has a capacity which shows how many citizens can be assigned to it. Each workplace is assigned an allotment. An allotment can only have one house/building on it.

CRUD URL Endpoint Input Output Errors
GET /buildings/workplaces None A list of all the workplaces None
GET /buildings/workplaces/{id} Desired workplace ID in URL Workplace object Resource Not Found (404) if no workplace with ID
POST /buildings/workplaces Workplace object. Capacity cannot be null None. Creates workplace in database Illegal State (500) if allotment not available. Internal Server (500) if capacity is null
DELETE /buildings/workplaces/{id} Desired workplace ID in URL None. Deletes workplace from database Resource Not Found (404) if no workplace with ID
PUT /buildings/workplaces/{id} Desired workplace ID in URL. Property to be updated with updated value. Building name will not be updated if null/has length of 0. Capacity will not be updated if null. Cannot update ID or allotment ID. To update allotment ID, delete workplace and create a new workplace. None. Updates workplace Resource Not Found (404) if no workplace with ID. Illegal State (500) if no content passed in. Not Modified (304) if nothing would be changed by the update. Illegal State (500) if capacity would be less than citizens assigned to workplace

Sample Workplace object:

  {
    "id": 2,
    "buildingName": "H&M headquarters",
    "capacity": 10,
    "allotment_id": 10
  }

Citizens

A class with a full name (String), house ID (int) and workplace id (int). Multiple citizens can be assigned to a house and/or workplace. This is the most complicated class.

CRUD URL Endpoint Input Output Errors
GET /citizens None A list of all citizens None
GET /citizens?house_id={id} Desired house ID in URL A list of citizens assigned to house with given ID, empty list if no house with given ID None
GET /citizens?workplace_id={id} Desired workplace ID in URL A list of citizens assigned to workplace with given ID, empty list if no workplace with given ID None
GET /citizens/{id} Desired citizen ID in URL Citizen object Resource Not Found (404) if no citizen with ID
POST /citizens Citizen object. Name cannot be null/have length of 0. Leave house ID/workplace ID null to not assign citizen to house/workplace None. Creates citizen in database Internal Server (500) if name is null/has a length of 0. Internal Server (500) if house/workplace being assigned to is at max capacity. Resource Not Found (404) if house/workplace being assigned to does not exist
DELETE /citizens/{id} Desired citizen ID in URL None. Deletes citizen from database Resource Not Found (404) if no citizen with ID
PUT /citizens/{id} Citizen object. Citizen name will not be updated if null/has length of 0. To set house/workplace ID as null (i.e. make citizen homeless/unemployed), pass in 0. Cannot update ID None. Updates citizen Resource Not Found (404) if no citizen with ID. Internal Server (500) if no content passed in. Not Modified (304) if nothing would be changed by update. Resource Not Found (404) if house/workplace being assigned to does not exist. Internal Server (500) if house/workplace being assigned to is at max capacity

Sample Citizen object:

  {
    "id": 3,
    "fullName": "Hendrik Perryman",
    "house_id": 4,
    "workplace_id": 2
  }

Clone this wiki locally