Commit 52050d30 authored by Gabriel Fanto Stundner's avatar Gabriel Fanto Stundner 💻
Browse files

#27 Atualizando os filtros

parent 77058404
Showing with 30 additions and 79 deletions
+30 -79
......@@ -14,6 +14,7 @@ import com.ages.joinfut.service.AthleteService;
import com.ages.joinfut.service.AdressService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
......@@ -48,8 +49,21 @@ public class AthleteController {
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista de todos os Atletas cadastrados")
public ResponseEntity<List<AthleteDTO>> readAllAthletes() {
List<Athlete> athletes = athleteRepository.findAll();
public ResponseEntity<List<AthleteDTO>> readAllAthletes(
@RequestParam(value = "dominantLeg", required = false) DominantLeg dominantLeg,
@RequestParam(value = "athleteHeight", required = false) Double athleteHeight,
@RequestParam(value = "age", required = false) Integer age,
@RequestParam(value = "athleteWeight", required = false) Double athleteWeight,
@RequestParam(value = "position", required = false) Position position)
{
Athlete athlete = Athlete.builder()
.dominantLeg(dominantLeg)
.athleteHeight(athleteHeight)
.age(age)
.athleteWeight(athleteWeight)
.position(position)
.build();
List<Athlete> athletes = athleteRepository.findAll(Example.of(athlete));
List<AthleteDTO> athletesDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athletesDTO, HttpStatus.OK);
}
......@@ -94,81 +108,6 @@ public class AthleteController {
return ResponseEntity.notFound().build();
}
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista as alturas dos atletas")
@Transactional
public ResponseEntity<List<AthleteDTO>> readAthleteByathleteHeight(@RequestParam(value = "athleteHeight", required = false) Double athleteHeight) {
if (athleteHeight != null) {
List<Athlete> athletes = athleteRepository.findByathleteHeight(athleteHeight);
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
} else {
List<Athlete> athletes = athleteRepository.findAll();
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
}
}
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista as idades dos atletas")
@Transactional
public ResponseEntity<List<AthleteDTO>> readAthleteByage(@RequestParam(value = "age", required = false) Integer age) {
if (age != null) {
List<Athlete> athletes = athleteRepository.findByage(age);
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
} else {
List<Athlete> athletes = athleteRepository.findAll();
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
}
}
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista os pesos dos atletas")
@Transactional
public ResponseEntity<List<AthleteDTO>> readAthelteByathleteWeight(@RequestParam(value = "athleteWeight", required = false) Double athleteWeight) {
if (athleteWeight != null) {
List<Athlete> athletes = athleteRepository.findByathleteWeight(athleteWeight);
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
} else {
List<Athlete> athletes = athleteRepository.findAll();
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
}
}
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista as pernas dominantes dos atletas")
@Transactional
public ResponseEntity<List<AthleteDTO>> readAthleteBydominantLeg(@RequestParam(value = "dominantLeg", required = false) DominantLeg dominantLeg) {
if (dominantLeg != null) {
List<Athlete> athletes = athleteRepository.findBydominantLeg(dominantLeg);
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
} else {
List<Athlete> athletes = athleteRepository.findAll();
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
}
}
@GetMapping(value = URL_PLURAL, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiModelProperty("Busca em lista as posições dos atletas")
@Transactional
public ResponseEntity<List<AthleteDTO>> readAthleteByposition(@RequestParam(value = "position", required = false) Position position) {
if (position != null) {
List<Athlete> athletes = athleteRepository.findByposition(position);
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
} else {
List<Athlete> athletes = athleteRepository.findAll();
List<AthleteDTO> athleteDTO = athleteService.convertList(athletes);
return new ResponseEntity<>(athleteDTO, HttpStatus.OK);
}
}
//Adress State
}
......
......@@ -5,7 +5,10 @@ import com.ages.joinfut.Enum.Position;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Type;
......@@ -31,6 +34,9 @@ import java.util.List;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Table(name = "athletes", schema = "personas")
......@@ -99,7 +105,7 @@ public class Athlete {
private User user;
public Athlete() {}
//public Athlete() {}
public Long getId() {
return getIdAthlete();
......
......@@ -9,13 +9,19 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
@Repository
public interface AthleteRepository extends JpaRepository<Athlete, Long> {
Athlete findByidAthlete(Long id);
List<Athlete> findByathleteHeight(Double athleteHeight);
// List<Athlete> findWithFilters(Objects...list) {
// for( Object object : list) {
// if object ! = null
// query += where object ...
// }
// }
List<Athlete> findByage(Integer age);
List<Athlete> findByathleteWeight(Double athleteWeight);
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment