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> criarTarefa(@Valid @RequestBody RequisicaoTarefaDTO dto) { RespostaTarefaDTO tarefa = tarefaServico.criarTarefa(dto); return ResponseEntity.status(HttpStatus.CREATED).body(RespostaApi.sucesso(tarefa)); } @GetMapping("/estudante/{estudanteId}") public ResponseEntity>> listarTarefasPorEstudante( @PathVariable String estudanteId) { List tarefas = tarefaServico.listarTarefasPorEstudante(estudanteId); return ResponseEntity.ok(RespostaApi.sucesso(tarefas)); } @GetMapping("/estudante/{estudanteId}/pendentes") public ResponseEntity>> listarTarefasPendentes( @PathVariable String estudanteId) { List tarefas = tarefaServico.listarTarefasPendentes(estudanteId); return ResponseEntity.ok(RespostaApi.sucesso(tarefas)); } @GetMapping("/estudante/{estudanteId}/data") public ResponseEntity>> listarTarefasPorData( @PathVariable String estudanteId, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate data) { List tarefas = tarefaServico.listarTarefasPorData(estudanteId, data); return ResponseEntity.ok(RespostaApi.sucesso(tarefas)); } @GetMapping("/estudante/{estudanteId}/periodo") public ResponseEntity>> listarTarefasPorPeriodo( @PathVariable String estudanteId, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate inicio, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fim) { List tarefas = tarefaServico.listarTarefasPorPeriodo(estudanteId, inicio, fim); return ResponseEntity.ok(RespostaApi.sucesso(tarefas)); } @GetMapping("/{id}") public ResponseEntity> buscarTarefaPorId(@PathVariable String id) { RespostaTarefaDTO dto = tarefaServico.buscarTarefaPorId(id); return ResponseEntity.ok(RespostaApi.sucesso(dto)); } @PutMapping("/{id}") public ResponseEntity> atualizarTarefa(@PathVariable String id, @Valid @RequestBody RequisicaoTarefaDTO dto) { RespostaTarefaDTO tarefa = tarefaServico.atualizarTarefa(id, dto); return ResponseEntity.ok(RespostaApi.sucesso(tarefa)); } @DeleteMapping("/{id}") public ResponseEntity> excluirTarefa(@PathVariable String id) { tarefaServico.excluirTarefa(id); return ResponseEntity.status(HttpStatus.NO_CONTENT).body(RespostaApi.sucesso(null)); } @PatchMapping("/{id}/concluir") public ResponseEntity> marcarConcluida(@PathVariable String id) { RespostaTarefaDTO tarefa = tarefaServico.marcarConcluida(id); return ResponseEntity.ok(RespostaApi.sucesso(tarefa)); } }