-
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
Did the task -Rick and Morty- #146
Conversation
+created API with two methods: 1) get randomly character 2) get character by part of name +used public API
|
||
@SpringBootApplication | ||
@ComponentScan("mate.academy.rickandmorty.mapper") |
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 spring application is already scanning this package, so this line is redundant
@ComponentScan("mate.academy.rickandmorty.mapper") |
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.
not fixed, doesn't it work without it?
try { | ||
HttpResponse<String> response = httpClient.send(httpRequest, | ||
HttpResponse.BodyHandlers.ofString()); | ||
CharacterResponseDto dataDto = objectMapper |
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.
CharacterResponseDto dataDto = objectMapper | |
CharacterResponseDto characterDto = objectMapper |
@Setter | ||
@Getter | ||
@ToString | ||
public class InfoResponseDto { |
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 can use @DaTa with Dtos instead of these annotations
@Getter | ||
@ToString | ||
public class InfoResponseDto { | ||
private String nextUrl; |
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.
Have you checked the result? I don't think next
deserializes into nextUrl
private final Random random; | ||
|
||
@Override | ||
public InternalCharacterDto getRandomlyCharacter() { |
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.
@transactional. You make more than one call to DB
@GetMapping("/random") | ||
@Operation(summary = "Get randomly character", description = "Return a character by random id") | ||
public InternalCharacterDto getRandomlyCharacter() { | ||
return characterService.getRandomlyCharacter(); |
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.
return characterService.getRandomlyCharacter(); | |
return characterService.getRandomCharacter(); |
@GetMapping | ||
@Operation(summary = "Filter by the given name", | ||
description = "Returns a list of all characters whose name contains the search string") | ||
public List<InternalCharacterDto> getCharacterByName(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.
public List<InternalCharacterDto> getCharacterByName(String name) { | |
public List<InternalCharacterDto> getCharactersByName(@RequestParam String name) { |
private final ObjectMapper objectMapper; | ||
|
||
@Override | ||
public void getAndSaveCharacters() { |
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.
|
||
@Override | ||
public List<InternalCharacterDto> getCharacterByName(String name) { | ||
return characterRepository.findAllByName(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.
} | ||
|
||
@Override | ||
public List<InternalCharacterDto> getCharacterByName(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.
public List<InternalCharacterDto> getCharacterByName(String name) { | |
public List<InternalCharacterDto> getCharactersByName(String name) { |
+used @DaTa for DTOs +getRandomCharacter -> @transactional now
|
||
@Repository | ||
public interface CharacterRepository extends JpaRepository<Character, Long> { | ||
List<Character> findAllByNameContaining(String partialName); |
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.
List<Character> findAllByNameContaining(String partialName); | |
List<Character> findAllByNameContainingIgnoreCase(String partialName); |
@Override | ||
public void fetchAndSaveCharacters() { | ||
HttpClient httpClient = HttpClient.newHttpClient(); |
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.
renaming to fetch
doesn't help Spring understand that that it should call this method at the beginning of the application bootstrapping. I hope you are familiar with bean's lifecycle, there's a method init(), look up what the annotation in Spring helps you put this method in init() method.
.stream() | ||
.map(characterMapper::toDto) | ||
.collect(Collectors.toList()); |
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.
List<InternalCharacterDto> toDtoList(List<Character> characters)
Iterable<Character> characters = externalCharacterDtoList.stream() | ||
.map(characterMapper::toModel) | ||
.toList(); |
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.
Mapstruct supports mapping collections from the box
} | ||
} while (url != null); | ||
|
||
Iterable<Character> characters = externalCharacterDtoList.stream() |
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.
Iterable<Character> characters = externalCharacterDtoList.stream() | |
List<Character> characters = externalCharacterDtoList.stream() |
+method find all by name now ignore case +fixed some issues
characterRepository.findAllByNameContainingIgnoreCase(partialName)); | ||
|
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.
characterRepository.findAllByNameContainingIgnoreCase(partialName)); | |
characterRepository.findAllByNameContainingIgnoreCase(partialName)); |
|
||
@SpringBootApplication | ||
@ComponentScan("mate.academy.rickandmorty.mapper") |
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.
not fixed, doesn't it work without it?
+created API with two methods:
+used public API