I'm having trouble solving this problem here that was sent to me as an exercise
Create a vehicle registration Rest API to store the vehicles used by the company. The register must contain the following data:
- Name
- brand
- model
- Manufacturing date
- Average fuel consumption within the city (KM/L)
- Average fuel consumption on highways (KM/L)
Create an API to perform the expense forecast calculation. It should receive the following information as a parameter:
- gasoline price R$
- Total km that will be traveled within the city
- Total km to be traveled on highways
The return must be a ranked list of company vehicles taking into account consideration of the amount spent on fuel
I'm having difficulty in how to add an "expense", then calculate this expense according to the variables, associate this expense with the foreign key, and finally show this expense.
This is the database (By the way, it is in Brazilian Portuguese): car database
What I managed to do so far in the code was this: https://github.com/LuizMafraJNR/fluigcclean-api-0.0.1
If anyone can really help me, because I'm racking my brains and can't find proper ways to solve this, I'm still learning Spring boot and API creations, so I need someone to enlighten me
I will give an example of entry in the registration of a vehicle { "name":"Jetta", "brand":"Volkswagen", "model":"GLI", "dateManufacture":"12/12/2021", "ConsumoMedioCidade":10.9, "ConsumoMedioRodovia":14.7, }
So far so good, but now I want to register a "Spend" on this vehicle that I registered. I made the foreign key already linked to the primary key of the Car class, but I want to understand how to register an expense by selecting the vehicle ID.
After registering this expense in the vehicle I selected, I want to calculate it following these parameters
valorGasto = ((kmRodadosCidade /consumoMedioCidade) + (kmRodadosRodovia/consumoRodovia)) * valorGasolina
The parameter valorGasto is from the database, that is, I want it to take these values from the database, calculate and return in this column and then make an endpoint to show the expense of this vehicle.