how to do proper data validation in service? using enum in if condition? and other questions
hey guys. i have a couple of questions about how to better approach some cases. i have this service:
so my questions are:
1. would it be better to throw an excepetion (maybe ArithmeticException) if distance isnt positive. or to just return smth else? for some reason this response looks horrible for me. or maybe im just overthinking?
2. would it be better to check the season with this long and cumbersome if, or would it be better to have enum and check in the if condition, if season falls into an enum. for me enum looks like a cleaner option
3. rn in my db i have items where their distance column is 20 and a couple with 1. so if i do a request where distance is 25, i get nothing. and i want to retrieve all the items, that have less or equal distance of my request distance. i want for spring to do smth like
select ... from items where distance from request >= distance col val in the record
and idk how to do that. i dont even know how to formulate this thing and how to google it. can smb help me out?1 Reply
⌛
This post has been reserved for your question.
Hey @bambyzas! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.