Changeset f29cd58 for src/main/java/edu


Ignore:
Timestamp:
01/15/24 00:11:01 (10 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
943857c
Parents:
e8999eb
Message:

Add services search functionality.

Location:
src/main/java/edu/gjoko/schedlr
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/controllers/rest/ServiceApi.java

    re8999eb rf29cd58  
    11package edu.gjoko.schedlr.controllers.rest;
    22
     3import edu.gjoko.schedlr.dto.ServiceDto;
    34import edu.gjoko.schedlr.entity.Service;
     5import edu.gjoko.schedlr.mappers.ServiceDtoMapper;
    46import edu.gjoko.schedlr.services.ServicesService;
    57import lombok.AllArgsConstructor;
     
    1820
    1921    private ServicesService service;
     22    private ServiceDtoMapper serviceDtoMapper;
    2023    @PostMapping(path="/delete")
    2124    public void saveBusiness(@RequestBody List<Service> serviceList) {
     
    3437        service.saveOrUpdateServices(serviceList, ownerId);
    3538    }
     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    }
    3647}
  • src/main/java/edu/gjoko/schedlr/entity/Service.java

    re8999eb rf29cd58  
    5050    private Business business;
    5151
     52    @Column(name = "description")
     53    private String description;
     54
    5255    @OneToMany(mappedBy="service")
    5356    @JsonManagedReference(value = "serviceAppointments")
  • src/main/java/edu/gjoko/schedlr/repositories/ServiceRepository.java

    re8999eb rf29cd58  
    1111@Repository
    1212public interface ServiceRepository extends JpaRepository<Service, Long> {
     13
     14    @Query(value = "select s from Service as s " +
     15            " where (s.serviceType.name like CONCAT('%', :keyword, '%') " +
     16            " or s.description like CONCAT('%', :keyword, '%'))" +
     17            " and s.serviceStatus = 'ACTIVE'")
     18    List<Service> getServicesByKeyword(String keyword);
    1319}
  • src/main/java/edu/gjoko/schedlr/services/ServicesService.java

    re8999eb rf29cd58  
    55import edu.gjoko.schedlr.entity.ServiceType;
    66import edu.gjoko.schedlr.repositories.BusinessRepository;
    7 import edu.gjoko.schedlr.repositories.BusinessTypeRepository;
    87import edu.gjoko.schedlr.repositories.ServiceRepository;
    98import edu.gjoko.schedlr.repositories.ServiceTypeRepository;
     
    2928    }
    3029
     30    public List<edu.gjoko.schedlr.entity.Service> getServicesByKeyword(String keyword) {
     31        return serviceRepository.getServicesByKeyword(keyword);
     32    }
     33
    3134    public void saveOrUpdateServices(List<edu.gjoko.schedlr.entity.Service> serviceList, Long ownerId) {
    3235        if (!CollectionUtils.isEmpty(serviceList)) {
     
    3841                    found.setPrice(service.getPrice());
    3942                    found.setServiceStatus(ServiceStatus.ACTIVE);
     43                    found.setDescription(service.getDescription());
    4044                    serviceRepository.save(found);
    4145                } else {
Note: See TracChangeset for help on using the changeset viewer.