Skip to content

Commit

Permalink
Changed Controller and Service
Browse files Browse the repository at this point in the history
  • Loading branch information
GlebPashko committed Sep 16, 2024
1 parent bd3fca8 commit 248aef7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class CharactersController {
private final CharacterService characterService;

@Operation(summary = "Get one random character")
@GetMapping("/randomly")
@GetMapping("/random")
public CharacterEntity randomCharacter() {
return characterService.findRandom();
}

@Operation(summary = "Search characters by name")
@GetMapping("/search")
@GetMapping
public List<CharacterEntity> searchByName(String name) {
return characterService.findByName(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CharacterServiceImpl implements CharacterService {
private final CharactersClient charactersClient;
private final CharacterRepository characterRepository;
private final CharacterMapper characterMapper;
private final Random random = new Random();

@Override
public void saveAll() {
Expand All @@ -34,7 +35,6 @@ public List<CharacterEntity> findByName(String name) {
}

private long getRandomId() {
return new Random().nextLong(characterRepository.count());
return random.nextLong(characterRepository.count());
}
}

0 comments on commit 248aef7

Please sign in to comment.