Files
BackendFocusAgenda/src/main/java/com/agendaestudantil/controller/TarefaController.java
2026-02-27 15:56:44 -03:00

82 lines
3.2 KiB
Java

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<Tarefa> criarTarefa(@Valid @RequestBody TarefaRequestDTO dto) {
Tarefa tarefa = tarefaService.criarTarefa(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(tarefa);
}
@GetMapping("/estudante/{estudanteId}")
public ResponseEntity<List<Tarefa>> listarTarefasPorEstudante(@PathVariable String estudanteId) {
List<Tarefa> tarefas = tarefaService.listarTarefasPorEstudante(estudanteId);
return ResponseEntity.ok(tarefas);
}
@GetMapping("/estudante/{estudanteId}/pendentes")
public ResponseEntity<List<Tarefa>> listarTarefasPendentes(@PathVariable String estudanteId) {
List<Tarefa> tarefas = tarefaService.listarTarefasPendentes(estudanteId);
return ResponseEntity.ok(tarefas);
}
@GetMapping("/estudante/{estudanteId}/data")
public ResponseEntity<List<Tarefa>> listarTarefasPorData(
@PathVariable String estudanteId,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate data) {
List<Tarefa> tarefas = tarefaService.listarTarefasPorData(estudanteId, data);
return ResponseEntity.ok(tarefas);
}
@GetMapping("/estudante/{estudanteId}/periodo")
public ResponseEntity<List<Tarefa>> listarTarefasPorPeriodo(
@PathVariable String estudanteId,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate inicio,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fim) {
List<Tarefa> tarefas = tarefaService.listarTarefasPorPeriodo(estudanteId, inicio, fim);
return ResponseEntity.ok(tarefas);
}
@GetMapping("/{id}")
public ResponseEntity<Tarefa> buscarTarefaPorId(@PathVariable String id) {
return tarefaService.buscarTarefaPorId(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PutMapping("/{id}")
public ResponseEntity<Tarefa> atualizarTarefa(@PathVariable String id, @Valid @RequestBody TarefaRequestDTO dto) {
Tarefa tarefa = tarefaService.atualizarTarefa(id, dto);
return ResponseEntity.ok(tarefa);
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> excluirTarefa(@PathVariable String id) {
tarefaService.excluirTarefa(id);
return ResponseEntity.noContent().build();
}
@PatchMapping("/{id}/concluir")
public ResponseEntity<Tarefa> marcarConcluida(@PathVariable String id) {
Tarefa tarefa = tarefaService.marcarConcluida(id);
return ResponseEntity.ok(tarefa);
}
}