Skip to content

Commit 1f4237f

Browse files
committed
feat: SearchCompanyList API #35
1 parent ddda496 commit 1f4237f

4 files changed

Lines changed: 22 additions & 23 deletions

File tree

src/main/java/sopt/comfit/company/controller/CompanyController.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package sopt.comfit.company.controller;
22

3+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
34
import lombok.RequiredArgsConstructor;
45
import org.springframework.data.domain.PageRequest;
56
import org.springframework.data.domain.Pageable;
6-
import org.springframework.web.bind.annotation.PathVariable;
7-
import org.springframework.web.bind.annotation.RequestMapping;
8-
import org.springframework.web.bind.annotation.RequestParam;
9-
import org.springframework.web.bind.annotation.RestController;
7+
import org.springframework.web.bind.annotation.*;
108

119
import java.util.List;
1210

1311
import sopt.comfit.company.domain.EScale;
14-
import sopt.comfit.company.dto.response.FeaturedCompanyResponseDto;
15-
import sopt.comfit.company.dto.response.GetCompanyListResponseDto;
16-
import sopt.comfit.company.dto.response.GetCompanyResponseDto;
17-
import sopt.comfit.company.dto.response.GetSuggestionCompanyResponseDto;
12+
import sopt.comfit.company.dto.response.*;
1813
import sopt.comfit.company.service.CompanyService;
1914
import sopt.comfit.global.annotation.LoginUser;
2015
import sopt.comfit.global.dto.PageDto;
@@ -46,6 +41,12 @@ public PageDto<GetCompanyListResponseDto> getCompanyList(@RequestParam(required
4641
return companyService.getCompanyList(keyword, industryEnum, scaleEnum, sortEnum, isRecruited, pageable);
4742
}
4843

44+
@GetMapping("/search")
45+
@SecurityRequirement(name= "JWT")
46+
public List<CompanySearchResponseDto> getCompanySearchList(@RequestParam String keyword){
47+
48+
return companyService.getCompanySearchList(keyword);
49+
}
4950

5051

5152
@Override

src/main/java/sopt/comfit/company/domain/CompanyRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ public interface CompanyRepository extends JpaRepository<Company, Long>, Company
1717
@Query("SELECT c.id FROM Company c")
1818
List<Long> findAllIds();
1919

20+
@Query("SELECT c FROM Company c " +
21+
"WHERE LOWER(c.name) LIKE LOWER(CONCAT('%', :keyword, '%')) " +
22+
"ORDER BY CASE WHEN LOWER(c.name) LIKE LOWER(CONCAT(:keyword, '%')) THEN 0 ELSE 1 END, " +
23+
"LENGTH(c.name) ASC")
24+
List<Company> searchByKeyword(@Param("keyword") String keyword);
2025
}

src/main/java/sopt/comfit/company/dto/response/CompanySearchListResponseDto.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/sopt/comfit/company/service/CompanyService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import org.springframework.transaction.annotation.Transactional;
88
import org.springframework.web.bind.annotation.RequestParam;
99
import sopt.comfit.company.domain.*;
10-
import sopt.comfit.company.dto.response.FeaturedCompanyResponseDto;
11-
import sopt.comfit.company.dto.response.GetCompanyListResponseDto;
12-
import sopt.comfit.company.dto.response.GetCompanyResponseDto;
13-
import sopt.comfit.company.dto.response.GetSuggestionCompanyResponseDto;
10+
import sopt.comfit.company.dto.response.*;
1411
import sopt.comfit.company.exception.CompanyErrorCode;
1512
import sopt.comfit.global.dto.PageDto;
1613
import sopt.comfit.global.enums.EIndustry;
@@ -49,6 +46,13 @@ public PageDto<GetCompanyListResponseDto> getCompanyList( String keyword,
4946
));
5047
}
5148

49+
@Transactional(readOnly = true)
50+
public List<CompanySearchResponseDto> getCompanySearchList(String keyword){
51+
52+
return companyRepository.searchByKeyword(keyword).stream()
53+
.map(CompanySearchResponseDto::from)
54+
.collect(Collectors.toList());
55+
}
5256

5357

5458
@Transactional(readOnly = true)

0 commit comments

Comments
 (0)