-
Notifications
You must be signed in to change notification settings - Fork 240
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
Created API #133
base: main
Are you sure you want to change the base?
Created API #133
Conversation
@Tag(name = "Character management", description = "Endpoints for managing characters") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/character") |
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.
Better to use plural as endpoint represents that we have collection of characters
@RequestMapping("/character") | |
@RequestMapping("/characters") |
@GetMapping("/by-name") | ||
@Operation(summary = "Get characters by name", | ||
description = "Returns a list of all characters with the given name") | ||
public List<CharacterDto> getCharactersByName(@RequestParam String name) { |
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.
Filtering usually continues getAll operation. So .../characters is getAll and .../characters?name=someName is a filtered option, no need in additional URL suffix like .../characters/by-name?name=someNam
@GetMapping("/by-name") | |
@Operation(summary = "Get characters by name", | |
description = "Returns a list of all characters with the given name") | |
public List<CharacterDto> getCharactersByName(@RequestParam String name) { | |
@GetMapping | |
@Operation(summary = "Get characters by name", | |
description = "Returns a list of all characters with the given name") | |
public List<CharacterDto> getCharactersByName(@RequestParam String name) { |
OriginResponseDto origin, | ||
OriginResponseDto location, | ||
String image, | ||
ArrayList<String> episode, |
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.
No need to use particular List implementation
ArrayList<String> episode, | |
List<String> episode, |
import java.util.ArrayList; | ||
|
||
public record ResultsResponseDataDto( | ||
ArrayList<CharacterResponseDataDto> results, |
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.
ArrayList<CharacterResponseDataDto> results, | |
List<CharacterResponseDataDto> results, |
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class SaveCharacters { |
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.
Verbs shouldn't be used in class names
public class SaveCharacters { | |
public class CharactersInitializer { |
private final RickAndMortyClient rickAndMortyClient; | ||
|
||
@PostConstruct | ||
public void saveCharacters() { |
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.
method doesn't represent full specter of actions it's doing
public void saveCharacters() { | |
public void fetchCharactersToDb() { |
public void saveCharacters() { | ||
List<CharacterResponseDataDto> characterResponseDataDto = | ||
rickAndMortyClient.getCharacters(); | ||
characterService.saveAll(characterResponseDataDto); |
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.
I'd move logic from characterService.saveAll here.
It doesn't seems for me that work with characterResponseDataDto fits rest of methods characterService performs and may perform in future
No description provided.