-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented getRandom and getAllByNamePart methods #115
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but see a couple of comments.
@Configuration | ||
public class AppConfig { | ||
@Bean | ||
public Random random() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a bean of Random
class. Also, in concurrent environments (web app is concurrent) it's preferred to use ThreadLocalRandom
@RequestMapping("/characters") | ||
@RequiredArgsConstructor | ||
@Tag(name = "Characters management", | ||
description = "Endpoints for managing characters from the Rick and Morty cartoon") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually managing
means that the API allows some creation/modification, but this API is only for read access.
description = "Endpoints for managing characters from the Rick and Morty cartoon") | |
description = "Endpoints for retrieving characters from the Rick and Morty cartoon") |
} | ||
|
||
@GetMapping("/by-name") | ||
@Operation(summary = "Get all characters by name part") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also specify that this search ignores case.
|
||
@Override | ||
public CharacterInternalDto getRandomCharacter() { | ||
long randomId = random.nextLong(characterRepository.count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about optimizing this logic (considering that you save all characters only once on application startup)
No description provided.