Skip to content

Commit

Permalink
Feature: 직군 별 직무 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonseon12 committed Jan 19, 2024
1 parent 7508f7b commit 41043d9
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kernel.jdon.jobcategory.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import kernel.jdon.dto.response.CommonResponse;
import kernel.jdon.jobcategory.dto.response.FindListJobGroupResponse;
import kernel.jdon.jobcategory.service.JobCategoryService;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class JobCategoryController {
private final JobCategoryService jobCategoryService;

@GetMapping("/api/v1/job-categories")
public ResponseEntity<CommonResponse> getJobGroupList() {
FindListJobGroupResponse jobGroupList = jobCategoryService.findJobGroupList();

return ResponseEntity.ok(CommonResponse.of(jobGroupList));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package kernel.jdon.jobcategory.dto.response;

import java.util.List;
import java.util.Map;

import kernel.jdon.jobcategory.domain.JobCategory;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class FindListJobGroupResponse {
private List<FindJobGroupResponse> jobGroupList;

public FindListJobGroupResponse(List<JobCategory> jobGroupList, Map<Long, List<JobCategory>> jobCategoryMap) {
this.jobGroupList = jobGroupList.stream()
.map(jobGroup -> FindJobGroupResponse.of(jobGroup, jobCategoryMap.get(jobGroup.getId())))
.toList();
}

@Getter
@Builder
@AllArgsConstructor
public static class FindJobGroupResponse {
private Long id;
private String name;
private List<FindJobCategoryResponse> jobCategoryList;

public static FindJobGroupResponse of(JobCategory jobCategory, List<JobCategory> jobCategoryList) {
List<FindJobCategoryResponse> list = jobCategoryList.stream()
.map(FindJobCategoryResponse::of)
.toList();

return FindJobGroupResponse.builder()
.id(jobCategory.getId())
.name(jobCategory.getName())
.jobCategoryList(list)
.build();
}
}

@Getter
@Builder
@AllArgsConstructor
public static class FindJobCategoryResponse {
private Long id;
private String name;

public static FindJobCategoryResponse of(JobCategory jobCategory) {
return FindJobCategoryResponse.builder()
.id(jobCategory.getId())
.name(jobCategory.getName())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package kernel.jdon.jobcategory.repository;

import java.util.List;

import kernel.jdon.jobcategory.domain.JobCategory;

public interface JobCategoryRepository extends JobCategoryDomainRepository {
List<JobCategory> findByParentIdIsNull();
List<JobCategory> findByParentId(Long pareantId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kernel.jdon.jobcategory.service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import kernel.jdon.jobcategory.domain.JobCategory;
import kernel.jdon.jobcategory.dto.response.FindListJobGroupResponse;
import kernel.jdon.jobcategory.repository.JobCategoryRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class JobCategoryService {
private final JobCategoryRepository jobCategoryRepository;

public FindListJobGroupResponse findJobGroupList() {
List<JobCategory> findJobGroupList = jobCategoryRepository.findByParentIdIsNull();
Map<Long, List<JobCategory>> groupedCategoryList = findJobGroupList.stream()
.collect(Collectors.toMap(JobCategory::getId, jobGroup ->
jobCategoryRepository.findByParentId(jobGroup.getId())));

return new FindListJobGroupResponse(findJobGroupList, groupedCategoryList);
}
}

0 comments on commit 41043d9

Please sign in to comment.