Skip to content

Commit

Permalink
deleted redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemMakovskyy committed Oct 28, 2023
1 parent 1385367 commit e1419bf
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 810 deletions.
5 changes: 2 additions & 3 deletions src/main/java/mate/academy/rickandmorty/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
logger.info("API Documentation Overview link: http://localhost:8080/api/swagger-ui/index.html#/");
logger.info("Get random personality link " + "http://localhost:8080/api/personalities/random");
logger.info("find all link " + "http://localhost:8080/api/personalities");
logger.info("search link " + "http://localhost:8080/api/personalities/search?name=Alien&name=Baby&status=1&gender=0&gender=1");
logger.info("Get random personality link: " + "http://localhost:8080/api/personalities/random");
logger.info("Search link: " + "http://localhost:8080/api/personalities/search?name=Alien&name=Baby");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ public PersonalityDto getRandomPersonality() {
return personalityService.getRandomPersonality();
}

@GetMapping
@Operation(summary = "Get All",
description = "Getting all personalities")
public List<PersonalityDto> getAllPersonalities(
@Operation(summary = "Search characters.",
description = "Search characters by params")
@GetMapping("/search")
public List<PersonalityDto> search(
PersonalitySearchParametersDto params,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String[] sort) {
final Pageable pageable = PageRequest.of(page, size, Sort.by(sort));
return personalityService.getAll(pageable);
}

@Operation(summary = "Search characters.",
description = "Search characters by params")
@GetMapping("/search")
public List<PersonalityDto> search(PersonalitySearchParametersDto params, Pageable pageable) {
return personalityService.search(params,pageable);
return personalityService.search(params, pageable);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package mate.academy.rickandmorty.dto.internal;

public record PersonalitySearchParametersDto(
String[] name,
String[] status,
String[] gender) {
public record PersonalitySearchParametersDto(String[] name) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mate.academy.rickandmorty.repository.personality;

import java.util.List;
import mate.academy.rickandmorty.model.Personality;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
Expand All @@ -12,6 +11,4 @@ public interface PersonalityRepository
@Query(value = "SELECT * FROM personalities p WHERE p.is_deleted "
+ "= false ORDER BY RAND() LIMIT 1", nativeQuery = true)
Personality findRandomPersonality();

List<Personality> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
@RequiredArgsConstructor
public class PersonalitySpecificationBuilderImpl implements SpecificationBuilder<Personality> {
private static final String NAME_KEY = "name";
private static final String STATUS_KEY = "status";
private static final String GENDER_KEY = "gender";

@Autowired
private final SpecificationProviderManager<Personality> personalitySpecificationProviderManager;
Expand All @@ -27,16 +25,6 @@ public Specification<Personality> build(PersonalitySearchParametersDto searchPar
.getSpecificationProvider(NAME_KEY)
.getSpecification(searchParameters.name()));
}
if (searchParameters.status() != null && searchParameters.status().length > 0) {
spec = spec.and(personalitySpecificationProviderManager
.getSpecificationProvider(STATUS_KEY)
.getSpecification(searchParameters.status()));
}
if (searchParameters.gender() != null && searchParameters.gender().length > 0) {
spec = spec.and(personalitySpecificationProviderManager
.getSpecificationProvider(GENDER_KEY)
.getSpecification(searchParameters.gender()));
}
return spec;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public interface PersonalityService {

PersonalityDto getRandomPersonality();

List<PersonalityDto> getAll(Pageable pageable);

List<PersonalityDto> search(PersonalitySearchParametersDto params, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public PersonalityDto getRandomPersonality() {
personalityRepository.findRandomPersonality());
}

@Override
public List<PersonalityDto> getAll(Pageable pageable) {
return personalityRepository.findAll(pageable).stream()
.map(personMapper::toPersonalityDtoFromEntity)
.toList();
}

@Override
public List<PersonalityDto> search(
PersonalitySearchParametersDto params,
Expand Down
Loading

0 comments on commit e1419bf

Please sign in to comment.