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
The final score is 100% (max)
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:
- Adding a client (receives as input a json corresponding to the structure described from above).
- Deleting a client (by its identifier)
- Getting clients by first and last name (parameters: first and last name)
- 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)
- Changing the client's address (parameters: ID and the new address as json according to the format described above)
-
For products:
- Adding a product (receives as input a json corresponding to the structure described from above)
- Reducing the quantity of goods (parameters: ID of the product and the amount to reduce)
- Getting a product by id
- Getting all available products
- Deleting a product by id
-
For suppliers:
- Adding a supplier (receives as input a json corresponding to the structure described from above).
- Changing the address of the supplier (parameters: ID of the supplier and the new address as json according to the format described above)
- Deleting a supplier by ID
- Getting all suppliers
- Getting a supplier by ID
-
For images:
- Adding an image (parameters: ID of the product and the byte array).
- Changing an image (parameters: ID of the image and the new byte array)
- Deleting an image by ID
- Getting an image of a specific product (by product ID)
- 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
- 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