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

integrated Rick and Morty API #113

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

Conversation

vadymhrnk
Copy link

No description provided.

Copy link

@d1sam d1sam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, but there are some changes that should be done!

}

@GetMapping("/search")
@Operation(summary = "Search characters by name", description = "Search characters by name")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Operation(summary = "Search characters by name", description = "Search characters by name")
@Operation(summary = "Search characters by name", description = "Search characters by name contains ignore case")

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CharacterRepository extends JpaRepository<Character, Long> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public interface CharacterRepository extends JpaRepository<Character, Long> {
@Repository
public interface CharacterRepository extends JpaRepository<Character, Long> {


@Override
public CharacterDto findRandomCharacter() {
Long randomId = random.nextLong(characterRepository.count()) + 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not good idea to get count of characters from db during each findRandomCharacter method call. let's better to get this variable only once

@vadymhrnk vadymhrnk requested a review from d1sam February 14, 2024 13:21

@Override
public CharacterDto findRandomCharacter() {
Long randomId = random.nextLong(characterRepository.count()) + 1;
if (characterCount == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this method could be called by more than one parallel user, so better make characterCount field volatile.

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.

3 participants