Skip to content

School's project (REST API development using FastAPI, SQLModel, PostgreSQL)

Notifications You must be signed in to change notification settings

AlexeyGordiychenko/scp_backend_rest_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

Backend Project 2: REST API (Individual project)

The REST API was developed in Python 3.11 using FastAPI, SQLModel and PostgreSQL. Repository pattern was imlemented to access the database. To run the API please refer to README.md

Score:

The final score is 100% (max)

Task

ShopAPI

So, you've decided to open your own store. There's no money for a custom website, so you decided to write everything yourself. A properly written backend will allow you to make a website, desktop, and even mobile applications later. And all of them will receive data from our REST API. Don't forget about foreign keys. Learn the difference between DAL (Data Access Layer) and DTL (Data Transfer Layer) objects.

Store theme: home appliance store.

Pay attention! In the database we implement the relational model! Carefully study the models and design the database model according to normal forms. You will have to learn about normal forms on your own!

There are the following entities:

client
{
    id
    client_name
    client_surname
    birthday
    gender
    registration_date
    address_id
}
product
{
    id
    name
    category
    price
    available_stock // the number of purchased items
    last_update_date // date of the last purchase
    supplier_id
    image_id: UUID
}
supplier
{
    id
    name
    address_id
    phone_number
}
images
{
    id : UUID
    image: bytea
}
address 
{
    id
    country
    city
    street
}

You can create additional entities.

The entities described above must be implemented in a PostgreSQL relational database. The project should use DAO (Data Access Objects) to retrieve data from these tables in repositories.

Important - You need to choose the optimal type in DBMS for storing data (for each field)!

Hint - Use UUID/GUID type for unique identifiers.

You need to implement popular HTTP request types (GET, POST, PUT, DELETE, PATCH).

  • For clients:

    1. Adding a client (receives as input a json corresponding to the structure described from above).
    2. Deleting a client (by its identifier)
    3. Getting clients by first and last name (parameters: first and last name)
    4. Getting all clients (optional pagination parameters in the query string should be provided: limit and offset. If these parameters are missing, return the entire list)
    5. Changing the client's address (parameters: ID and the new address as json according to the format described above)
  • For products:

    1. Adding a product (receives as input a json corresponding to the structure described from above)
    2. Reducing the quantity of goods (parameters: ID of the product and the amount to reduce)
    3. Getting a product by id
    4. Getting all available products
    5. Deleting a product by id
  • For suppliers:

    1. Adding a supplier (receives as input a json corresponding to the structure described from above).
    2. Changing the address of the supplier (parameters: ID of the supplier and the new address as json according to the format described above)
    3. Deleting a supplier by ID
    4. Getting all suppliers
    5. Getting a supplier by ID
  • For images:

    1. Adding an image (parameters: ID of the product and the byte array).
    2. Changing an image (parameters: ID of the image and the new byte array)
    3. Deleting an image by ID
    4. Getting an image of a specific product (by product ID)
    5. Getting an image by image ID

Methods returning an image must return an image (byte array) with "application/octet-stream" header. In this case the file should be automatically loaded.

For each of the described requests, if it's expected to receive data in a body for input, it's necessary to validate the data. In case the validation was unsuccessful - return 400 error code with the message text.

If a request requires data update or a retrieval by ID, it is necessary to return 404 error code with the message text in case of the data absence.

If a request returns a list of data, an empty list should be returned in case of missing data

Mandatory requirements:

  • Full coverage of methods by OpenAPI specification, presence of swagger comments and object examples. The swagger specification should be at

    http://localhost:{YourPort}/swagger/index.html

  • DTOs (Data Transfer Objects) should be used to communicate with the API. To convert one model to another, use mappers. The path to controller methods should start with the prefix

    /api/v1/...

  • API should be designed according to RESTFUL methodology
  • Use database for data storage, implement Repository pattern as a data access layer

About

School's project (REST API development using FastAPI, SQLModel, PostgreSQL)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages