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

First Attempt #201

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

First Attempt #201

wants to merge 2 commits into from

Conversation

jszymanski97
Copy link

No description provided.

Copy link

@George-Khomiak George-Khomiak left a comment

Choose a reason for hiding this comment

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

Rework so you use your DTOs, especially in controller response

Copy link

@slade13 slade13 left a comment

Choose a reason for hiding this comment

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

Good job, please review my comments.


@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/character")
Copy link

Choose a reason for hiding this comment

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

For API design consistency, it would be better to use a plural form '/characters' instead of '/character'.

public class CharacterController {
private final CharacterService characterService;

@GetMapping
Copy link

Choose a reason for hiding this comment

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

The method 'getRandomCharacter' does not have any explicit path. Consider adding an explicit path like '/random' to make it clear this endpoint is for getting a random character.

List<Character> characters = characterMapper.toModelList(characterDtoList);
characterRepository.saveAll(characters);
} catch (IOException | InterruptedException e) {
throw new EntityNotFoundException("Can't access results from external API", e);
Copy link

Choose a reason for hiding this comment

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

EntityNotFoundException is not the appropriate exception to throw when there is an error connecting to the external API. Consider creating a custom exception to handle this scenario.

@RequiredArgsConstructor
public class CharacterInitializer {
@Value("${api.url}")
private String apiUrl;
Copy link

Choose a reason for hiding this comment

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

The 'apiUrl' field should be final. Since we are injecting value from the property file, it should not be changed during runtime.

@NoArgsConstructor
@Table(name = "results")

public class Character {
Copy link

Choose a reason for hiding this comment

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

The class 'Character' might conflict with 'java.lang.Character'. Consider renaming your class to something more specific like 'RickAndMortyCharacter'.

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