package com.agendaestudantil.controller; import com.agendaestudantil.dto.TarefaRequestDTO; import com.agendaestudantil.entity.Tarefa; import com.agendaestudantil.service.TarefaService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; 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") @RequiredArgsConstructor public class TarefaController { private final TarefaService tarefaService; @PostMapping public ResponseEntity criarTarefa(@Valid @RequestBody TarefaRequestDTO dto) { Tarefa tarefa = tarefaService.criarTarefa(dto); return ResponseEntity.status(HttpStatus.CREATED).body(tarefa); } @GetMapping("/estudante/{estudanteId}") public ResponseEntity> listarTarefasPorEstudante(@PathVariable String estudanteId) { List tarefas = tarefaService.listarTarefasPorEstudante(estudanteId); return ResponseEntity.ok(tarefas); } @GetMapping("/estudante/{estudanteId}/pendentes") public ResponseEntity> listarTarefasPendentes(@PathVariable String estudanteId) { List tarefas = tarefaService.listarTarefasPendentes(estudanteId); return ResponseEntity.ok(tarefas); } @GetMapping("/estudante/{estudanteId}/data") public ResponseEntity> listarTarefasPorData( @PathVariable String estudanteId, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate data) { List tarefas = tarefaService.listarTarefasPorData(estudanteId, data); return ResponseEntity.ok(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 = tarefaService.listarTarefasPorPeriodo(estudanteId, inicio, fim); return ResponseEntity.ok(tarefas); } @GetMapping("/{id}") public ResponseEntity buscarTarefaPorId(@PathVariable String id) { return tarefaService.buscarTarefaPorId(id) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @PutMapping("/{id}") public ResponseEntity atualizarTarefa(@PathVariable String id, @Valid @RequestBody TarefaRequestDTO dto) { Tarefa tarefa = tarefaService.atualizarTarefa(id, dto); return ResponseEntity.ok(tarefa); } @DeleteMapping("/{id}") public ResponseEntity excluirTarefa(@PathVariable String id) { tarefaService.excluirTarefa(id); return ResponseEntity.noContent().build(); } @PatchMapping("/{id}/concluir") public ResponseEntity marcarConcluida(@PathVariable String id) { Tarefa tarefa = tarefaService.marcarConcluida(id); return ResponseEntity.ok(tarefa); } }