Skip to content

Commit

Permalink
feat: inicio das validações do [backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio-Pupim committed Nov 4, 2024
1 parent d8fc74e commit 94b00c9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import br.com.servicemaker.domain.Agenda;
import br.com.servicemaker.repository.AgendaRepository;
import br.com.servicemaker.service.AgendaService;
import java.time.LocalDate;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -16,4 +21,11 @@ public class AgendaController extends AbstractController<Agenda, AgendaRepositor
public AgendaController(AgendaService service) {
super(service);
}

@GetMapping("/{idPrestador}/dias-disponiveis")
public ResponseEntity<List<LocalDate>> findAllDiasDisponiveis(
@PathVariable("idPrestador") Long idPrestador) {

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

import br.com.servicemaker.abstractcrud.AbstractRepository;
import br.com.servicemaker.domain.Agenda;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface AgendaRepository extends AbstractRepository<Agenda> {

@Query("SELECT a FROM Agenda a WHERE a.prestador.id = :idPrestador")
Agenda findAgendaByPrestador(@Param("idPrestador") Long idPrestador);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,55 @@

import br.com.servicemaker.abstractcrud.AbstractService;
import br.com.servicemaker.domain.Agenda;
import br.com.servicemaker.domain.CronogramaTrabalho;
import br.com.servicemaker.domain.Reserva;
import br.com.servicemaker.repository.AgendaRepository;
import br.com.servicemaker.repository.PrestadorRepository;
import jakarta.persistence.EntityManager;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AgendaService extends AbstractService<Agenda, AgendaRepository> {

private final AgendaRepository agendaRepository;

@Autowired
public AgendaService(AgendaRepository repository, EntityManager em) {
public AgendaService(AgendaRepository repository, EntityManager em,
PrestadorRepository prestadorRepository) {
super(repository, em);
this.agendaRepository = repository;
}

public List<LocalDate> findAllDiasDisponiveis(Long idPrestador) {

Agenda agenda = agendaRepository.findAgendaByPrestador(idPrestador);

}

private Set<Integer> getAllDiasCronograTrabalho(List<CronogramaTrabalho> cronogramas) {

return cronogramas.stream().map(CronogramaTrabalho::getDiaSemana)
.collect(Collectors.toSet());
}

private void verificarSeODiaEspecificoEstaCheio(LocalDate diaEspecifico, Agenda agenda) {

DayOfWeek diaDaSemana = diaEspecifico.getDayOfWeek();

List<Reserva> reservasEspecificas = agenda.getReservas().stream()
.filter(reserva -> reserva.getReservadoEm().toLocalDate().equals(diaEspecifico)).toList();

List<CronogramaTrabalho> cronogramaTrabalhos = agenda.getCronogramas().stream().filter(
cronogramaTrabalho -> cronogramaTrabalho.getDiaSemana().equals(diaDaSemana.getValue()))
.toList();

}


}

0 comments on commit 94b00c9

Please sign in to comment.