Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

nshtykh
Copy link

@nshtykh nshtykh commented Feb 14, 2024

No description provided.

Copy link

@vovasalyha vovasalyha left a 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() {

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")

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.

Suggested change
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")

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());

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants