This project is for test assignment for a mid-senior backend developer position.
The project consists of creating a backend application with 3 entities, Carro, Modelo and Marca (names in Portuguese because it is written like that in the modeling).
For the carros query route, it must return a custom json in this format (fully copied, maybe I change somethings... but same pattern!):
{
"carros": [
{
"id": 1,
"timestamp_cadastro": 1696539488,
"modelo_id": 12,
"ano": 2015,
"combustivel": "FLEX",
"num_portas": 4
"cor": "BEGE",
"nome_modelo": "ONIX PLUS",
"valor": 50.000
},
{
"id": 2,
"timestamp_cadastro": 1696531234,
"modelo_id": 14,
"ano": 2014,
"combustivel": "FLEX",
"num_portas": 4
"cor": "AZUL",
"nome_modelo": "JETTA",
"valor": 49.000
},
{
"id": 3,
"timestamp_cadastro": 16965354321,
"modelo_id": 79,
"ano": 1993,
"combustivel": "DIESEL",
"num_portas": 4
"cor": "AZUL",
"nome_modelo": "HILLUX SW4",
"valor": 47.500
}
]
}
In the other routes, as nothing was specified, I implemented it in the way I thought most appropriate.
In total, the application has 15 routes (5 for each entity)
GET hostname:port/api/carros/
GET hostname:port/api/carros/:id
POST hostname:port/api/carros/
PUT hostname:port/api/carros/:id
DELETE hostname:port/api/carros/:id
GET hostname:port/api/modelos/
GET hostname:port/api/models/:id
POST hostname:port/api/modelos/
PUT hostname:port/api/modelos/:id
DELETE hostname:port/api/modelos/:id
GET hostname:port/api/marcas/
GET hostname:port/api/marcas/:id
POST hostname:port/api/marcas/
PUT hostname:port/api/marcas/:id
DELETE hostname:port/api/marcas/:id
The routes are made to carry out CRUD operations, in common we have:
- Route to access all entity records
- Route to access a specific record
- Route to create a new record
- Route to change an existing record
- Route to delete an existing record
Things to note:
-
Errors are handled by Controller Advice
-
There are a pre-insered registers ( just to demonstrate )
-
This use H2database, so it's saved in memory
Routes:
- POST hostname:port/api/carros/
- PUT hostname:port/api/carros/:id
{
"modelo_id": INTEGER,
"ano": INTEGER,
"combustivel": STRING,
"cor": STRING,
"num_portas": INTEGER
}
Routes:
- POST hostname:port/api/modelos/
- PUT hostname:port/api/modelos/:id
{
"nome": STRING,
"valor_fipe": INTEGER,
"marca_id": INTEGER
}
Routes:
- POST hostname:port/api/marcas/
- PUT hostname:port/api/marcas/:id
{
"nome_marca": STRING
}
The errors that the backend currently handles are:
- POST hostname:port/api/carros/
- POST hostname:port/api/modelos/
- POST hostname:port/api/marcas/
- Return 400 When: Client inserts a json that is invalid, informs that that object is invalid and cannot be created.
There are 3 routes:
- GET hostname:port/api/carros/
- GET hostname:port/api/modelos/
- GET hostname:port/api/marcas/
In these 3 routes, no error is returned, if there is no record in the database, a 200 is returned with an empty object.
- GET hostname:port/api/carros/:id
- GET hostname:port/api/models/:id
- GET hostname:port/api/marcas/:id
- Return 404 When: A record with this id does not exist.
- PUT hostname:port/api/carros/:id
- PUT hostname:port/api/modelos/:id
- PUT hostname:port/api/marcas/:id
- Return 404 When: A record with this id does not exist.
- Return 400 when: Client inserts a json that is invalid, informs that that object is invalid!
- DELETE hostname:port/api/carros/:id
- DELETE hostname:port/api/modelos/:id
- DELETE hostname:port/api/marcas/:id
- Return 404 When: A record with this id does not exist.