From c8a260c766226cc383c4fdd45feea8c2845b8703 Mon Sep 17 00:00:00 2001
From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com>
Date: Sat, 11 May 2024 16:11:49 +0900
Subject: [PATCH 1/2] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EA=B3=BC=EC=A0=9C=20?=
=?UTF-8?q?=EB=B0=9C=ED=91=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6a8787e..d4a57ad 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ Aggregate란, 여러 도메인을 하나로 합치는 과정을 의미합니다.
아래 페이지는 신입모집 어드민 페이지입니다.
+
하나의 API 요청에 모든 데이터를 담을 수 있도록 구성해봅시다.
@@ -57,4 +58,4 @@ Aggregate란, 여러 도메인을 하나로 합치는 과정을 의미합니다.
제출지 : ymecca730135@gmail.com
-### 마감시간 : 2024:05:11/21:30
\ No newline at end of file
+### 마감시간 : 2024:05:11/21:30
From bc5140cb0754300a6798afc4f4c79e2e271d2e9e Mon Sep 17 00:00:00 2001
From: KimJongMin
Date: Mon, 13 May 2024 02:09:55 +0900
Subject: [PATCH 2/2] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EA=B3=BC=EC=A0=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/AdminQueryController.java | 8 ++
.../third_project/database/Database.java | 9 ++
.../third_project/database/DesiredTime.java | 6 ++
.../third_project/domain/AllApplicantCnt.java | 17 ++++
.../domain/AllApplicantStatistics.java | 23 +++++
.../third_project/domain/ApplyPathCnt.java | 16 ++++
.../domain/DesiredTimeStatistics.java | 39 +++++++++
.../third_project/domain/HopeFieldCnt.java | 16 ++++
.../third_project/domain/MajorCnt.java | 16 ++++
.../domain/dto/response/AdminResponse.java | 7 ++
.../third_project/service/AdminService.java | 87 +++++++++++++++++++
11 files changed, 244 insertions(+)
create mode 100644 src/main/java/com/econovation/third_project/domain/AllApplicantCnt.java
create mode 100644 src/main/java/com/econovation/third_project/domain/AllApplicantStatistics.java
create mode 100644 src/main/java/com/econovation/third_project/domain/ApplyPathCnt.java
create mode 100644 src/main/java/com/econovation/third_project/domain/DesiredTimeStatistics.java
create mode 100644 src/main/java/com/econovation/third_project/domain/HopeFieldCnt.java
create mode 100644 src/main/java/com/econovation/third_project/domain/MajorCnt.java
create mode 100644 src/main/java/com/econovation/third_project/domain/dto/response/AdminResponse.java
create mode 100644 src/main/java/com/econovation/third_project/service/AdminService.java
diff --git a/src/main/java/com/econovation/third_project/controller/AdminQueryController.java b/src/main/java/com/econovation/third_project/controller/AdminQueryController.java
index 4c15adb..dd42269 100644
--- a/src/main/java/com/econovation/third_project/controller/AdminQueryController.java
+++ b/src/main/java/com/econovation/third_project/controller/AdminQueryController.java
@@ -2,6 +2,8 @@
import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.Registration;
+import com.econovation.third_project.domain.AllApplicantStatistics;
+import com.econovation.third_project.service.AdminService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -13,6 +15,7 @@
@RequiredArgsConstructor
public class AdminQueryController {
private final Database database;
+ private final AdminService adminService;
// 예시 코드
@PostMapping("/registration")
@@ -25,4 +28,9 @@ public ResponseEntity getRegistration(String userId) {
return ResponseEntity.ok().body(database.getRegistration(userId));
}
+ @GetMapping("/admin")
+ public ResponseEntity getAdminInformation(){
+ return ResponseEntity.ok().body(adminService.getAllStatistics());
+ }
+
}
diff --git a/src/main/java/com/econovation/third_project/database/Database.java b/src/main/java/com/econovation/third_project/database/Database.java
index 33b8710..fd2e8b7 100644
--- a/src/main/java/com/econovation/third_project/database/Database.java
+++ b/src/main/java/com/econovation/third_project/database/Database.java
@@ -1,6 +1,7 @@
package com.econovation.third_project.database;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.stereotype.Component;
@@ -22,6 +23,14 @@ public void register(Registration registrationRequest) {
registration.put(UUID.randomUUID().toString(), registrationRequest);
}
+ public List getPaths(){ return path.values().stream().toList(); }
+
+ public List getDesiredTimes(){ return desiredTime.values().stream().toList(); }
+
+ public List getPersonalInformations(){ return personalInformation.values().stream().toList(); }
+
+ public List getRegistrations(){ return registration.values().stream().toList(); }
+
public Registration getRegistration(String userId) {
return registration.get(userId);
}
diff --git a/src/main/java/com/econovation/third_project/database/DesiredTime.java b/src/main/java/com/econovation/third_project/database/DesiredTime.java
index 2d7a140..b3068d4 100644
--- a/src/main/java/com/econovation/third_project/database/DesiredTime.java
+++ b/src/main/java/com/econovation/third_project/database/DesiredTime.java
@@ -11,3 +11,9 @@ public class DesiredTime {
// 희망 시간 (11 * 3)의 테이블 형태를 준수합니다.
private List desiredTime;
}
+
+/**
+ * 0 -> (0,1)
+ * 1 -> (1,2)
+ * 2 -> (2,3) ...
+ */
\ No newline at end of file
diff --git a/src/main/java/com/econovation/third_project/domain/AllApplicantCnt.java b/src/main/java/com/econovation/third_project/domain/AllApplicantCnt.java
new file mode 100644
index 0000000..9b5cfd4
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/AllApplicantCnt.java
@@ -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);
+// }
+
+}
diff --git a/src/main/java/com/econovation/third_project/domain/AllApplicantStatistics.java b/src/main/java/com/econovation/third_project/domain/AllApplicantStatistics.java
new file mode 100644
index 0000000..38ef0dd
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/AllApplicantStatistics.java
@@ -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 hopeFieldCnt;
+
+ private final Map majorCnt;
+
+ private final Map pathCnt;
+
+ // 이게 난관이네
+ private final DesiredTimeStatistics desiredTimes;
+}
diff --git a/src/main/java/com/econovation/third_project/domain/ApplyPathCnt.java b/src/main/java/com/econovation/third_project/domain/ApplyPathCnt.java
new file mode 100644
index 0000000..53cc03a
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/ApplyPathCnt.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/com/econovation/third_project/domain/DesiredTimeStatistics.java b/src/main/java/com/econovation/third_project/domain/DesiredTimeStatistics.java
new file mode 100644
index 0000000..418103a
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/DesiredTimeStatistics.java
@@ -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> cnt = new HashMap<>();
+
+ public void put(List key, String value){
+ if(cnt.containsKey(key)) cnt.get(key).add(value);
+ cnt.put(key, Arrays.asList(value));
+ }
+
+ public static DesiredTimeStatistics of(List desiredTimes){
+ desiredTimes.stream()
+ .peek(
+ times -> {
+ List desiredTime = times.getDesiredTime();
+ for (int i = 0; i < 3; i++) {
+ List 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());
+ }
+ }
+ );
+
+ return new DesiredTimeStatistics();
+ }
+}
diff --git a/src/main/java/com/econovation/third_project/domain/HopeFieldCnt.java b/src/main/java/com/econovation/third_project/domain/HopeFieldCnt.java
new file mode 100644
index 0000000..a60f552
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/HopeFieldCnt.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/com/econovation/third_project/domain/MajorCnt.java b/src/main/java/com/econovation/third_project/domain/MajorCnt.java
new file mode 100644
index 0000000..2a12200
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/MajorCnt.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/com/econovation/third_project/domain/dto/response/AdminResponse.java b/src/main/java/com/econovation/third_project/domain/dto/response/AdminResponse.java
new file mode 100644
index 0000000..2c79558
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/domain/dto/response/AdminResponse.java
@@ -0,0 +1,7 @@
+package com.econovation.third_project.domain.dto.response;
+
+public class AdminResponse {
+
+
+
+}
diff --git a/src/main/java/com/econovation/third_project/service/AdminService.java b/src/main/java/com/econovation/third_project/service/AdminService.java
new file mode 100644
index 0000000..2576bef
--- /dev/null
+++ b/src/main/java/com/econovation/third_project/service/AdminService.java
@@ -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 toHopeFieldCnt(List registrations){
+ Map 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) // 누적
+ )
+ ));
+
+ }
+
+ // 주전공만 카운트
+ // 복수전공까지 카운트 해야 한다.
+ private Map toMajorcnt(List 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 toPathCnt(List 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 desiredTimes){
+
+ }
+
+ private List getAllRegistration(){ return database.getRegistrations(); }
+
+ private List getAllPath(){ return database.getPaths(); }
+
+ private List getAllPersonalInformation(){ return database.getPersonalInformations(); }
+
+ private List getAllDesiredTimes(){ return database.getDesiredTimes(); }
+
+}
\ No newline at end of file