Skip to content

Latest commit

 

History

History
358 lines (341 loc) · 22.1 KB

README.md

File metadata and controls

358 lines (341 loc) · 22.1 KB

API V1

This is the first version of the backend API for the WIG!T Web Application. You can view the Swagger docs to see more details and test out the routes.

The following are endpoints implemented and the data needed in the JSON payload where applicable, as well as response codes and types.

NB: All routes should carry the prefix /api/v1.

Strong fields are required.

Routes that require sign in carry a star *

Admin routes carry two stars **

Super Admin routes carry three stars ***

GET

  • /products

    Get all products in the database. On success, it will return a 200 response code with a data object which is a list of all product objects in the payload. On failure, it will return a 500 response code and an error string in the payload.
  • /products/{product_id}

    Get a particular product from the database. On success, it will return a 200 response code with a data object in the payload. On failure, it will return a 400 or 500 response code and an error string in the payload.
  • /products/categories/{category}

    Get all products in a given category. trending is a category. On success, it will return a 200 response code with a data object in the payload. This will be a list of all product objects in the given category. On failure, it will return a 400 or 500 response code and an error string in the payload.
  • /products/search/{name}

    Get all products in a given substring `name` in their name. The search is case insensitive. On success, it will return a 200 response code with a data object in the payload. This will be a list of all product objects with the given substring `name`. On failure, it will return a 400 or 500 response code and an error string in the payload.
  • /cart *

    Get all items in the user's cart. On success, it will return a 200 response code with a data object in the payload. This will be a list of all item objects in the user's cart. On failure, it will return a 500 response code and an error string in the payload.
  • /services

    Get a list of all services. On success, it will return a 200 response code with a data object in the payload. This will be a list of all service objects. On failure, it will return a 500 response code and an error string in the payload.
  • /services/{service_id}

    Get a particular service. On success, it will return a 200 response code with a data object in the payload which will be a service object. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /slots

    Get all free slots which are still valid. On success, it will return a 200 response code with a data object in the payload which will be a list of slot objects. On failure, it will return a 500 response code, and an error string in the payload.
  • /orders *

    Get all orders belonging to the current user. On success, it will return a 200 response code with a data object in the payload which will be a list of order objects. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /orders/{order_id} *

    Get a given order with order_id belonging to the current user. On success, it will return a 200 response code with a data object in the payload which will be an order. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /orders/status/{status} *

    Get all orders based on the status for the current user. Values are pending, paid, shipped, delivered, or cancelled. On success, it will return a 200 response code with a data object in the payload which will be a list of orders. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /bookings *

    Get a list of the user's bookings. On success, it will return a 200 response code with a data object in the payload which will be a list of booking objects. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /bookings/{booking_id} *

    Get a specific booking with booking_id belonging to the user. On success, it will return a 200 response code with a data object in the payload which will be a booking object. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/bookings **

    Get a list of all bookings in the database. On success, it will return a 200 response code with a data object in the payload which will be a list of booking objects. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/bookings/{booking_id} **

    Get a specific booking with booking_id. On success, it will return a 200 response code with a data object in the payload which will be a booking object. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/orders **

    Get all orders from the database. On success, it will return a 200 response code with a data object in the payload which will be a list of orders. On failure, it will return a 500 response code, and an error string in the payload.
  • /admin/orders/{order_id} **

    Get an order with given order_id from the database. On success, it will return a 200 response code with a data object in the payload which will be an order. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/orders/status/{status} **

    Get all orders with given status from the database. Values are pending, paid, shipped, delivered, or cancelled. On success, it will return a 200 response code with a data object in the payload which will be a list of orders. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/users/{email}/orders_bookings **

    Get all orders and bookings belonging to the user with given email. On success, it will return a 200 response code with a data object in the payload. The data object will contain orders object which is a list of orders, and bookings object which is a list of bookings. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /super_admin/users/admins ***

    Get all users with admin roles. On success, it will return a 200 response code with a data object in the payload which will be a list of users. On failure, it will return a 500 response code, and an error string in the payload.
  • /super_admin/users/customers ***

    Get all users with customer roles. On success, it will return a 200 response code with a data object in the payload which will be a list of users. On failure, it will return a 500 response code, and an error string in the payload.
  • /super_admin/users/{email} ***

    Get the user with given email. On success, it will return a 200 response code with a data object in the payload. On failure, it will return a 500 response code, and an error string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.

POST

  • /signup

    Sign a user up.
    • email: The new user's email address. Must be unique and between 5 and 45 characters long.
    • password: The user's password. Between 8 and 45 characters.
    • repeat_password: A repeat of the user's password.
    • first_name: The user's first name. Not more than 45 characters.
    • last_name: The user's last name. Not more than 45 characters.
    • address: The user's address. Not more than 255 characters.
    • phone: The user's phone number. Between 8 and 11 characters.
    On success, it will return a 201 response code with a jwt string and a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /signin

    Sign a user with given credentials in.
    • email: The user's email address. Between 5 and 45 characters long.
    • password: The user's password. Between 8 and 45 characters.
    On success, it will return a 200 response code with a jwt string, a msg string, and a user object in the payload. On failure, it will return a 400, 401, or 500 response code, and an error string in the payload.
  • /reset_password

    Send a request to reset password for user with given email.
    • email: The user's email address. Between 5 and 45 characters long.
    On success, it will return a 201 response code with a reset_token string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /cart *

    Add an item to the user's cart.
    • product_id: This is the id of the product to add to cart.
    • quantity: This is the quantity of the product the user wants. An integer. Cannot be 0.
    On success, it will return a 201 response code with a msg string and a data object in the payload. The data is the new item. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /bookings *

    Add a new user booking to the database.
    • slot_id: The id for the slot the user has been booked for.
    • service_id: The id for the service the user has booked.
    On success, it will return a 201 response code with a msg string and a data list of booking objects in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /orders *

    Create a new order for the current user. This order will be made up of all items in cart, so cart cannot be empty.
    • delivery_method: This is a string. Value is either pickup or delivery.
    On success, it will return a 201 response code with a data object in the payload which will be an Order. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/products **

    Add a new product to the database.
    • name: The name of the product. Must be 3 to 45 characters long.
    • description: The details of what the product is. Must be between 3 to 1024 characters long.
    • category: The category the product belong to. Must be 3 to 45 characters long.
    • stock: The quantity of the product in stock. An integer.
    • price: The price of the product. Decimal as a string. Will be rounded up to 2 decimal places.
    • image_url: A link to the product display image. Not longer than 255 characters.
    On success, it will return a 201 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/services **

    Add a new service to the database.
    • name: The name of the service. Must be 3 to 45 characters long.
    • description: The details of what the service is. Must be between 3 to 1024 characters long.
    • price: The price of the service. Decimal as a string. Will be rounded up to 2 decimal places.
    • available: A boolean. Says if the service is currently available or not.
    On success, it will return a 201 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/slots **

    Add a new slot to the database.
    • date_time: This is the date and time for the slot. String value format of a datetime. y/m/d "2006-01-02T15:00:00Z"
    • is_free: A boolean which says if the slot is free or not.
    On success, it will return a 201 response code with a data object in the payload which will be a slot object. On failure, it will return a 400 or 500 response code, and an error string in the payload.

PUT

  • /reset_password

    Send information to reset a password.
    • email: The user's email address. Between 5 and 45 characters long.
    • reset_token: The reset token sent back for that user when a post to this route was made.
    • new_password: The user's new password. Must be 8 to 45 characters long.
    • repeat_new_password: A repeat of the user's new password.
    On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /users/{email} *

    Update the information for the current user with email.
    • email: This is the user's existing email or new email. Between 5 to 45 characters.
    • first_name: This is the existing or new first name of the user. Not empty and not more than 45 characters.
    • last_name: This is the existing or new last_name of the user. Not empty and not more than 45 characters.
    • address: This is the existing or new address of the user. Not empty and not more than 255 characters.
    • phone: This is the existing or new user's phone number. Not empty and between 8 and 11 characters.
    On success, it will return a 200 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /cart/{item_id}/{quantity} *

    Update the quantity of the item with item_id in cart to quantity given in path.
  • /admin/products/{product_id} **

    Update the information for a given product with product_id.
    • name: The name of the product. Must be 3 to 45 characters long.
    • description: The details of what the product is. Must be between 3 to 1024 characters long.
    • category: The category the product belong to. Must be 3 to 45 characters long.
    • stock: The quantity of the product in stock. An integer.
    • price: The price of the product. Decimal as a string. Will be rounded up to 2 decimal places.
    • image_url: A link to the product display image. Not longer than 128 characters.
    On success, it will return a 200 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/services/{service_id} **

    Update the information about a given service with service_id.
    • name: The name of the service. Must be 3 to 45 characters long.
    • description: The details of what the service is. Must be between 3 to 1024 characters long.
    • price: The price of the service. Decimal as a string. Will be rounded up to 2 decimal places.
    • available: A boolean. Says if the service is currently available or not.
    On success, it will return a 200 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/bookings/{booking_id}/{status} **

    This updates the status of a booking. Allowed status' are pending(which is the default), paid, fulfilled, and cancelled. On success, it will return a 200 response code with a msg string and a data object of the booking in the payload. If a service is no longer available at the time of payment, the updated will be rejected. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/orders/{order_id}/{status} **

    Update the status of a given order with order_id. Status value is either pending(which is the default), paid, shipped, delivered, or cancelled. On success, it will return a 200 response code with a msg string and a data object in the payload. If any item in the order is no longer available (in the quantity specified), the status update will be rejected. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /super_admin/users/{email}/{new_role} ***

    Update the role of a user with given email to new_role. Roles are either customer or admin. On success, it will return a 200 response code with a msg string and a data object in the payload which will be the updated user. On failure, it will return a 400 or 500 response code, and an error string in the payload.

DELETE

  • /cart *

    Clear the user's cart. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 500 response code, and an error string in the payload.
  • /cart/{item_id} *

    Delete an item with item_id from the user's cart. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /users/{email} *

    Delete the current user account with email. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/products/{product_id} **

    Delete a product with product_id. On success, it will return a 200 response code with a msg string and a data object in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/services/{service_id} **

    Delete a service from the database. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /admin/slots/{slot_id} **

    Delete a slot from the database. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.
  • /super_admin/users/{email} ***

    Delete the current user account with given email. On success, it will return a 200 response code with a msg string in the payload. On failure, it will return a 400 or 500 response code, and an error string in the payload.

Author

Emmanuel Chee-zaram Okeke