Repositorio movido

This commit is contained in:
2026-02-27 15:56:44 -03:00
commit 662ea8ba2f
23 changed files with 894 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.agendaestudantil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AgendaDigitalEstudantesApplication {
public static void main(String[] args) {
SpringApplication.run(AgendaDigitalEstudantesApplication.class, args);
}
}

View File

@@ -0,0 +1,25 @@
package com.agendaestudantil.config;
import io.github.cdimascio.dotenv.Dotenv;
import org.springframework.context.annotation.Configuration;
import jakarta.annotation.PostConstruct;
import java.util.Map;
@Configuration
public class EnvConfig {
@PostConstruct
public void init() {
Dotenv dotenv = Dotenv.configure()
.ignoreIfMissing()
.load();
if (dotenv != null) {
Map<String, String> envVars = (Map<String, String>) dotenv.entries();
for (Map.Entry<String, String> entry : envVars.entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
}
}
}
}

View File

@@ -0,0 +1,31 @@
package com.agendaestudantil.controller;
import com.agendaestudantil.dto.CadastroRequestDTO;
import com.agendaestudantil.dto.EstudanteResponseDTO;
import com.agendaestudantil.dto.LoginRequestDTO;
import com.agendaestudantil.service.EstudanteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/estudantes")
@CrossOrigin(origins = "*")
public class EstudanteController {
@Autowired
private EstudanteService estudanteService;
@PostMapping("/cadastro")
public ResponseEntity<EstudanteResponseDTO> cadastrar(@RequestBody CadastroRequestDTO dto) {
EstudanteResponseDTO resposta = estudanteService.cadastrar(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(resposta);
}
@PostMapping("/login")
public ResponseEntity<EstudanteResponseDTO> login(@RequestBody LoginRequestDTO dto) {
EstudanteResponseDTO resposta = estudanteService.login(dto);
return ResponseEntity.ok(resposta);
}
}

View File

@@ -0,0 +1,81 @@
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);
}
}

View File

@@ -0,0 +1,16 @@
package com.agendaestudantil.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CadastroRequestDTO {
private String nome;
private String email;
private String senha;
private String curso;
private Integer periodo;
}

View File

@@ -0,0 +1,16 @@
package com.agendaestudantil.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EstudanteResponseDTO {
private String id;
private String nome;
private String email;
private String curso;
private Integer periodo;
}

View File

@@ -0,0 +1,13 @@
package com.agendaestudantil.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginRequestDTO {
private String email;
private String senha;
}

View File

@@ -0,0 +1,28 @@
package com.agendaestudantil.dto;
import com.agendaestudantil.entity.Tarefa;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDate;
@Data
public class TarefaRequestDTO {
@NotBlank(message = "Título é obrigatório")
private String titulo;
private String descricao;
private Tarefa.Prioridade prioridade;
private Tarefa.StatusTarefa status;
@NotNull(message = "Data de entrega é obrigatória")
private LocalDate dataEntrega;
private String disciplinaId;
@NotBlank(message = "ID do estudante é obrigatório")
private String estudanteId;
}

View File

@@ -0,0 +1,30 @@
package com.agendaestudantil.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
@Document(collection = "disciplinas")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Disciplina {
@Id
private String id;
private String nome;
private String professor;
private String sala;
private String cor;
private String estudanteId;
private LocalDateTime dataCriacao;
}

View File

@@ -0,0 +1,32 @@
package com.agendaestudantil.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
@Document(collection = "estudantes")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Estudante {
@Id
private String id;
private String nome;
private String email;
private String senha;
private String curso;
private Integer periodo;
private LocalDateTime dataCriacao;
private LocalDateTime dataAtualizacao;
}

View File

@@ -0,0 +1,40 @@
package com.agendaestudantil.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
@Document(collection = "eventos")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Evento {
@Id
private String id;
private String titulo;
private String descricao;
private TipoEvento tipo;
private LocalDateTime dataInicio;
private LocalDateTime dataFim;
private String local;
private String disciplinaId;
private String estudanteId;
private LocalDateTime dataCriacao;
public enum TipoEvento {
AULA, PROVA, TRABALHO, ATIVIDADE, EVENTO, LEMBRETE
}
}

View File

@@ -0,0 +1,45 @@
package com.agendaestudantil.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Document(collection = "tarefas")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Tarefa {
@Id
private String id;
private String titulo;
private String descricao;
private Prioridade prioridade;
private StatusTarefa status;
private LocalDate dataEntrega;
private String disciplinaId;
private String estudanteId;
private LocalDateTime dataCriacao;
private LocalDateTime dataAtualizacao;
public enum Prioridade {
BAIXA, MEDIA, ALTA, URGENTE
}
public enum StatusTarefa {
PENDENTE, EM_ANDAMENTO, CONCLUIDA, ATRASADA
}
}

View File

@@ -0,0 +1,11 @@
package com.agendaestudantil.repository;
import com.agendaestudantil.entity.Disciplina;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DisciplinaRepository extends MongoRepository<Disciplina, String> {
List<Disciplina> findByEstudanteId(String estudanteId);
}

View File

@@ -0,0 +1,12 @@
package com.agendaestudantil.repository;
import com.agendaestudantil.entity.Estudante;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface EstudanteRepository extends MongoRepository<Estudante, String> {
Optional<Estudante> findByEmail(String email);
boolean existsByEmail(String email);
}

View File

@@ -0,0 +1,22 @@
package com.agendaestudantil.repository;
import com.agendaestudantil.entity.Evento;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
@Repository
public interface EventoRepository extends MongoRepository<Evento, String> {
List<Evento> findByEstudanteId(String estudanteId);
List<Evento> findByDisciplinaId(String disciplinaId);
@Query("{'estudanteId': ?0, 'dataInicio': {$gte: ?1, $lte: ?2}}")
List<Evento> findByEstudanteIdAndDataInicioBetween(String estudanteId, LocalDateTime inicio, LocalDateTime fim);
@Query("{'estudanteId': ?0, 'dataInicio': {$gte: ?1}}")
List<Evento> findProximosEventosByEstudanteId(String estudanteId, LocalDateTime data);
}

View File

@@ -0,0 +1,27 @@
package com.agendaestudantil.repository;
import com.agendaestudantil.entity.Tarefa;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.time.LocalDate;
import java.util.List;
@Repository
public interface TarefaRepository extends MongoRepository<Tarefa, String> {
List<Tarefa> findByEstudanteId(String estudanteId);
List<Tarefa> findByEstudanteIdAndStatus(String estudanteId, Tarefa.StatusTarefa status);
List<Tarefa> findByDisciplinaId(String disciplinaId);
@Query("{'estudanteId': ?0, 'dataEntrega': ?1}")
List<Tarefa> findByEstudanteIdAndDataEntrega(String estudanteId, LocalDate data);
@Query("{'estudanteId': ?0, 'dataEntrega': {$gte: ?1, $lte: ?2}}")
List<Tarefa> findByEstudanteIdAndDataEntregaBetween(String estudanteId, LocalDate inicio, LocalDate fim);
@Query("{'estudanteId': ?0, 'status': {$ne: 'CONCLUIDA'}}")
List<Tarefa> findTarefasPendentesByEstudanteId(String estudanteId);
}

View File

@@ -0,0 +1,64 @@
package com.agendaestudantil.service;
import com.agendaestudantil.dto.CadastroRequestDTO;
import com.agendaestudantil.dto.EstudanteResponseDTO;
import com.agendaestudantil.dto.LoginRequestDTO;
import com.agendaestudantil.entity.Estudante;
import com.agendaestudantil.repository.EstudanteRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.Optional;
@Service
public class EstudanteService {
@Autowired
private EstudanteRepository estudanteRepository;
public EstudanteResponseDTO cadastrar(CadastroRequestDTO dto) {
Optional<Estudante> existente = estudanteRepository.findByEmail(dto.getEmail());
if (existente.isPresent()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Email já cadastrado");
}
Estudante estudante = new Estudante();
estudante.setNome(dto.getNome());
estudante.setEmail(dto.getEmail());
estudante.setSenha(dto.getSenha());
estudante.setCurso(dto.getCurso());
estudante.setPeriodo(dto.getPeriodo());
estudante.setDataCriacao(LocalDateTime.now());
estudante.setDataAtualizacao(LocalDateTime.now());
Estudante salvo = estudanteRepository.save(estudante);
return toResponse(salvo);
}
public EstudanteResponseDTO login(LoginRequestDTO dto) {
Optional<Estudante> estudante = estudanteRepository.findByEmail(dto.getEmail());
if (estudante.isEmpty()) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Email ou senha incorretos");
}
if (!estudante.get().getSenha().equals(dto.getSenha())) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Email ou senha incorretos");
}
return toResponse(estudante.get());
}
private EstudanteResponseDTO toResponse(Estudante estudante) {
return new EstudanteResponseDTO(
estudante.getId(),
estudante.getNome(),
estudante.getEmail(),
estudante.getCurso(),
estudante.getPeriodo()
);
}
}

View File

@@ -0,0 +1,98 @@
package com.agendaestudantil.service;
import com.agendaestudantil.dto.TarefaRequestDTO;
import com.agendaestudantil.entity.Disciplina;
import com.agendaestudantil.entity.Tarefa;
import com.agendaestudantil.repository.DisciplinaRepository;
import com.agendaestudantil.repository.TarefaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@Service
@RequiredArgsConstructor
public class TarefaService {
private final TarefaRepository tarefaRepository;
private final DisciplinaRepository disciplinaRepository;
@Transactional
public Tarefa criarTarefa(TarefaRequestDTO dto) {
Tarefa tarefa = new Tarefa();
tarefa.setTitulo(dto.getTitulo());
tarefa.setDescricao(dto.getDescricao());
tarefa.setPrioridade(dto.getPrioridade() != null ? dto.getPrioridade() : Tarefa.Prioridade.MEDIA);
tarefa.setStatus(dto.getStatus() != null ? dto.getStatus() : Tarefa.StatusTarefa.PENDENTE);
tarefa.setDataEntrega(dto.getDataEntrega());
tarefa.setEstudanteId(dto.getEstudanteId());
tarefa.setDataCriacao(LocalDateTime.now());
tarefa.setDataAtualizacao(LocalDateTime.now());
if (dto.getDisciplinaId() != null) {
Disciplina disciplina = disciplinaRepository.findById(dto.getDisciplinaId())
.orElseThrow(() -> new RuntimeException("Disciplina não encontrada"));
tarefa.setDisciplinaId(disciplina.getId());
}
return tarefaRepository.save(tarefa);
}
public List<Tarefa> listarTarefasPorEstudante(String estudanteId) {
return tarefaRepository.findByEstudanteId(estudanteId);
}
public List<Tarefa> listarTarefasPendentes(String estudanteId) {
return tarefaRepository.findTarefasPendentesByEstudanteId(estudanteId);
}
public List<Tarefa> listarTarefasPorData(String estudanteId, LocalDate data) {
return tarefaRepository.findByEstudanteIdAndDataEntrega(estudanteId, data);
}
public List<Tarefa> listarTarefasPorPeriodo(String estudanteId, LocalDate inicio, LocalDate fim) {
return tarefaRepository.findByEstudanteIdAndDataEntregaBetween(estudanteId, inicio, fim);
}
public Optional<Tarefa> buscarTarefaPorId(String id) {
return tarefaRepository.findById(id);
}
@Transactional
public Tarefa atualizarTarefa(String id, TarefaRequestDTO dto) {
Tarefa tarefa = tarefaRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Tarefa não encontrada"));
tarefa.setTitulo(dto.getTitulo());
tarefa.setDescricao(dto.getDescricao());
tarefa.setPrioridade(dto.getPrioridade());
tarefa.setStatus(dto.getStatus());
tarefa.setDataEntrega(dto.getDataEntrega());
tarefa.setDataAtualizacao(LocalDateTime.now());
if (dto.getDisciplinaId() != null) {
Disciplina disciplina = disciplinaRepository.findById(dto.getDisciplinaId())
.orElseThrow(() -> new RuntimeException("Disciplina não encontrada"));
tarefa.setDisciplinaId(disciplina.getId());
}
return tarefaRepository.save(tarefa);
}
@Transactional
public void excluirTarefa(String id) {
tarefaRepository.deleteById(id);
}
@Transactional
public Tarefa marcarConcluida(String id) {
Tarefa tarefa = tarefaRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Tarefa não encontrada"));
tarefa.setStatus(Tarefa.StatusTarefa.CONCLUIDA);
tarefa.setDataAtualizacao(LocalDateTime.now());
return tarefaRepository.save(tarefa);
}
}