-
Notifications
You must be signed in to change notification settings - Fork 256
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 First Commit #43
base: main
Are you sure you want to change the base?
Conversation
pom.xml
Outdated
<dependency> | ||
<groupId>com.mysql</groupId> | ||
<artifactId>mysql-connector-j</artifactId> | ||
<version>8.1.0</version> |
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.
let spring to manage version
<version>8.1.0</version> |
private static RickAndMortyClient rickAndMortyClient; | ||
private static CharacterService characterService; | ||
|
||
@Autowired | ||
public Application(CharacterService service, RickAndMortyClient client) { | ||
Application.rickAndMortyClient = client; | ||
Application.characterService = service; | ||
} |
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.
Application is responsible for booting your app.
Not for the characterService.saveAll(characters);
SRP violates here.
Consider using CommanLineRunner or ApplicationRunner.
private static RickAndMortyClient rickAndMortyClient; | |
private static CharacterService characterService; | |
@Autowired | |
public Application(CharacterService service, RickAndMortyClient client) { | |
Application.rickAndMortyClient = client; | |
Application.characterService = service; | |
} |
|
||
@Operation(summary = "Get random character", | ||
description = "Get a random characters from Rick and Morty world") | ||
@GetMapping("/random") |
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.
REST URI convention violates here.
@GetMapping("/random") | |
@GetMapping |
|
||
@Operation(summary = "Search characters", | ||
description = "Search characters by name") | ||
@GetMapping("/search") |
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.
Recall the REST URI convention.
@GetMapping("/search") | |
@GetMapping |
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository |
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.
@repository is redundant here.
@Repository |
private final ObjectMapper objectMapper; | ||
|
||
public List<CharacterResponseDto> getCharacters() { | ||
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.
Make HttpClient the spring bean.
It shouldnt be created every method invokation.
HttpClient httpClient = HttpClient.newHttpClient(); | |
HttpClient httpClient = HttpClient.newHttpClient(); |
.readValue(response.body(), ListCharacterDto.class); | ||
return listCharacterDto.getResults(); | ||
} catch (IOException | InterruptedException e) { | ||
throw new RuntimeException(e); |
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.
Add method description here.
throw new RuntimeException(e); | |
throw new RuntimeException(e); |
@Service | ||
public class CharacterServiceImpl implements CharacterService { | ||
private int listSize; | ||
private final Random random = new Random(); |
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.
We are using spring, so such instantiations is bad practice.
COnsider making random the spring bean.
private final Random random = new Random(); | |
private final Random random = new Random(); |
spring.datasource.username=root | ||
spring.datasource.password=Romaxa051979 | ||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect |
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.
Is it required property? if not should be removed
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect | |
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect |
@@ -1,13 +1,8 @@ | |||
package mate.academy.rickandmorty; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
|
|||
@SpringBootTest | |||
class ApplicationTests { |
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.
empty class should be removed.
or write the tests.
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
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.
almost good
|
||
@Bean | ||
public CommandLineRunner commandLineRunnerBean() { | ||
|
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.
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class RandomUtil { |
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 class RandomUtil { | |
public class RandomConfiguration { |
Random util() { | ||
return new Random(); | ||
} |
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.
Random util() { | |
return new Random(); | |
} | |
public Random random() { | |
return new Random(); | |
} |
@@ -1,13 +1,8 @@ | |||
package mate.academy.rickandmorty; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
|
|||
@SpringBootTest | |||
class ApplicationTests { |
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
No description provided.