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

Rick and Morty solution #152

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

Conversation

VlasenkoYevhenii
Copy link

No description provided.

Copy link

@andrii-hoienko andrii-hoienko 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, but some improvements required

<property name="validateComments" value="true"/>
</module>
</module>
</module>

Choose a reason for hiding this comment

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

Suggested change
</module>
</module>

Comment on lines +36 to +59
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.4.4.Final</version>

Choose a reason for hiding this comment

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

Please be consistent and use properties to define versions

@RequiredArgsConstructor
@Component
public class CharacterClient {
private static final String URL = "https://rickandmortyapi.com/api/character";

Choose a reason for hiding this comment

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

Better to make this value configurable via properties

@Component
public class CharacterClient {
private static final String URL = "https://rickandmortyapi.com/api/character";
@Qualifier("characterMapperImpl")

Choose a reason for hiding this comment

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

What is the reason to add Qualifier?


public List<Character> getAll() throws IOException {
HttpClient httpClient = HttpClient.newHttpClient();
ObjectMapper objectMapper = new ObjectMapper();

Choose a reason for hiding this comment

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

No reason to create objectMapper, bean of this object exists in context

Comment on lines +22 to +23
public Character() {
}

Choose a reason for hiding this comment

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

Please use lombok annotation

Comment on lines +15 to +18
@Override
public List<Character> getAll() {
return List.of();
}

Choose a reason for hiding this comment

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

Is it expected to have empty list here?

Comment on lines +32 to +40
try {
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create(URL))
.build();
HttpResponse<String> response = httpClient.send(request,
HttpResponse.BodyHandlers.ofString());
JsonNode rootNode = objectMapper.readTree(response.body());
resultsNode = rootNode.get("results");

Choose a reason for hiding this comment

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

I suggest to map response object as is, and then on service level extract necessary information and convert to Character object and save to db. This approach will be more flexible and code will be more clear


@Mappings({
@Mapping(target = "externalId", source = "id"),
@Mapping(target = "id", ignore = true) // DB auto-generated ID

Choose a reason for hiding this comment

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

Remove redundant comments

Comment on lines +23 to +25
throw new LoadExternalDataException(
"Failed to load characters from external DB", e);
}

Choose a reason for hiding this comment

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

I believe you already catch case when characters is failed to load in CharacterClient

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