-
Notifications
You must be signed in to change notification settings - Fork 6
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
3주차 과제(김종민) #19
base: main
Are you sure you want to change the base?
3주차 과제(김종민) #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Aggregate란, 여러 도메인을 하나로 합치는 과정을 의미합니다. | |
|
||
|
||
아래 페이지는 신입모집 어드민 페이지입니다. | ||
<img width="1062" alt="image" src="https://github.com/JNU-econovation/Spring_Hell_Study/assets/54030889/9cc9bc92-923d-4649-bb92-ac914f4f6ab5"> | ||
|
||
하나의 API 요청에 모든 데이터를 담을 수 있도록 구성해봅시다. | ||
|
||
|
@@ -57,4 +58,4 @@ Aggregate란, 여러 도메인을 하나로 합치는 과정을 의미합니다. | |
|
||
제출지 : [email protected] | ||
|
||
### 마감시간 : 2024:05:11/21:30 | ||
### 마감시간 : 2024:05:11/21:30 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class AllApplicantCnt { | ||
|
||
// private final String generation; | ||
// | ||
// private final Integer cnt; | ||
// | ||
// public static AllApplicantCnt of(String generation, Integer cnt){ | ||
// return new AllApplicantCnt(generation, cnt); | ||
// } | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor | ||
@Builder | ||
public class AllApplicantStatistics { | ||
|
||
private final Integer cnt; | ||
|
||
private final Map<String, Integer> hopeFieldCnt; | ||
|
||
private final Map<String, Integer> majorCnt; | ||
|
||
private final Map<String, Integer> pathCnt; | ||
|
||
// 이게 난관이네 | ||
private final DesiredTimeStatistics desiredTimes; | ||
Comment on lines
+13
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 선언할 경우 나중에 캐시나 DB에 최신 데이터를 저장하게 될경우 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ApplyPathCnt { | ||
|
||
private final String path; | ||
|
||
private final Integer cnt; | ||
|
||
public static ApplyPathCnt of(String path, Integer cnt){ | ||
return new ApplyPathCnt(path, cnt); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import com.econovation.third_project.database.DesiredTime; | ||
import lombok.NoArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.*; | ||
|
||
@NoArgsConstructor | ||
public class DesiredTimeStatistics { | ||
|
||
// [1,2] - 김종민 이렇게 저장된다. | ||
private final Map<List<Integer>, List<String>> cnt = new HashMap<>(); | ||
|
||
public void put(List<Integer> key, String value){ | ||
if(cnt.containsKey(key)) cnt.get(key).add(value); | ||
cnt.put(key, Arrays.asList(value)); | ||
} | ||
|
||
public static DesiredTimeStatistics of(List<DesiredTime> desiredTimes){ | ||
desiredTimes.stream() | ||
.peek( | ||
times -> { | ||
List<int[]> desiredTime = times.getDesiredTime(); | ||
for (int i = 0; i < 3; i++) { | ||
List<Integer> tmp = new ArrayList<>(); | ||
int[] targetArr = desiredTime.get(i); | ||
for (int j = 0; j < desiredTime.size(); i++) { | ||
if (targetArr[j] == 1) tmp.add(j); | ||
} | ||
DesiredTimeStatistics.put(tmp,times.getRegistrationId()); | ||
Comment on lines
+25
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stream 필드 내에서 for문을 쓰는 것은 패러다임의 불일치입니다. 함수형과 절차지향의 짬뽕이랄까요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 람다의 매개변수로 times를 주셨는데 stream을 사용했을 때 스트림 원소는 List 이아니라 DesiredTime 객체 1개입니다. 따라서 times보다는 time이 의미에 맞을 것 같네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그리고 desiredTime이 List<int[]> 이라서 내부에서 for문을 이렇게 사용한 것 같은데 flatMap을 사용해서 |
||
} | ||
} | ||
); | ||
|
||
return new DesiredTimeStatistics(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class HopeFieldCnt { | ||
|
||
private final String hopeField; | ||
|
||
private final Integer cnt; | ||
|
||
public static HopeFieldCnt of(String hopeField, Integer cnt){ | ||
return new HopeFieldCnt(hopeField, cnt); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.econovation.third_project.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class MajorCnt { | ||
|
||
private final String major; | ||
|
||
private final Integer cnt; | ||
|
||
public static MajorCnt of(String major, Integer cnt){ | ||
return new MajorCnt(major, cnt); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.econovation.third_project.domain.dto.response; | ||
|
||
public class AdminResponse { | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.econovation.third_project.service; | ||
|
||
import com.econovation.third_project.database.*; | ||
import com.econovation.third_project.domain.AllApplicantCnt; | ||
import com.econovation.third_project.domain.AllApplicantStatistics; | ||
import com.econovation.third_project.domain.ApplyPathCnt; | ||
import com.econovation.third_project.domain.DesiredTimeStatistics; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdminService { | ||
|
||
private final Database database; | ||
|
||
public AllApplicantStatistics getAllStatistics(){ | ||
|
||
return AllApplicantStatistics.builder() | ||
.cnt(getAllRegistration().size()) | ||
.hopeFieldCnt(toHopeFieldCnt(getAllRegistration())) | ||
.majorCnt(toMajorcnt(getAllPersonalInformation())) | ||
.pathCnt(toPathCnt(getAllPath())) | ||
.desiredTimes(toDesiredTimeStatistics(getAllDesiredTimes())) | ||
.build(); | ||
} | ||
|
||
private Map<String, Integer> toHopeFieldCnt(List<Registration> registrations){ | ||
Map<String, Integer> hopeFieldCnt = new HashMap<>(); | ||
|
||
return registrations.stream() | ||
.map(registration -> registration.getHopeField()) | ||
.collect(Collectors.groupingBy( | ||
s -> s, // 키는 희망 분야 그대로 | ||
Collectors.mapping( | ||
s -> 1, // 희망 분야를 1로 변경 | ||
Collectors.reducing(0, (i,j)->i+j) // 누적 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
)); | ||
|
||
} | ||
|
||
// 주전공만 카운트 | ||
// 복수전공까지 카운트 해야 한다. | ||
private Map<String, Integer> toMajorcnt(List<PersonalInformation> personalInformations){ | ||
return personalInformations.stream() | ||
.map(personalInformation -> personalInformation.getMajor()) | ||
.collect(Collectors.groupingBy( | ||
s -> s, | ||
Collectors.mapping( | ||
s -> 1, | ||
Collectors.reducing(0, (i,j)->i+j)) | ||
) | ||
); | ||
} | ||
|
||
|
||
private Map<String, Integer> toPathCnt(List<Path> paths){ | ||
return paths.stream() | ||
.map(path -> path.getSupportPath()) | ||
.collect(Collectors.groupingBy( | ||
s -> s, | ||
Collectors.mapping( | ||
s -> 1, | ||
Collectors.reducing(0, (i,j)->i+j) | ||
) | ||
)); | ||
} | ||
|
||
private DesiredTimeStatistics toDesiredTimeStatistics(List<DesiredTime> desiredTimes){ | ||
|
||
} | ||
|
||
private List<Registration> getAllRegistration(){ return database.getRegistrations(); } | ||
|
||
private List<Path> getAllPath(){ return database.getPaths(); } | ||
|
||
private List<PersonalInformation> getAllPersonalInformation(){ return database.getPersonalInformations(); } | ||
|
||
private List<DesiredTime> getAllDesiredTimes(){ return database.getDesiredTimes(); } | ||
|
||
} |
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.
주석으로 가득찬 코드? 그냥 지우세요 ㅋㅋ 추상 클래스로 선언해둬도 되구요.