source: src/main/java/edu/gjoko/schedlr/controllers/rest/ServiceApi.java

Last change on this file was f29cd58, checked in by gjoko kostadinov <gjokokostadinov@…>, 10 months ago

Add services search functionality.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package edu.gjoko.schedlr.controllers.rest;
2
3import edu.gjoko.schedlr.dto.ServiceDto;
4import edu.gjoko.schedlr.entity.Service;
5import edu.gjoko.schedlr.mappers.ServiceDtoMapper;
6import edu.gjoko.schedlr.services.ServicesService;
7import lombok.AllArgsConstructor;
8import org.springframework.util.CollectionUtils;
9import org.springframework.web.bind.annotation.*;
10
11import javax.servlet.http.HttpServletRequest;
12import java.util.List;
13import java.util.Objects;
14
15@RestController
16@RequestMapping("api/service")
17@AllArgsConstructor
18public class ServiceApi {
19
20
21 private ServicesService service;
22 private ServiceDtoMapper serviceDtoMapper;
23 @PostMapping(path="/delete")
24 public void saveBusiness(@RequestBody List<Service> serviceList) {
25 if(!CollectionUtils.isEmpty(serviceList)) {
26 List<Long> serviceIds = serviceList.stream()
27 .map(Service::getId)
28 .filter(Objects::nonNull)
29 .toList();
30 service.deleteByIds(serviceIds);
31 }
32 }
33
34 @PatchMapping
35 public void updateServices (@RequestBody List<Service> serviceList, HttpServletRequest request) {
36 Long ownerId = (long) request.getSession(true).getAttribute("stakeholderId");
37 service.saveOrUpdateServices(serviceList, ownerId);
38 }
39
40 @GetMapping
41 public List<ServiceDto> searchServicesByKeyWord(@RequestParam(value = "searchKeyword", required = false) String searchKeyWord) {
42 return service.getServicesByKeyword(searchKeyWord)
43 .stream()
44 .map(serviceDtoMapper::serviceToServiceDto)
45 .toList();
46 }
47}
Note: See TracBrowser for help on using the repository browser.