1 | package edu.gjoko.schedlr.controllers.rest;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.entity.Business;
|
---|
4 | import edu.gjoko.schedlr.services.BusinessService;
|
---|
5 | import lombok.AllArgsConstructor;
|
---|
6 | import org.springframework.web.bind.annotation.*;
|
---|
7 |
|
---|
8 | import javax.servlet.http.HttpServletRequest;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | @RestController
|
---|
12 | @RequestMapping("api/business")
|
---|
13 | @AllArgsConstructor
|
---|
14 | public class BusinessApi {
|
---|
15 |
|
---|
16 | private final BusinessService businessService;
|
---|
17 |
|
---|
18 | @PostMapping
|
---|
19 | public void saveBusiness(@RequestBody Business business) {
|
---|
20 | businessService.saveBusiness(business);
|
---|
21 | }
|
---|
22 |
|
---|
23 | @GetMapping
|
---|
24 | public List<Business> findAll() {
|
---|
25 | return businessService.findAll();
|
---|
26 | }
|
---|
27 |
|
---|
28 | @PatchMapping
|
---|
29 | public void updateBusinesses(@RequestBody List<Business> businessList, HttpServletRequest request) {
|
---|
30 | Long businessOwnerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
31 | businessService.updateBusinesses(businessList, businessOwnerId);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @GetMapping(path = "/me")
|
---|
35 | public Business getPersonalInfo(HttpServletRequest request) {
|
---|
36 | Long businessOwnerId = (long) request.getSession(true).getAttribute("stakeholderId");
|
---|
37 | return businessService.findByOwner(businessOwnerId);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @GetMapping(path = "/{businessTypeId}")
|
---|
41 | public List<Business> getBusinessesByBusinessType(@PathVariable("businessTypeId") Long id) {
|
---|
42 | return businessService.findByBusinessTypeAndActiveStatus(id);
|
---|
43 | }
|
---|
44 | }
|
---|