-
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
integrated Rick and Morty API #113
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.
Good job, but there are some changes that should be done!
} | ||
|
||
@GetMapping("/search") | ||
@Operation(summary = "Search characters by name", description = "Search characters by name") |
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.
@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> { |
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.
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; |
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.
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
|
||
@Override | ||
public CharacterDto findRandomCharacter() { | ||
Long randomId = random.nextLong(characterRepository.count()) + 1; | ||
if (characterCount == null) { |
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.
Keep in mind that this method could be called by more than one parallel user, so better make characterCount
field volatile.
No description provided.