Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”— :: (#421) νŽ˜μ΄μ§€ 개수 쑰회 api #426

Merged
merged 7 commits into from
Sep 26, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.retum.jobis.common.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class TotalPageCountResponse {

private final int totalPageCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public class TeacherQueryCompaniesResponse {

private final List<TeacherQueryCompanyResponse> companies;
private final int totalPageCount;

@Getter
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.ReadOnlyUseCase;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.common.util.NumberUtil;
import team.retum.jobis.domain.company.dto.CompanyFilter;
import team.retum.jobis.domain.company.dto.response.StudentQueryCompaniesResponse;
import team.retum.jobis.domain.company.spi.QueryCompanyPort;
Expand All @@ -23,4 +25,18 @@ public StudentQueryCompaniesResponse execute(Long page, String name) {
queryCompanyPort.queryStudentCompanies(filter)
);
}

public TotalPageCountResponse getTotalPageCount(Long page, String name) {
CompanyFilter filter = CompanyFilter.builder()
.name(name)
.page(page)
.limit(12)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryCompanyPort.getTotalCompanyCount(filter), filter.getLimit()
);

return new TotalPageCountResponse(totalPageCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.ReadOnlyUseCase;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.common.util.NumberUtil;
import team.retum.jobis.domain.code.exception.CodeNotFoundException;
import team.retum.jobis.domain.code.spi.QueryCodePort;
Expand Down Expand Up @@ -38,10 +39,6 @@ public TeacherQueryCompaniesResponse execute(
.page(page)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryCompanyPort.getTotalCompanyCount(filter), filter.getLimit()
);

return new TeacherQueryCompaniesResponse(
queryCompanyPort.queryCompaniesByConditions(filter).stream()
.map(company -> TeacherQueryCompanyResponse.builder()
Expand All @@ -58,11 +55,31 @@ public TeacherQueryCompaniesResponse execute(
.totalAcceptanceCount(company.getTotalAcceptanceCount())
.reviewCount(company.getReviewCount())
.build()
).toList(),
totalPageCount
).toList()
);
}

public TotalPageCountResponse getTotalPageCount(CompanyType type, String companyName, String region, Long businessArea, Long page) {
CompanyFilter filter = CompanyFilter.builder()
.type(type)
.name(companyName)
.region(region)
.businessArea(
businessArea == null ? null :
queryCodePort.queryCodeById(businessArea)
.orElseThrow(() -> CodeNotFoundException.EXCEPTION)
.getKeyword()
)
.page(page)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryCompanyPort.getTotalCompanyCount(filter), filter.getLimit()
);

return new TotalPageCountResponse(totalPageCount);
}

private String getRegionByAddress(String address) {
return address.substring(0, 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class TeacherQueryRecruitmentsResponse {

private final List<TeacherRecruitmentResponse> recruitments;

private final int totalPageCount;

@Getter
@Builder
public static class TeacherRecruitmentResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.ReadOnlyUseCase;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.common.spi.SecurityPort;
import team.retum.jobis.common.util.NumberUtil;
import team.retum.jobis.domain.code.exception.CodeNotFoundException;
import team.retum.jobis.domain.code.spi.QueryCodePort;
import team.retum.jobis.domain.recruitment.dto.RecruitmentFilter;
Expand Down Expand Up @@ -60,6 +62,28 @@ public StudentQueryRecruitmentsResponse execute(
return new StudentQueryRecruitmentsResponse(recruitments);
}

public TotalPageCountResponse getTotalPageCount(String name, Long page, Long jobCode, List<Long> codeIds) {
Long currentStudentId = securityPort.getCurrentUserId();
String jobKeyword = validJobCode(jobCode);

RecruitmentFilter filter = RecruitmentFilter.builder()
.year(Year.now().getValue())
.status(RecruitStatus.RECRUITING)
.companyName(name)
.page(page)
.limit(12)
.codes(codeIds)
.studentId(currentStudentId)
.jobKeyword(jobKeyword)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryRecruitmentPort.getRecruitmentCountByFilter(filter), filter.getLimit()
);

return new TotalPageCountResponse(totalPageCount);
}

private String validJobCode(Long jobCode) {
if (jobCode != null) {
return queryCodePort.queryCodeById(jobCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.ReadOnlyUseCase;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.common.util.NumberUtil;
import team.retum.jobis.domain.recruitment.dto.RecruitmentFilter;
import team.retum.jobis.domain.recruitment.dto.response.TeacherQueryRecruitmentsResponse;
Expand Down Expand Up @@ -30,10 +31,6 @@ public TeacherQueryRecruitmentsResponse execute(String companyName, LocalDate st
.page(page)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryRecruitmentPort.getRecruitmentCountByFilter(filter), filter.getLimit()
);

List<TeacherRecruitmentResponse> recruitments =
queryRecruitmentPort.queryRecruitmentsByFilter(filter).stream()
.map(recruitment ->
Expand All @@ -52,6 +49,25 @@ public TeacherQueryRecruitmentsResponse execute(String companyName, LocalDate st
.build()
).toList();

return new TeacherQueryRecruitmentsResponse(recruitments, totalPageCount);
return new TeacherQueryRecruitmentsResponse(recruitments);
}

public TotalPageCountResponse getTotalPageCount(String companyName, LocalDate start, LocalDate end,
Integer year, RecruitStatus status, Long page) {
RecruitmentFilter filter = RecruitmentFilter.builder()
.companyName(companyName)
.status(status)
.startDate(start)
.endDate(end)
.codes(List.of())
.year(year)
.page(page)
.build();

int totalPageCount = NumberUtil.getTotalPageCount(
queryRecruitmentPort.getRecruitmentCountByFilter(filter), filter.getLimit()
);

return new TotalPageCountResponse(totalPageCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import team.retum.jobis.domain.company.dto.response.QueryCompanyDetailsResponse;
import team.retum.jobis.domain.company.dto.response.QueryReviewAvailableCompaniesResponse;
import team.retum.jobis.domain.company.dto.response.StudentQueryCompaniesResponse;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.domain.company.dto.response.TeacherQueryCompaniesResponse;
import team.retum.jobis.domain.company.dto.response.TeacherQueryEmployCompaniesResponse;
import team.retum.jobis.domain.company.model.CompanyType;
Expand Down Expand Up @@ -83,6 +84,14 @@ public StudentQueryCompaniesResponse studentQueryCompanies(
return studentQueryCompaniesUseCase.execute(page - 1, name);
}

@GetMapping("/student/count")
public TotalPageCountResponse studentQueryCompanyCount(
@RequestParam(value = "page", required = false, defaultValue = "1") Long page,
@RequestParam(value = "name", required = false) String name
) {
return studentQueryCompaniesUseCase.getTotalPageCount(page - 1, name);
}

@GetMapping("/{company-id}")
public QueryCompanyDetailsResponse getCompanyDetails(@PathVariable("company-id") Long companyId) {
return queryCompanyDetailsUseCase.execute(companyId);
Expand Down Expand Up @@ -120,6 +129,17 @@ public TeacherQueryCompaniesResponse queryCompanies(
return teacherQueryCompaniesUseCase.execute(type, companyName, region, businessArea, page - 1);
}

@GetMapping("/teacher/count")
public TotalPageCountResponse queryCompanyCount(
@RequestParam(value = "type", required = false) CompanyType type,
@RequestParam(value = "name", required = false) String companyName,
@RequestParam(value = "region", required = false) String region,
@RequestParam(value = "business_area", required = false) Long businessArea,
@RequestParam(value = "page", defaultValue = "1") Long page
) {
return teacherQueryCompaniesUseCase.getTotalPageCount(type, companyName, region, businessArea, page - 1);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping("/mou")
public void updateMou(@RequestBody @Valid UpdateMouWebRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import team.retum.jobis.common.dto.response.TotalPageCountResponse;
import team.retum.jobis.common.util.StringUtil;
import team.retum.jobis.domain.recruitment.dto.response.QueryRecruitmentDetailResponse;
import team.retum.jobis.domain.recruitment.dto.response.StudentQueryRecruitmentsResponse;
Expand Down Expand Up @@ -99,6 +100,17 @@ public StudentQueryRecruitmentsResponse studentQueryRecruitments(
return studentQueryRecruitmentsUseCase.execute(companyName, page - 1, jobCode, techCodes);
}

@GetMapping("/student/count")
public TotalPageCountResponse studentQueryRecruitmentCount(
@RequestParam(value = "name", required = false) String companyName,
@RequestParam(value = "page", required = false, defaultValue = "1") Long page,
@RequestParam(value = "job_code", required = false) Long jobCode,
@RequestParam(value = "tech_code", required = false) String techCode
) {
List<Long> techCodes = StringUtil.divideString(techCode).stream().map(Long::parseLong).toList();
return studentQueryRecruitmentsUseCase.getTotalPageCount(companyName, page, jobCode, techCodes);
}

@GetMapping("/teacher")
public TeacherQueryRecruitmentsResponse queryRecruitmentList(
@RequestParam(value = "company_name", required = false) String companyName,
Expand All @@ -111,6 +123,18 @@ public TeacherQueryRecruitmentsResponse queryRecruitmentList(
return teacherQueryRecruitmentsUseCase.execute(companyName, start, end, year, status, page - 1);
}

@GetMapping("/teacher/count")
public TotalPageCountResponse queryRecruitmentCount(
@RequestParam(value = "company_name", required = false) String companyName,
@RequestParam(value = "start", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
@RequestParam(value = "end", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end,
@RequestParam(value = "status", required = false) RecruitStatus status,
@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "page", defaultValue = "1") Long page
) {
return teacherQueryRecruitmentsUseCase.getTotalPageCount(companyName, start, end, year, status, page);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping("/status")
public void changeRecruitStatus(@RequestBody @Valid ChangeRecruitmentStatusWebRequest webRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.PATCH, "/recruitments/{recruitment-id}").hasAnyAuthority(COMPANY.name(), TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/recruitments/area/{recruit-area-id}").hasAnyAuthority(COMPANY.name(), TEACHER.name())
.antMatchers(HttpMethod.POST, "/recruitments/{recruitment-id}/area").hasAnyAuthority(COMPANY.name(), TEACHER.name())
.antMatchers(HttpMethod.GET, "/recruitments/student").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.GET, "/recruitments/student").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/recruitments/student/count").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/recruitments/{recruitment-id}").hasAnyAuthority(STUDENT.name(), TEACHER.name())
.antMatchers(HttpMethod.GET, "/recruitments/teacher").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/recruitments/teacher/count").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/recruitments/status").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.DELETE, "/recruitments/{recruitment-id}").hasAnyAuthority(COMPANY.name(), TEACHER.name())
.antMatchers(HttpMethod.DELETE, "/recruitments/area/{recruit-area-id}").hasAnyAuthority(COMPANY.name(), TEACHER.name())
Expand All @@ -95,6 +97,7 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

//companies
.antMatchers(HttpMethod.GET, "/companies/teacher").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/companies/teacher/count").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/companies/type").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/companies/mou").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.POST, "/companies").permitAll()
Expand All @@ -104,8 +107,9 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.POST, "/companies/recruitment").hasAuthority(COMPANY.name())
.antMatchers(HttpMethod.GET, "/companies/{company-id}").hasAnyAuthority(STUDENT.name(), TEACHER.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/companies/student").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/companies/student/count").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/companies/employment").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/companies/review").hasAnyAuthority(STUDENT.name())
.antMatchers(HttpMethod.GET, "/companies/review").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())

//users
.antMatchers(HttpMethod.POST, "/users/login").permitAll()
Expand Down