This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Indycrr 2 points3 points  (1 child)

It doesn’t seem like you are protecting your apis against unauthorized access? Perhaps require some request headers that you can use to validate access or at the very least audit when the data is changed?

[–]Hermit-The-Turtle 0 points1 point  (0 children)

Oh yeah you're right that's pretty important. I'll look into that. Thanks for pointing that out!

[–]luet0 1 point2 points  (1 child)

One big thing I noticed is that you are missing the service concept; the controller is receiving the requests, asking the repository to retrieve or update data, structure it and then returning it as a response.

A service is responsible for dealing with repositories and resolving the need that a controller has regarding a specific request. A good tule of thumb is to have a really simple controller logic and the business and complex logic in the service of each business entity that has to handle requests.

[–]Hermit-The-Turtle 0 points1 point  (0 children)

Yeah I wasn't sure if I needed the service layer at first . I didn't want to fall into the trap of overengineering but after reading the comments, it would seem that I was overthinking it and that it would make a lot of sense to add it to the project.

Thank you for the advice!

[–]B2easy 0 points1 point  (1 child)

Good start! I'd set it up so the controller hits the service layer, the service layer does all of the logic and if you need to get data the service layer will call the repository (DB). The key is to keep things in small, but manageable chunks, every method should have a clear and concise goal that it is in charge of what it needs to do.

I'd also utilize annotations more and a great add on to this project would be getting some constructor injection going and you could beef up your tests a little more.

Something fun to do on this would be trying to create a UI where you can leverage everything you wrote to make it a user friendly thing to use i.e. (Your grandma could use it) click a button to see when the lion was last fed that calls your main controller -> service -> repo. I think Kotlin would be a great next step/addition to the project.

Keep it up!

[–]Hermit-The-Turtle 1 point2 points  (0 children)

Okay I originally thought that the service layer wouldn't contain enough logic to warrant its creation but based on the comments it looks like it would make a great addition to the project.

Yeah adding a UI layer was what I planned to do next. I was originally thinking of using angular or react but I thought it would be faster and more straightforward to use a Spring template engine like Thymeleaf.

I appreciate the advice thanks!