[950fa0d] | 1 | package edu.gjoko.schedlr.controllers.rest;
|
---|
| 2 |
|
---|
| 3 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
| 4 | import edu.gjoko.schedlr.entity.Business;
|
---|
| 5 | import edu.gjoko.schedlr.entity.Stakeholder;
|
---|
| 6 | import edu.gjoko.schedlr.repositories.AppointmentRepository;
|
---|
| 7 | import edu.gjoko.schedlr.services.AppointmentsService;
|
---|
| 8 | import edu.gjoko.schedlr.services.StakeholderService;
|
---|
| 9 | import lombok.AllArgsConstructor;
|
---|
| 10 | import org.springframework.web.bind.annotation.*;
|
---|
| 11 |
|
---|
| 12 | import javax.servlet.http.HttpServletRequest;
|
---|
| 13 | import java.util.List;
|
---|
| 14 |
|
---|
| 15 | @RestController
|
---|
| 16 | @RequestMapping("api/appointment")
|
---|
| 17 | @AllArgsConstructor
|
---|
| 18 | public class AppointmentController {
|
---|
| 19 |
|
---|
| 20 | private final AppointmentsService appointmentsService;
|
---|
| 21 |
|
---|
| 22 | @PostMapping
|
---|
| 23 | public void getBusinessTypes(@RequestBody Appointment appointment, HttpServletRequest request) {
|
---|
| 24 | Long customerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
| 25 | Stakeholder customer = new Stakeholder();
|
---|
| 26 | customer.setId(customerId);
|
---|
| 27 | appointment.setCustomer(customer);
|
---|
| 28 | appointmentsService.saveAppointment(appointment);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @GetMapping(path = "/business/{businessId}")
|
---|
| 32 | public List<Appointment> getAppointmentsByBusiness(@PathVariable("businessId") Long businessId) {
|
---|
| 33 | var business = new Business();
|
---|
| 34 | business.setId(businessId);
|
---|
| 35 | return appointmentsService.getAppointmentsByBusiness(business);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|