forked from Kernel360/f1-JDON-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7508f7b
commit 41043d9
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
module-api/src/main/java/kernel/jdon/jobcategory/controller/JobCategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
module-api/src/main/java/kernel/jdon/jobcategory/dto/response/FindListJobGroupResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
module-api/src/main/java/kernel/jdon/jobcategory/repository/JobCategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
27 changes: 27 additions & 0 deletions
27
module-api/src/main/java/kernel/jdon/jobcategory/service/JobCategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |