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

Implemented task #49

Closed
wants to merge 12 commits into from
Closed

Implemented task #49

wants to merge 12 commits into from

Conversation

OlegMR0
Copy link

@OlegMR0 OlegMR0 commented Nov 7, 2023

No description provided.


@Tag(name = "Rick and Morty API")
@RestController
@RequestMapping("/api")
Copy link

Choose a reason for hiding this comment

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

i'd expand path in order to be able to add other endpoints later

Suggested change
@RequestMapping("/api")
@RequestMapping("/api/characters")

Comment on lines 9 to 15
long count();

Character save(Character character);

List<Character> findAll();

Optional<Character> findById(Long id);
Copy link

Choose a reason for hiding this comment

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

these methods are present by default in JpaRepository, no need to duplicate

Suggested change
long count();
Character save(Character character);
List<Character> findAll();
Optional<Character> findById(Long id);

Comment on lines 20 to 24
@PostConstruct
private void init() {
List<Character> characters = client.getCharacters();
repository.saveAll(characters);
}
Copy link

Choose a reason for hiding this comment

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

Please move method to CharacterClientImpl
This service mainly works to process our users' requests and initialization is logically out of this scope

Suggested change
@PostConstruct
private void init() {
List<Character> characters = client.getCharacters();
repository.saveAll(characters);
}

Comment on lines 45 to 46
character.setInternalId(null);
return repository.save(character);
Copy link

Choose a reason for hiding this comment

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

Cannot understand why we reset id and call save for character we just retrieved from DB

Comment on lines 27 to 39
public List<Character> getAll() {
return repository.findAll();
}

@Override
public List<CharacterDto> getCharactersByName(String name) {
List<Character> characters = repository.findByNameContaining(name);
List<CharacterDto> characterDtos = mapper.map(characters);
return characterDtos;
}

@Override
public Character saveRandomCharacter() {
Copy link

Choose a reason for hiding this comment

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

you should unify if you service returns DTOs or models

Comment on lines 23 to 35
public List<Character> getCharacters() {
return characterService.getAll();
}

@Operation(summary = "Find characters by specific name.")
@GetMapping("/search")
public List<CharacterDto> getCharactersByName(String name) {
return characterService.getCharactersByName(name);
}

@Operation(summary = "Generate and save random existing character.")
@GetMapping("/random")
public Character saveRandomCharacter() {
Copy link

Choose a reason for hiding this comment

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

please use dtos and hide internal implementation of classes

@OlegMR0 OlegMR0 requested a review from olekskov November 7, 2023 23:18
Comment on lines +20 to +23
@Operation(summary = "Get all available characters.")
@GetMapping
public List<CharacterDto> getCharacters() {
return characterService.getAll();
Copy link

Choose a reason for hiding this comment

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

Have you ever heard about YAGNI?
image

@OlegMR0 OlegMR0 closed this Dec 13, 2023
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