-
Notifications
You must be signed in to change notification settings - Fork 6
3주차 과제 (윤석호) #17
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
Open
inferior3x
wants to merge
9
commits into
JNU-econovation:YoonSeokHo3
Choose a base branch
from
inferior3x:YoonSeokHo3
base: YoonSeokHo3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
3주차 과제 (윤석호) #17
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6b96ea1
feat: 테스트 종료
inferior3x d2d1793
feat: 지원 현황 페이지 api
inferior3x d051aa6
fix
inferior3x 9e548d4
동기 API
inferior3x 0ca8248
feat: 병렬 처리
inferior3x 59ade23
comment: todo
inferior3x 70e6cde
fix: 27기 DesiredTime 삭제
inferior3x eda68fc
컨트롤러에서 집계 로직 분리, 나머지 개선
inferior3x cab8423
fix: aggregator
inferior3x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/com/econovation/third_project/agrregate/AdminPageQuery.java
This file contains hidden or 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,9 @@ | ||
| package com.econovation.third_project.agrregate; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface AdminPageQuery { | ||
| String getType(); | ||
| List<?> execute(); | ||
|
|
||
| } |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/econovation/third_project/agrregate/AdminPageQueryAggregator.java
This file contains hidden or 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,52 @@ | ||
| package com.econovation.third_project.agrregate; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| //TODO: 제네릭? | ||
| @Component | ||
| public class AdminPageQueryAggregator { | ||
| private final Map<String, AdminPageQuery> queries; | ||
| public AdminPageQueryAggregator(List<AdminPageQuery> queries) { | ||
| this.queries = queries.stream() | ||
| .collect(Collectors.toMap(AdminPageQuery::getType, Function.identity())); | ||
| } | ||
|
|
||
| public Map<String, List<?>> aggregate(Set<String> requests){ | ||
| List<AdminPageQuery> queriesToExecute = getQueriesToExecute(requests); | ||
| Map<String, CompletableFuture<List<?>>> executedQueries = executeQueriesAsync(queriesToExecute); | ||
| return aggregateResults(executedQueries); | ||
| } | ||
|
|
||
| private List<AdminPageQuery> getQueriesToExecute(Set<String> requests){ | ||
| return requests.stream() | ||
| .map(request -> Optional.ofNullable(queries.get(request)) | ||
| .orElseThrow(IllegalArgumentException::new) | ||
| ) | ||
| .toList(); | ||
| } | ||
|
|
||
| private Map<String, CompletableFuture<List<?>>> executeQueriesAsync(List<AdminPageQuery> queriesToExecute){ | ||
| return queriesToExecute.stream() | ||
| .collect(Collectors.toMap( | ||
| AdminPageQuery::getType, | ||
| query-> CompletableFuture.supplyAsync(query::execute) | ||
| )); | ||
| } | ||
|
|
||
| private Map<String, List<?>> aggregateResults(Map<String, CompletableFuture<List<?>>> executedQueries) { | ||
| return CompletableFuture.allOf(executedQueries.values().toArray(new CompletableFuture[0])) | ||
| .<Map<String, List<?>>>thenApply(v -> | ||
| executedQueries.entrySet().stream() | ||
| .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().join())) | ||
| ) | ||
| .join(); | ||
| } | ||
|
|
||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/econovation/third_project/agrregate/PathQuery.java
This file contains hidden or 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,21 @@ | ||
| package com.econovation.third_project.agrregate; | ||
|
|
||
| import com.econovation.third_project.service.PathService; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class PathQuery implements AdminPageQuery{ | ||
| private final PathService pathService; | ||
| @Override | ||
| public String getType() { | ||
| return "path"; | ||
| } | ||
|
|
||
| @Override | ||
| public List<?> execute() { | ||
| return pathService.getApplicantNumberEachPath(); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/econovation/third_project/config/Field.java
This file contains hidden or 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,20 @@ | ||
| package com.econovation.third_project.config; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Getter | ||
| public enum Field { | ||
| WEB("WEB"), | ||
| APP("APP"), | ||
| AI("AI"), | ||
| GAME("GAME"), | ||
| IOT("IoT"), | ||
| ARVR("AR/VR"), | ||
| NONE("선택없음"); | ||
|
|
||
| private final String fieldName; | ||
|
|
||
|
|
||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/econovation/third_project/config/Job.java
This file contains hidden or 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,14 @@ | ||
| package com.econovation.third_project.config; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Getter | ||
| public enum Job { | ||
| DEVELOPER("개발자"), | ||
| PLANNER("기획자"), | ||
| DESIGNER("디자이너"); | ||
|
|
||
| private final String jobName; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/econovation/third_project/config/SupportPath.java
This file contains hidden or 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,16 @@ | ||
| package com.econovation.third_project.config; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Getter | ||
| public enum SupportPath { | ||
| POSTER("홍보 포스터"), | ||
| DEPARTMENT_ANNOUNCEMENT("학과 공지사항"), | ||
| ACQUAINTANCE("지인 소개"), | ||
| INSTAGRAM("인스타그램"), | ||
| EVERYTIME("에브리타임"); | ||
| private final String entryPathName; | ||
|
|
||
| } |
34 changes: 21 additions & 13 deletions
34
src/main/java/com/econovation/third_project/controller/AdminQueryController.java
This file contains hidden or 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,28 +1,36 @@ | ||
| package com.econovation.third_project.controller; | ||
|
|
||
| import com.econovation.third_project.database.Database; | ||
| import com.econovation.third_project.database.Registration; | ||
| import com.econovation.third_project.agrregate.AdminPageQueryAggregator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/admin") | ||
| public class AdminQueryController { | ||
| private final Database database; | ||
| private final AdminPageQueryAggregator adminPageQueryAggregator; | ||
|
|
||
| // 예시 코드 | ||
| @PostMapping("/registration") | ||
| public ResponseEntity<Object> postRegistrate(@RequestBody Registration registration) { | ||
| database.register(registration); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| @GetMapping("/registration") | ||
| public ResponseEntity<Registration> getRegistration(String userId) { | ||
| return ResponseEntity.ok().body(database.getRegistration(userId)); | ||
| @GetMapping("/applicants/async-test") | ||
| public ResponseEntity<Map<String, List<?>>> getApplicantsInfo(@RequestBody Set<String> fields){ | ||
| return ResponseEntity.ok().body( | ||
| adminPageQueryAggregator.aggregate(fields)); | ||
| } | ||
|
|
||
|
|
||
| //TODO: | ||
| // 병렬 스트림 + async의 장점, | ||
| // 병렬 스트림, async 각각 적절한 상황, | ||
| // 서비스 메서드마다 다른 인자가 필요한 경우, | ||
| // 일부 의존 관계가 있을경우 어떻게 처리할지 | ||
| // 서비스 메서드 맵 어떻게 뺄지, | ||
| // 적절한 스레드 수 알아보기, | ||
| // 자바 비동기 기초, | ||
|
|
||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/econovation/third_project/controller/ApplicationController.java
This file contains hidden or 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,22 @@ | ||
| package com.econovation.third_project.controller; | ||
|
|
||
| import com.econovation.third_project.dto.CreateApplicationReq; | ||
| import com.econovation.third_project.service.ApplicationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RequestMapping("/api") | ||
| @RequiredArgsConstructor | ||
| @RestController | ||
| public class ApplicationController { | ||
| private final ApplicationService applicationService; | ||
|
|
||
| @PostMapping("/application") | ||
| public ResponseEntity<Integer> createApplication(@RequestBody CreateApplicationReq createApplicationReq){ | ||
| return ResponseEntity.ok().body(applicationService.createApplication(createApplicationReq)); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/econovation/third_project/database/Application.java
This file contains hidden or 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,36 @@ | ||
| package com.econovation.third_project.database; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NonNull; | ||
|
|
||
|
|
||
| @Getter | ||
| public final class Application { | ||
| private static final AtomicInteger lastUsedId = new AtomicInteger(0); | ||
| @NonNull | ||
| private final Integer applicationId = lastUsedId.getAndIncrement(); | ||
| @NonNull | ||
| private final Registration registration; | ||
| @NonNull | ||
| private final PersonalInformation personalInformation; | ||
| @NonNull | ||
| private final Path path; | ||
| @NonNull | ||
| private final DesiredTime desiredTime; | ||
|
|
||
| @Builder | ||
| public Application(Registration registration, PersonalInformation personalInformation, | ||
| Path path, | ||
| DesiredTime desiredTime) { | ||
| this.registration = registration; | ||
| this.personalInformation = personalInformation; | ||
| this.path = path; | ||
| this.desiredTime = desiredTime; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or 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
29 changes: 24 additions & 5 deletions
29
src/main/java/com/econovation/third_project/database/DesiredTime.java
This file contains hidden or 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,13 +1,32 @@ | ||
| package com.econovation.third_project.database; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import java.util.Map; | ||
| import lombok.Getter; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public class DesiredTime { | ||
| String registrationId; | ||
| // 희망 시간 (11 * 3)의 테이블 형태를 준수합니다. | ||
| private List<int[]> desiredTime; | ||
| private static final Map<List<Integer>, List<Integer>> cachedTimes = new HashMap<>(); | ||
| private final List<List<Integer>> desiredTimes; | ||
|
|
||
| public DesiredTime(List<List<Integer>> desiredTimes) { | ||
| validateDesiredTime(desiredTimes); | ||
| this.desiredTimes = desiredTimes.stream() | ||
| .map(time-> cachedTimes.computeIfAbsent(time, t->t)) | ||
| .toList(); | ||
| } | ||
| private void validateDesiredTime(List<List<Integer>> desiredTimes) { | ||
| //27기 기준 | ||
| int interviewDays = 3; | ||
| int hoursPerDay = 11; | ||
|
|
||
| desiredTimes.forEach( | ||
| time -> { | ||
| if (time.get(0) >= interviewDays || time.get(1) >= hoursPerDay) | ||
| throw new IllegalArgumentException("면접 시간 잘못 입력"); | ||
| } | ||
| ); | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsert라는 개념을 put 한줄로 표현한 부분 아주 깔끔합니다. 아주 잘하셨습니다.
차 후, Map이 아니라, 일반 클래스에서도 적용하는 부분도 한번 짜보세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hashMap에 key가 중복인 데이터를 넣을 때 value가 덮어씌워진다는 것을 이용하여 upsert로 표현한게 멋지네요