fix betreft afspraken
This commit is contained in:
107
src/main/java/nl/veenm/paypoint/domain/dto/AppointmentDTO.java
Normal file
107
src/main/java/nl/veenm/paypoint/domain/dto/AppointmentDTO.java
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package nl.veenm.paypoint.domain.dto;
|
||||||
|
|
||||||
|
import nl.veenm.paypoint.domain.Customer;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class AppointmentDTO {
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private LocalDateTime startDate;
|
||||||
|
private int startHour;
|
||||||
|
private int startMinute;
|
||||||
|
private int endHour;
|
||||||
|
private int endMinute;
|
||||||
|
private int durationInMinutes;
|
||||||
|
private Customer customer;
|
||||||
|
private CompanyDTO company;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(LocalDateTime startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartHour() {
|
||||||
|
return startHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartHour(int startHour) {
|
||||||
|
this.startHour = startHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartMinute() {
|
||||||
|
return startMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartMinute(int startMinute) {
|
||||||
|
this.startMinute = startMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndHour() {
|
||||||
|
return endHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndHour(int endHour) {
|
||||||
|
this.endHour = endHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndMinute() {
|
||||||
|
return endMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndMinute(int endMinute) {
|
||||||
|
this.endMinute = endMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDurationInMinutes() {
|
||||||
|
return durationInMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDurationInMinutes(int durationInMinutes) {
|
||||||
|
this.durationInMinutes = durationInMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Customer getCustomer() {
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomer(Customer customer) {
|
||||||
|
this.customer = customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompanyDTO getCompany() {
|
||||||
|
return company;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompany(CompanyDTO company) {
|
||||||
|
this.company = company;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package nl.veenm.paypoint.domain.mapper;
|
||||||
|
|
||||||
|
import nl.veenm.paypoint.domain.Appointment;
|
||||||
|
import nl.veenm.paypoint.domain.dto.AppointmentDTO;
|
||||||
|
|
||||||
|
public class AppointmentMapper {
|
||||||
|
|
||||||
|
public static AppointmentDTO toDto(Appointment appointment) {
|
||||||
|
if (appointment == null) return null;
|
||||||
|
|
||||||
|
AppointmentDTO dto = new AppointmentDTO();
|
||||||
|
dto.setId(appointment.getId());
|
||||||
|
dto.setTitle(appointment.getTitle());
|
||||||
|
dto.setDescription(appointment.getDescription());
|
||||||
|
dto.setStartDate(appointment.getStartDate());
|
||||||
|
dto.setStartHour(appointment.getStartHour());
|
||||||
|
dto.setStartMinute(appointment.getStartMinute());
|
||||||
|
dto.setEndHour(appointment.getEndHour());
|
||||||
|
dto.setEndMinute(appointment.getEndMinute());
|
||||||
|
dto.setDurationInMinutes(appointment.getDurationInMinutes());
|
||||||
|
dto.setCustomer(appointment.getCustomer());
|
||||||
|
dto.setCompany(CompanyMapper.toDto(appointment.getCompany()));
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ import jakarta.ws.rs.*;
|
|||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import nl.veenm.paypoint.domain.Appointment;
|
import nl.veenm.paypoint.domain.Appointment;
|
||||||
|
import nl.veenm.paypoint.domain.dto.AppointmentDTO;
|
||||||
import nl.veenm.paypoint.service.AppointmentService;
|
import nl.veenm.paypoint.service.AppointmentService;
|
||||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public class AppointmentResource {
|
|||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("/date")
|
@Path("/date")
|
||||||
public List<Appointment> getAppointmentsByDate(@QueryParam("start") String start) {
|
public List<AppointmentDTO> getAppointmentsByDate(@QueryParam("start") String start) {
|
||||||
System.out.println("getting appointments from " + start);
|
System.out.println("getting appointments from " + start);
|
||||||
String user = jwt.getClaim("username");
|
String user = jwt.getClaim("username");
|
||||||
System.out.println("user " + user);
|
System.out.println("user " + user);
|
||||||
@@ -49,7 +50,7 @@ public class AppointmentResource {
|
|||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
public Appointment getAppointmentById(@PathParam("id") Long id) {
|
public AppointmentDTO getAppointmentById(@PathParam("id") Long id) {
|
||||||
return appointmentService.getAppointment(id);
|
return appointmentService.getAppointment(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ public class AppointmentResource {
|
|||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Response updateAppointment(Appointment appointment) {
|
public Response updateAppointment(AppointmentDTO appointment) {
|
||||||
return Response.ok(appointmentService.update(appointment)).build();
|
return Response.ok(appointmentService.update(appointment)).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import nl.veenm.paypoint.domain.AppUser;
|
|||||||
import nl.veenm.paypoint.domain.Appointment;
|
import nl.veenm.paypoint.domain.Appointment;
|
||||||
import nl.veenm.paypoint.domain.Company;
|
import nl.veenm.paypoint.domain.Company;
|
||||||
import nl.veenm.paypoint.domain.dto.AppUserDTO;
|
import nl.veenm.paypoint.domain.dto.AppUserDTO;
|
||||||
|
import nl.veenm.paypoint.domain.dto.AppointmentDTO;
|
||||||
import nl.veenm.paypoint.domain.dto.CompanyDTO;
|
import nl.veenm.paypoint.domain.dto.CompanyDTO;
|
||||||
import nl.veenm.paypoint.domain.dto.UserCompanyDTO;
|
import nl.veenm.paypoint.domain.dto.UserCompanyDTO;
|
||||||
import nl.veenm.paypoint.domain.mapper.AppUserMapper;
|
import nl.veenm.paypoint.domain.mapper.AppUserMapper;
|
||||||
|
import nl.veenm.paypoint.domain.mapper.AppointmentMapper;
|
||||||
import nl.veenm.paypoint.repository.AppointmentRepository;
|
import nl.veenm.paypoint.repository.AppointmentRepository;
|
||||||
import nl.veenm.paypoint.repository.CompanyRepository;
|
import nl.veenm.paypoint.repository.CompanyRepository;
|
||||||
import nl.veenm.paypoint.repository.UserRepository;
|
import nl.veenm.paypoint.repository.UserRepository;
|
||||||
@@ -45,17 +47,17 @@ public class AppointmentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Appointment add(Appointment appointment, Long companyId, String username) {
|
public AppointmentDTO add(Appointment appointment, Long companyId, String username) {
|
||||||
Company company = companyRepository.findById(companyId);
|
Company company = companyRepository.findById(companyId);
|
||||||
AppUser user = userRepository.findByUsername(username);
|
AppUser user = userRepository.findByUsername(username);
|
||||||
appointment.setCompany(company);
|
appointment.setCompany(company);
|
||||||
appointmentRepository.persist(appointment);
|
appointmentRepository.persist(appointment);
|
||||||
emailService.stuurBevestiging(appointment, user);
|
emailService.stuurBevestiging(appointment, user);
|
||||||
return appointment;
|
return AppointmentMapper.toDto(appointment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<Appointment> getAppointmentsByDate(String start, String username) {
|
public List<AppointmentDTO> getAppointmentsByDate(String start, String username) {
|
||||||
LocalDate date = LocalDate.parse(start);
|
LocalDate date = LocalDate.parse(start);
|
||||||
AppUser user = userRepository.findByUsername(username);
|
AppUser user = userRepository.findByUsername(username);
|
||||||
System.out.println("user " + user);
|
System.out.println("user " + user);
|
||||||
@@ -69,8 +71,7 @@ public class AppointmentService {
|
|||||||
LocalDateTime endOfDay = date.atTime(23, 59, 59);
|
LocalDateTime endOfDay = date.atTime(23, 59, 59);
|
||||||
|
|
||||||
List<Appointment> appointmentsForCompanies = appointmentRepository.findAppointmentsForCompanies(companies, startOfDay, endOfDay);
|
List<Appointment> appointmentsForCompanies = appointmentRepository.findAppointmentsForCompanies(companies, startOfDay, endOfDay);
|
||||||
System.out.println(appointmentsForCompanies);
|
return appointmentsForCompanies.stream().map(AppointmentMapper::toDto).toList();
|
||||||
return appointmentsForCompanies;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -80,7 +81,7 @@ public class AppointmentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Appointment update(Appointment appointment) {
|
public AppointmentDTO update(AppointmentDTO appointment) {
|
||||||
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
|
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
|
||||||
appointmentToUpdate.setTitle(appointment.getTitle());
|
appointmentToUpdate.setTitle(appointment.getTitle());
|
||||||
appointmentToUpdate.setStartDate(appointment.getStartDate());
|
appointmentToUpdate.setStartDate(appointment.getStartDate());
|
||||||
@@ -93,12 +94,13 @@ public class AppointmentService {
|
|||||||
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
|
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
|
||||||
appointmentRepository.persist(appointmentToUpdate);
|
appointmentRepository.persist(appointmentToUpdate);
|
||||||
emailService.stuurBewerking(appointmentToUpdate);
|
emailService.stuurBewerking(appointmentToUpdate);
|
||||||
return appointmentToUpdate;
|
return AppointmentMapper.toDto(appointmentToUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Appointment getAppointment(Long id) {
|
public AppointmentDTO getAppointment(Long id) {
|
||||||
return appointmentRepository.findById(id);
|
Appointment byId = appointmentRepository.findById(id);
|
||||||
|
return AppointmentMapper.toDto(byId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
Reference in New Issue
Block a user