Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 요청에 모든 데이터를 담을 수 있도록 구성해봅시다.

Expand Down Expand Up @@ -57,4 +58,4 @@ Aggregate란, 여러 도메인을 하나로 합치는 과정을 의미합니다.

제출지 : ymecca730135@gmail.com

### 마감시간 : 2024:05:11/21:30
### 마감시간 : 2024:05:11/21:30
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.Registration;
import com.econovation.third_project.dto.response.AdminPageResponse;
import com.econovation.third_project.service.GetAdminPage;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -13,6 +15,7 @@
@RequiredArgsConstructor
public class AdminQueryController {
private final Database database;
private final GetAdminPage getAdminPage;

// 예시 코드
@PostMapping("/registration")
Expand All @@ -25,4 +28,9 @@ public ResponseEntity<Registration> getRegistration(String userId) {
return ResponseEntity.ok().body(database.getRegistration(userId));
}

@GetMapping("/admin")
public ResponseEntity<AdminPageResponse> getAdminPage(){
return ResponseEntity.ok().body();
}

}
16 changes: 16 additions & 0 deletions src/main/java/com/econovation/third_project/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,20 @@ public void register(Registration registrationRequest) {
public Registration getRegistration(String userId) {
return registration.get(userId);
}

public Map<String, Registration> getAllRegistration(){
return this.registration;
}

public Map<String, PersonalInformation> getAllPersonalInformation(){
return this.personalInformation;
}

public Map<String, Path> getAllPath(){
return this.path;
}

public Map<String, DesiredTime> getAllDesiredTime(){
return this.desiredTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.econovation.third_project.dto.response;

public class AdminPageResponse {
private HopeField hopeField;
private Priority priority;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.econovation.third_project.dto.response;

public class HopeField {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.econovation.third_project.dto.response;

public class Priority {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.econovation.third_project.service;


import java.util.Map;

public class ApplicantMapper {
Map<String, Integer> applicantNum;
Map<String, int[]> applicantPriority;

public ApplicantMapper(Map<String, Integer> applicantNum, Map<String, int[]> applicantPriority) {
this.applicantNum = applicantNum;
this.applicantPriority = applicantPriority;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.econovation.third_project.service;

import java.util.Map;

public class DesiredTimeMapper {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.econovation.third_project.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetAdminPage {
private final GetApplicant getApplicant;
private final GetDesiredTime getDesiredTime;
private final GetMajor getMajor;
private final GetPath getPath;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.econovation.third_project.service;

import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.Registration;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetApplicant {
private final Database db;

public ApplicantMapper getAllApplicant(){
Map<String, Registration> allRegistration = db.getAllRegistration();

// PG 개발자, PM 기획자, DE 디자이너
// key = hopeField, value = 몇 명인지
Map<String, Integer> allApplicantNum = new HashMap<>();

allApplicantNum.put("PG", 0);
allApplicantNum.put("PM", 0);
allApplicantNum.put("DE", 0);

// value = Registration
for (String key : allRegistration.keySet()){
Registration registration = allRegistration.get(key);
allApplicantNum.put(registration.getHopeField(), allApplicantNum.get(registration.getHopeField()) + 1);
}

// WEB, APP, AI, GAME
// key = firstPriority, secondPriority
Map<String, int[]> allApplicantPriority = new HashMap<>();

allApplicantPriority.put("WEB", new int[2]);
allApplicantPriority.put("APP", new int[2]);
allApplicantPriority.put("AI", new int[2]);
allApplicantPriority.put("GAME", new int[2]);
Comment on lines +22 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put put put put 해서 메소드 하나에 별도로 인덱스를 접근해서 초기화 하는 코드 하나로 지금 거의 10줄이 넘게 소요되고 있죠? 차라리 init 함수를 따로 빼도 좋겠습니다.


// value = Registration
for (String key : allRegistration.keySet()){
Registration registration = allRegistration.get(key);
int[] firstPriority = allApplicantPriority.get(registration.getFirstPriority());
int[] secondPriority = allApplicantPriority.get(registration.getSecondPriority());

firstPriority[0] += 1;
secondPriority[1] += 1;

}

Comment on lines +42 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1씩 늘려가며 집계하는 코드는 좋지 않습니다. 나중에 100만건이 있으면 100만번 더하는 것이 좋을까요? 다시 고민!

return new ApplicantMapper(allApplicantNum, allApplicantPriority);
}

// public Map<String, int[]> getAllApplicantPriority(){
// Map<String, Registration> allRegistration = db.getAllRegistration();
// // WEB, APP, AI, GAME
// Map<String, int[]> allApplicantPriority = new HashMap<>();
//
// allApplicantPriority.put("WEB", new int[2]);
// allApplicantPriority.put("APP", new int[2]);
// allApplicantPriority.put("AI", new int[2]);
// allApplicantPriority.put("GAME", new int[2]);
//
// // value = Registration
// for (String key : allRegistration.keySet()){
// Registration registration = allRegistration.get(key);
// int[] firstPriority = allApplicantPriority.get(registration.getFirstPriority());
// int[] secondPriority = allApplicantPriority.get(registration.getSecondPriority());
//
// firstPriority[0] += 1;
// secondPriority[1] += 1;
//
// }
// return allApplicantPriority;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.econovation.third_project.service;

import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.DesiredTime;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetDesiredTime {

private final Database db;

public DesiredTimeMapper getAllDesiredTime() {
Map<String, DesiredTime> allDesiredTime = db.getAllDesiredTime();
for (String key : allDesiredTime.keySet()){
DesiredTime desiredTime = allDesiredTime.get(key);
for (int[] times: desiredTime.getDesiredTime()){
int startTime = times[0];
int endTime = times[1];


}
Comment on lines +15 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return이 없는데 덜 짜신건가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네...덜 짰습니다


}
}

}
47 changes: 47 additions & 0 deletions src/main/java/com/econovation/third_project/service/GetMajor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.econovation.third_project.service;

import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.PersonalInformation;
import com.econovation.third_project.database.Registration;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetMajor {
private final Database db;

public Map<String, Integer> getAllMajor(){
Map<String, PersonalInformation> allPersonalInformation = db.getAllPersonalInformation();
// PG 개발자, PM 기획자, DE 디자이너
// key = hopeField, value = 몇 명인지
Map<String, Integer> allMajor = new HashMap<>();


for (String key : allPersonalInformation.keySet()){
PersonalInformation personalInformation = allPersonalInformation.get(key);

String major = personalInformation.getMajor();
String doubleMajor = personalInformation.getDoubleMajor();
String minor = personalInformation.getMinor();

// 리팩토링 예정
if(!allMajor.containsKey(major)){
allMajor.put(major, 0);
}
if(!allMajor.containsKey(doubleMajor)){
allMajor.put(doubleMajor, 0);
}
if(!allMajor.containsKey(minor)){
allMajor.put(minor, 0);
}

allMajor.put(major, allMajor.get(major) + 1);
allMajor.put(doubleMajor, allMajor.get(doubleMajor) + 1);
allMajor.put(minor, allMajor.get(minor) + 1);
Comment on lines +31 to +43
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

르블랑의 법칙

나는 현재 충분히 아름다운 코드를 짜고 있는가?
우리 모두는 자신이 짠 쓰레기 코드를 쳐다보며 나중에 손보겠다고 생각한 경험이 있다. 우리 모두는 대충 짠 프로그램이 돌아간다는 사실에 안도감을 느끼며 그래도 안 돌아가는 프로그램보다 돌아가는 쓰레기가 좋다고 스스로를 위로한 경험이 있다. 다시 돌아와 나중에 정리하겠다고 다짐했었다. 물론 그때 그 시절 우리는 르블랑의 법칙을 몰랐다. 나중은 결코 오지 않는다.

}
return allMajor;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/econovation/third_project/service/GetPath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.econovation.third_project.service;

import com.econovation.third_project.database.Database;
import com.econovation.third_project.database.Path;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetPath {
private final Database db;

public Map<String, Integer> getAllApplicantNum(){
Map<String, Path> allPath = db.getAllPath();
// 홍보 포스터, 학과 공지사항, 지인 소개, 인스타그램, 에브리타임
// key = supportPath, value = 몇 명인지
Map<String, Integer> allSupportPath = new HashMap<>();
allSupportPath.put("홍보 포스터", 0);
allSupportPath.put("학과 공지사항", 0);
allSupportPath.put("지인 소개", 0);
allSupportPath.put("지인 인스타그램", 0);
allSupportPath.put("에브리타임", 0);

for (String key : allPath.keySet()){
Path path = allPath.get(key);
allSupportPath.put(path.getSupportPath(), allSupportPath.get(path.getSupportPath()) + 1);
}
return allSupportPath;
}
}