source: src/main/java/edu/gjoko/schedlr/controllers/rest/AppointmentApi.java@ 77205be

Last change on this file since 77205be was 77205be, checked in by gjoko kostadinov <gjokokostadinov@…>, 6 months ago

Add entire code

  • Property mode set to 100755
File size: 2.5 KB
Line 
1package edu.gjoko.schedlr.controllers.rest;
2
3import edu.gjoko.schedlr.dto.AppointmentDto;
4import edu.gjoko.schedlr.dto.AppointmentInfoDto;
5import edu.gjoko.schedlr.entity.Appointment;
6import edu.gjoko.schedlr.entity.Stakeholder;
7import edu.gjoko.schedlr.mappers.AppointmentDtoMapper;
8import edu.gjoko.schedlr.services.AppointmentsService;
9import lombok.AllArgsConstructor;
10import org.springframework.web.bind.annotation.*;
11
12import javax.security.sasl.AuthenticationException;
13import javax.servlet.http.HttpServletRequest;
14import java.time.LocalDateTime;
15import java.util.List;
16import java.util.stream.Collectors;
17
18@RestController
19@RequestMapping("api/appointment")
20@AllArgsConstructor
21public 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}
Note: See TracBrowser for help on using the repository browser.