87 lines
3.8 KiB
Java
87 lines
3.8 KiB
Java
package com.agendaestudantil.controlador;
|
|
|
|
import com.agendaestudantil.dto.RespostaApi;
|
|
import com.agendaestudantil.dto.RequisicaoTarefaDTO;
|
|
import com.agendaestudantil.dto.RespostaTarefaDTO;
|
|
import com.agendaestudantil.servico.TarefaServico;
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import java.time.LocalDate;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/tarefas")
|
|
public class TarefaControlador {
|
|
|
|
private final TarefaServico tarefaServico;
|
|
|
|
public TarefaControlador(TarefaServico tarefaServico) {
|
|
this.tarefaServico = tarefaServico;
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<RespostaApi<RespostaTarefaDTO>> criarTarefa(@Valid @RequestBody RequisicaoTarefaDTO dto) {
|
|
RespostaTarefaDTO tarefa = tarefaServico.criarTarefa(dto);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(RespostaApi.sucesso(tarefa));
|
|
}
|
|
|
|
@GetMapping("/estudante/{estudanteId}")
|
|
public ResponseEntity<RespostaApi<List<RespostaTarefaDTO>>> listarTarefasPorEstudante(
|
|
@PathVariable String estudanteId) {
|
|
List<RespostaTarefaDTO> tarefas = tarefaServico.listarTarefasPorEstudante(estudanteId);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefas));
|
|
}
|
|
|
|
@GetMapping("/estudante/{estudanteId}/pendentes")
|
|
public ResponseEntity<RespostaApi<List<RespostaTarefaDTO>>> listarTarefasPendentes(
|
|
@PathVariable String estudanteId) {
|
|
List<RespostaTarefaDTO> tarefas = tarefaServico.listarTarefasPendentes(estudanteId);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefas));
|
|
}
|
|
|
|
@GetMapping("/estudante/{estudanteId}/data")
|
|
public ResponseEntity<RespostaApi<List<RespostaTarefaDTO>>> listarTarefasPorData(
|
|
@PathVariable String estudanteId,
|
|
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate data) {
|
|
List<RespostaTarefaDTO> tarefas = tarefaServico.listarTarefasPorData(estudanteId, data);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefas));
|
|
}
|
|
|
|
@GetMapping("/estudante/{estudanteId}/periodo")
|
|
public ResponseEntity<RespostaApi<List<RespostaTarefaDTO>>> listarTarefasPorPeriodo(
|
|
@PathVariable String estudanteId,
|
|
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate inicio,
|
|
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fim) {
|
|
List<RespostaTarefaDTO> tarefas = tarefaServico.listarTarefasPorPeriodo(estudanteId, inicio, fim);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefas));
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<RespostaApi<RespostaTarefaDTO>> buscarTarefaPorId(@PathVariable String id) {
|
|
RespostaTarefaDTO dto = tarefaServico.buscarTarefaPorId(id);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(dto));
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<RespostaApi<RespostaTarefaDTO>> atualizarTarefa(@PathVariable String id,
|
|
@Valid @RequestBody RequisicaoTarefaDTO dto) {
|
|
RespostaTarefaDTO tarefa = tarefaServico.atualizarTarefa(id, dto);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefa));
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<RespostaApi<Void>> excluirTarefa(@PathVariable String id) {
|
|
tarefaServico.excluirTarefa(id);
|
|
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(RespostaApi.sucesso(null));
|
|
}
|
|
|
|
@PatchMapping("/{id}/concluir")
|
|
public ResponseEntity<RespostaApi<RespostaTarefaDTO>> marcarConcluida(@PathVariable String id) {
|
|
RespostaTarefaDTO tarefa = tarefaServico.marcarConcluida(id);
|
|
return ResponseEntity.ok(RespostaApi.sucesso(tarefa));
|
|
}
|
|
}
|