Skip to content

Controller

Rob Bronson edited this page Jun 7, 2022 · 5 revisions

Controller

The controller for this app sits between the frontend and the backend. Its purpose is to provide functions that make an HTTP request to the backend API. It receives response data, formats it into proper models, and sends those models to the frontend.

Current State

Currently, the controller has a basic setup that can make a call to a dummy API and convert the return data into a "Book" object which is then returned.
The controller has placeholder functions for additional functionality, including full CRUD operation:

  • login
  • sign up
  • add a book
  • edit a book
  • delete a book
  • update user info
  • delete a user

The Book and User models have been defined in the code, and the Codable interface has been implemented.
The current Book model is set up to accept the data provided by the dummy API. The code to match the expected API schema is there for future use, but is commented out.

Moving Forward (aka Product Backlog)

The next steps to take are:

  1. Implementing the registration and login functions. The backend API is already set up for these routes.
  • login request format:
#header
x-api-key: <api key given for backend>
#body
{ 
  "username": "name@email.com",
  "password": "abc123"
}
  • login response format:
{
  "user": {
      "username": "name@email.com",
      "name": "name"
  },
  "token": "abc...xyz"
}
  • register (sign up) request format:
#header
 x-api-key: <api key given for backend>
#body
{
    "name": "name",
    "email": "name@email.com",
    "username": "name@email.com",
    "password": "abc123"
}
  • register (sign up) response format:
{
    "username": "bob@email.com"
}
  1. When the get books functionality is fully implemented in the API, adjust the existing get books function to use the proper model schema, and change the API URL appropriately.
  2. As the backend gets additional routes set up, build out the code of the remaining CRUD functions.
Clone this wiki locally