Skip to content

Commit 92bc716

Browse files
authored
✨ Feature - 기업 검색, 주요 기업 조회, 일반 기업 조회 API를 구현한다.
✨ Feature - 기업 검색, 주요 기업 조회, 일반 기업 조회 API를 구현한다.
2 parents 2abf935 + f1bd43a commit 92bc716

15 files changed

Lines changed: 534 additions & 19 deletions

build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ group = 'sopt'
88
version = '0.0.1-SNAPSHOT'
99
description = 'Demo project for Spring Boot'
1010

11+
def querydslDir = "$buildDir/generated/querydsl"
12+
1113
java {
1214
toolchain {
1315
languageVersion = JavaLanguageVersion.of(21)
@@ -30,6 +32,19 @@ dependencyManagement {
3032
}
3133
}
3234

35+
// QueryDSL 설정
36+
sourceSets {
37+
main.java.srcDirs += [querydslDir]
38+
}
39+
40+
tasks.withType(JavaCompile).configureEach {
41+
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
42+
}
43+
44+
clean.doLast {
45+
file(querydslDir).deleteDir()
46+
}
47+
3348
dependencies {
3449
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
3550
implementation 'org.springframework.boot:spring-boot-starter-validation'
@@ -70,6 +85,12 @@ dependencies {
7085
//webclient
7186
implementation 'org.springframework.boot:spring-boot-starter-webflux'
7287

88+
// QueryDSL
89+
implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
90+
annotationProcessor 'com.querydsl:querydsl-apt:5.1.0:jakarta'
91+
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
92+
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
93+
7394
}
7495

7596
tasks.named('test') {

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

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

3+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
34
import lombok.RequiredArgsConstructor;
4-
import org.springframework.web.bind.annotation.PathVariable;
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RestController;
7-
import sopt.comfit.company.dto.response.GetCompanyResponseDto;
8-
import sopt.comfit.company.dto.response.GetSuggestionCompanyResponseDto;
9-
import sopt.comfit.company.service.CompanyService;
10-
import sopt.comfit.global.annotation.LoginUser;
5+
import org.springframework.data.domain.PageRequest;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.web.bind.annotation.*;
118

129
import java.util.List;
1310

11+
import sopt.comfit.company.domain.EScale;
12+
import sopt.comfit.company.dto.response.*;
13+
import sopt.comfit.company.service.CompanyService;
14+
import sopt.comfit.global.annotation.LoginUser;
15+
import sopt.comfit.global.dto.PageDto;
16+
import sopt.comfit.global.enums.EIndustry;
17+
import sopt.comfit.global.enums.ESort;
18+
1419
@RestController
1520
@RequestMapping("/api/v1/companies")
1621
@RequiredArgsConstructor
17-
public class CompanyController implements CompanySwagger{
22+
public class CompanyController implements CompanySwagger {
1823

1924
private final CompanyService companyService;
2025

26+
27+
@Override
28+
public PageDto<GetCompanyListResponseDto> getCompanyList(@RequestParam(required = false) String keyword,
29+
@RequestParam(required = false) String industry,
30+
@RequestParam(required = false) String scale,
31+
@RequestParam(required = false) String sort,
32+
@RequestParam(defaultValue = "1") int page,
33+
@RequestParam(required = false) Boolean isRecruited) {
34+
35+
Pageable pageable = PageRequest.of(Math.min(page - 1, 0), 8);
36+
EIndustry industryEnum = industry != null ? EIndustry.from(industry) : null;
37+
EScale scaleEnum = scale != null ? EScale.valueOf(scale) : null;
38+
ESort sortEnum = sort != null ? ESort.valueOf(sort) : null;
39+
40+
41+
return companyService.getCompanyList(keyword, industryEnum, scaleEnum, sortEnum, isRecruited, pageable);
42+
}
43+
44+
@Override
45+
public List<GetCompanySearchResponseDto> getCompanySearchList(@RequestParam String keyword){
46+
47+
return companyService.getCompanySearchList(keyword);
48+
}
49+
50+
51+
@Override
52+
public List<FeaturedCompanyResponseDto> getFeaturedCompanies(@LoginUser(required = false) Long userId,
53+
@RequestParam int rank) {
54+
if (userId == null) {
55+
return companyService.getFeaturedCompaniesWithoutUser();
56+
}
57+
return companyService.getFeaturedCompaniesWithUser(userId, rank);
58+
}
59+
2160
@Override
2261
public GetCompanyResponseDto getCompany(@LoginUser(required = false) Long userId ,
2362
@PathVariable Long companyId){
2463
if(userId == null) {
2564
return companyService.getPublicCompany(companyId);
2665
}
66+
2767
return companyService.getCompany(userId ,companyId);
2868

2969
}

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

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,91 @@
99
import io.swagger.v3.oas.annotations.tags.Tag;
1010
import org.springframework.web.bind.annotation.GetMapping;
1111
import org.springframework.web.bind.annotation.PathVariable;
12-
import sopt.comfit.company.dto.response.GetCompanyResponseDto;
13-
import sopt.comfit.company.dto.response.GetSuggestionCompanyResponseDto;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
import sopt.comfit.company.dto.response.*;
1414
import sopt.comfit.global.annotation.LoginUser;
1515
import sopt.comfit.global.dto.CommonApiResponse;
1616
import sopt.comfit.global.dto.CustomErrorResponse;
17+
import sopt.comfit.global.dto.PageDto;
1718

1819
import java.util.List;
1920

2021
@Tag(name = "Company", description = "기업 관련 API")
2122
public interface CompanySwagger {
2223

24+
25+
@Operation(
26+
summary = "기업 검색/조회 API",
27+
description = "기업검색/조회 API 입니다"
28+
)
29+
@ApiResponses({
30+
@ApiResponse(responseCode = "200", description = "기업 검색/조회 성공",
31+
content = @Content(mediaType = "application/json",
32+
schema = @Schema(implementation = CommonApiResponse.class))),
33+
34+
@ApiResponse(responseCode = "403", description = "권한 오류",
35+
content = @Content(mediaType = "application/json",
36+
schema = @Schema(implementation = CustomErrorResponse.class))),
37+
@ApiResponse(responseCode = "401", description = "헤더값 오류",
38+
content = @Content(mediaType = "application/json",
39+
schema = @Schema(implementation = CustomErrorResponse.class))),
40+
@ApiResponse(responseCode = "400", description = "올바르지 않은 값입니다",
41+
content = @Content(mediaType = "application/json",
42+
schema = @Schema(implementation = CustomErrorResponse.class)))
43+
})
44+
@GetMapping
45+
@SecurityRequirement(name = "JWT")
46+
PageDto<GetCompanyListResponseDto> getCompanyList(@RequestParam(required = false) String keyword,
47+
@RequestParam(required = false) String industry,
48+
@RequestParam(required = false) String scale,
49+
@RequestParam(required = false) String sort,
50+
@RequestParam(defaultValue = "1") int page,
51+
@RequestParam(required = false) Boolean isRecruited);
52+
@Operation(
53+
summary = "기업 검색 API",
54+
description = "기업검색 API 입니다"
55+
)
56+
@ApiResponses({
57+
@ApiResponse(responseCode = "200", description = "기업 검색 성공",
58+
content = @Content(mediaType = "application/json",
59+
schema = @Schema(implementation = CommonApiResponse.class))),
60+
61+
@ApiResponse(responseCode = "403", description = "권한 오류",
62+
content = @Content(mediaType = "application/json",
63+
schema = @Schema(implementation = CustomErrorResponse.class))),
64+
@ApiResponse(responseCode = "401", description = "헤더값 오류",
65+
content = @Content(mediaType = "application/json",
66+
schema = @Schema(implementation = CustomErrorResponse.class)))
67+
})
68+
@GetMapping("/search")
69+
@SecurityRequirement(name= "JWT")
70+
List<GetCompanySearchResponseDto> getCompanySearchList(@RequestParam String keyword);
71+
72+
73+
@Operation(
74+
summary = "주요 기업 조회 API",
75+
description = "주요 기업 조회 API입니다. 토큰이 없으면 랜덤 3개, 토큰이 있으면 rank에 따라 사용자의 관심 산업군 기업을 반환합니다."
76+
)
77+
@SecurityRequirement(name = "JWT")
78+
@ApiResponses({
79+
@ApiResponse(responseCode = "200", description = "주요 기업 조회 성공",
80+
content = @Content(mediaType = "application/json",
81+
schema = @Schema(implementation = CommonApiResponse.class))),
82+
83+
@ApiResponse(responseCode = "403", description = "권한 오류",
84+
content = @Content(mediaType = "application/json",
85+
schema = @Schema(implementation = CustomErrorResponse.class))),
86+
@ApiResponse(responseCode = "401", description = "헤더값 오류",
87+
content = @Content(mediaType = "application/json",
88+
schema = @Schema(implementation = CustomErrorResponse.class))),
89+
@ApiResponse(responseCode = "400", description = "올바르지 않은 값입니다",
90+
content = @Content(mediaType = "application/json",
91+
schema = @Schema(implementation = CustomErrorResponse.class)))
92+
})
93+
@GetMapping("/major")
94+
List<FeaturedCompanyResponseDto> getFeaturedCompanies(@LoginUser Long userId,
95+
@RequestParam int rank);
96+
2397
@Operation(
2498
summary = "기업 상세 정보 조회 API",
2599
description = "기업 상세 정보 조회 API입니다"
@@ -42,7 +116,7 @@ public interface CompanySwagger {
42116
@GetMapping("{companyId}")
43117
@SecurityRequirement(name = "JWT")
44118
GetCompanyResponseDto getCompany(@LoginUser(required = false) Long userId ,
45-
@PathVariable Long companyId);
119+
@PathVariable Long companyId);
46120

47121
@Operation(
48122
summary = "추천기업 조회 API",
@@ -59,4 +133,5 @@ GetCompanyResponseDto getCompany(@LoginUser(required = false) Long userId ,
59133
})
60134
@GetMapping("{companyId}/suggestion")
61135
List<GetSuggestionCompanyResponseDto> getSuggestionCompany(@PathVariable Long companyId);
136+
62137
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package sopt.comfit.company.domain;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
5+
import org.springframework.data.repository.query.Param;
46
import sopt.comfit.global.enums.EIndustry;
57

68
import java.util.List;
79

8-
public interface CompanyRepository extends JpaRepository<Company, Long> {
10+
public interface CompanyRepository extends JpaRepository<Company, Long>, CompanyRepositoryCustom {
11+
12+
@Query("SELECT c.id FROM Company c WHERE c.industry = :industry")
13+
List<Long> findIdsByIndustry(@Param("industry") EIndustry industry);
14+
915
List<Company> findByIndustryAndIdNot(EIndustry industry, Long id);
16+
17+
@Query("SELECT c.id FROM Company c")
18+
List<Long> findAllIds();
19+
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);
1025
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package sopt.comfit.company.domain;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
5+
import sopt.comfit.company.dto.response.GetCompanyListResponseDto;
6+
import sopt.comfit.global.enums.EIndustry;
7+
import sopt.comfit.global.enums.ESort;
8+
9+
public interface CompanyRepositoryCustom {
10+
11+
Page<GetCompanyListResponseDto> getCompanyList(
12+
String keyword,
13+
EIndustry industry,
14+
EScale scale,
15+
Boolean isRecruited,
16+
ESort sort,
17+
Pageable pageable
18+
);
19+
20+
}

0 commit comments

Comments
 (0)