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

feat: implemented Rick and Morty API integration with MySQL database,… #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PavloMelnyk10
Copy link

… including random character retrieval and name-based search, with Swagger documentation

… including random character retrieval and name-based search, with Swagger documentation
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on implementing the task requirements! 🎉 Your code is well-structured and meets the core functionality needed for the application. While there are minor improvements suggested, such as optimizing the retrieval of random characters and configuring RestTemplate as a bean, these do not hinder the current functionality. Keep up the good work and consider these suggestions for future enhancements! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

public class CharacterServiceImpl implements CharacterService {
private static final String API_URL = "https://rickandmortyapi.com/api/character";
private final CharacterRepository characterRepository;
private final RestTemplate restTemplate = new RestTemplate();

Choose a reason for hiding this comment

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

Consider injecting RestTemplate as a bean instead of instantiating it directly. This allows for better configuration and testing, especially if you need to customize the RestTemplate with interceptors or error handlers.

public CharacterEntity getRandomCharacter() {
long count = characterRepository.count();
int index = random.nextInt((int) count);
return characterRepository.findAll().get(index);

Choose a reason for hiding this comment

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

Using findAll() to retrieve a random character is not efficient for large datasets. Consider using a method that retrieves a random entity directly from the database, such as using a native query or a custom repository method.

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.

2 participants