ADSP-EcoTrekker-Project / EcoTrekker

3 stars 1 forks source link

Feature/rest api json validation #38

Closed arslanerdemm closed 9 months ago

arslanerdemm commented 9 months ago

18 json validation from rest-api

arslanerdemm commented 9 months ago

apparently I can't add multiple reviewers.. feel free to review @Andy3189 @lierseleow

Andy3189 commented 9 months ago

Validation doesnt work for me:

Verification whether a start and endpoint or a distance is given works.

arslanerdemm commented 9 months ago
  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{}' is valid json but should return error

this is now fixed

  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{"routes":[{"steps":[{"start":"Alexanderplatz","end":"Gesundbrunnnen","vehicle":"U8","distance":-1},{"start":"Gesundbrunnnen","end":"Westhafen","vehicle":"S41","distance":400}]}]}' contains a negative distance, if the field is given, it should be validated too

do I understand it correct, that if the distance is invalid but the start and end location are given, we should still validate the distance, even tho when we could calculate the distance ourselves?

Andy3189 commented 9 months ago
  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{}' is valid json but should return error

this is now fixed

  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{"routes":[{"steps":[{"start":"Alexanderplatz","end":"Gesundbrunnnen","vehicle":"U8","distance":-1},{"start":"Gesundbrunnnen","end":"Westhafen","vehicle":"S41","distance":400}]}]}' contains a negative distance, if the field is given, it should be validated too

do I understand it correct, that if the distance is invalid but the start and end location are given, we should still validate the distance, even tho when we could calculate the distance ourselves?

It makes the most sense to do it here, otherwise we have to do it later. Otherwise we have the headache of having to validate it later and check if start and endpoints and distances have valid values again

arslanerdemm commented 9 months ago
  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{}' is valid json but should return error

this is now fixed

  • curl localhost:8080/v1/calc/co2 -X POST -H "Content-Type: application/json" -d '{"routes":[{"steps":[{"start":"Alexanderplatz","end":"Gesundbrunnnen","vehicle":"U8","distance":-1},{"start":"Gesundbrunnnen","end":"Westhafen","vehicle":"S41","distance":400}]}]}' contains a negative distance, if the field is given, it should be validated too

do I understand it correct, that if the distance is invalid but the start and end location are given, we should still validate the distance, even tho when we could calculate the distance ourselves?

It makes the most sense to do it here, otherwise we have to do it later. Otherwise we have the headache of having to validate it later and check if start and endpoints and distances have valid values again

should work as expected now, could you try again and lemme know? @Andy3189 @lierseleow

Andy3189 commented 9 months ago

Id probably call the error message for no routes something along the lines of request must contain atleast one route, buts its okay

Edit: nvm its good like this

arslanerdemm commented 9 months ago

@lierseleow are you still experiencing the same issue with the curl request?