envelope-zero / backend

Serves the API and contains the application logic
Other
6 stars 3 forks source link

Make required fields required, simplify binding and improve error messages #1073

Open morremeyer opened 2 months ago

morremeyer commented 2 months ago

For fields that need to be set in the API, e.g. the Month field in URIMonth and QueryMonth, thebinding:"required" tag should be set.

Errors on binding should be handled with e.g. a middleware, see https://github.com/gin-gonic/gin/issues/430#issuecomment-141774133 for inspiration.

With this, the parseMonthQuery could probably be removed, too.

There should be only one struct for API responses with the fields data, error and links ideally, so that all responses can be handled in the same way.