[77205be] | 1 | package edu.gjoko.schedlr.controllers.rest;
|
---|
| 2 |
|
---|
| 3 | import edu.gjoko.schedlr.dto.AppointmentDto;
|
---|
| 4 | import edu.gjoko.schedlr.dto.AppointmentInfoDto;
|
---|
| 5 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
| 6 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
| 7 | import edu.gjoko.schedlr.mappers.AppointmentDtoMapper;
|
---|
| 8 | import edu.gjoko.schedlr.services.AppointmentsService;
|
---|
| 9 | import lombok.AllArgsConstructor;
|
---|
| 10 | import org.springframework.web.bind.annotation.*;
|
---|
| 11 |
|
---|
| 12 | import javax.security.sasl.AuthenticationException;
|
---|
| 13 | import javax.servlet.http.HttpServletRequest;
|
---|
| 14 | import java.time.LocalDateTime;
|
---|
| 15 | import java.util.List;
|
---|
| 16 | import java.util.stream.Collectors;
|
---|
| 17 |
|
---|
| 18 | @RestController
|
---|
| 19 | @RequestMapping("api/appointment")
|
---|
| 20 | @AllArgsConstructor
|
---|
| 21 | public class AppointmentApi {
|
---|
| 22 |
|
---|
| 23 | private final AppointmentsService appointmentsService;
|
---|
| 24 | private final AppointmentDtoMapper appointmentsMapper;
|
---|
| 25 |
|
---|
| 26 | @PostMapping
|
---|
| 27 | public void getBusinessTypes(@RequestBody Appointment appointment, HttpServletRequest request) {
|
---|
| 28 | Long customerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
| 29 | Stakeholder customer = new Stakeholder();
|
---|
| 30 | customer.setId(customerId);
|
---|
| 31 | appointment.setCustomer(customer);
|
---|
| 32 | appointmentsService.saveAppointment(appointment);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @GetMapping(path = "/business/{businessId}")
|
---|
| 36 | public List<AppointmentDto> getAppointmentsByBusiness(@PathVariable("businessId") Long businessId) {
|
---|
| 37 | return appointmentsService.getActiveAppointmentsByBusiness(businessId).stream()
|
---|
| 38 | .map(appointmentsMapper::appointmentToAppointmentDto)
|
---|
| 39 | .collect(Collectors.toList());
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @GetMapping(path = "/future/me")
|
---|
| 43 | public List<AppointmentInfoDto> getFutureAppointmentsInfoList(HttpServletRequest request) {
|
---|
| 44 | Long businessOwnerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
| 45 | return appointmentsService.getFutureAppointmentInfoList(businessOwnerId);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | @GetMapping(path = "/past/me")
|
---|
| 49 | public List<AppointmentInfoDto> getPastAppointmentsInfoList(HttpServletRequest request) {
|
---|
| 50 | Long stakeholderId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
| 51 | return appointmentsService.getPastAppointmentInfoList(stakeholderId);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | @DeleteMapping("/{appointmentId}")
|
---|
| 55 | public void cancelAppointment(@PathVariable("appointmentId") Long appointmentId, HttpServletRequest request) throws AuthenticationException {
|
---|
| 56 | Long stakeholderId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
| 57 | appointmentsService.deleteAppointment(appointmentId, stakeholderId);
|
---|
| 58 | }
|
---|
| 59 | }
|
---|