Skip to content

Conversation

dlvsn
Copy link

@dlvsn dlvsn commented Oct 30, 2024

No description provided.

@dlvsn
Copy link
Author

dlvsn commented Oct 30, 2024

Mapper doesn't work with < sourceDirectories > src < / sourceDirectories >) in pom.xml

@dlvsn
Copy link
Author

dlvsn commented Oct 31, 2024

Not sure about solution, give some edvice ;)

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Rick&MortyApi", description = "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty description is not very good

Comment on lines 20 to 22
@Operation(summary = "Add random hero", description = """
The request randomly generates a wiki about one character in
the universe the animated series Rick & Morty.""")
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Does this endpoint add a random hero or return a random one?

Comment on lines 33 to 36
@GetMapping("/find")
List<InternalHeroDto> heroesByName(String name) {
return rickAndMortyService.findByName(name);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. You don't use a @PathVariable or @RequestParam, where do you get parameter "name" from?)
Suggested change
@GetMapping("/find")
List<InternalHeroDto> heroesByName(String name) {
return rickAndMortyService.findByName(name);
}
@GetMapping
List<InternalHeroDto> getCharacterByName(@RequestParam String name) {
return rickAndMortyService.findByName(name);
}

@Operation(summary = "Add random hero", description = """
The request randomly generates a wiki about one character in
the universe the animated series Rick & Morty.""")
@GetMapping("/get")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@GetMapping("/get")
@GetMapping("/random")

Comment on lines 24 to 26
public InternalHeroDto rickAndMorty() {
return rickAndMortyService.getRandomCharacter();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You use 2 different names: hero and character for the same thing through all your project. Please, stick to one of them, because it can be confusing


@Override
public ExternalHeroDto getRandomHero(int randomNumber) {
HttpClient httpClient = HttpClient.newHttpClient();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to the constants

return objectMapper
.readValue(response.body(), ExternalHeroDto.class);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add an informative error message

Comment on lines 46 to 47
return objectMapper
.readValue(response.body(), ExternalHeroResponseDto.class).result();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return objectMapper
.readValue(response.body(), ExternalHeroResponseDto.class).result();
return objectMapper
.readValue(response.body(), ExternalHeroResponseDto.class)
.result();

Comment on lines 23 to 24
ExternalHeroDto randomHero = rickAndMortyClient
.getRandomHero(new Random().nextInt(API_COUNT_HEROES));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move Random to the constants

Comment on lines 31 to 38
return rickAndMortyClient
.findHeroesByName(name).stream()
.map(e -> {
Hero entity = heroMapper.toEntity(e);
return heroMapper.toDto(heroRepository.save(entity));
})
.toList();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need always call rickAndMortyClient.findHeroesByName and perform a HTTP call + save the same values in DB (if name is repeated), instead you can load this values from DB

@dlvsn dlvsn requested a review from JJJazl January 6, 2025 15:16
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