-
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
First solution of jv-rick-and-morty #118
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.
Your code doesn't compile successfully - fix it before requesting a review.
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 so far! Make sure to retrieve all the characters, keeping pagination in mind
HttpResponse<String> response = httpClient.send( | ||
request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
return objectMapper.readValue( | ||
response.body(), CharacterResponseDataDto.class); | ||
|
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.
long randomId = random.nextLong(characterRepository.count()); | ||
Character character = characterRepository.findById(randomId) | ||
.orElseThrow(() -> | ||
new RuntimeException("Cannot find a character by id: " + randomId)); |
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 better to throw more specific exceptions where possible, let's go for EntityNotFound or NoSuchElement exception here
@Query(value = "SELECT c FROM Character c WHERE c.name LIKE CONCAT('%', :name, '%')") | ||
List<Character> findAllByNameContainingIgnoreCase(String 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.
Consider removing the @query annotation for this method as Spring Data JPA's query derivation from method names can automatically generate the required query
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.
Few minor comments, good work with the rest :)
@@ -5,7 +5,6 @@ | |||
|
|||
@SpringBootApplication | |||
public class Application { | |||
|
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.
Avoid unnecessary changes in your PRs.
import lombok.Data; | ||
|
||
@Data | ||
public class CharacterExternalResponseDto { |
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 might use record instead of regular class for DTOs. Additionally, you won't require Lombok - @Data
produces lots of boilerplate code.
import lombok.Data; | ||
|
||
@Data | ||
public class CharacterResponseDataDto { |
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.
Same here, you can use record.
void contextLoads() { | ||
} | ||
|
||
@Test |
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.
Unnecessary change.
No description provided.