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
86 changes: 86 additions & 0 deletions src/main/java/com/econovation/third_project/controller/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.econovation.third_project.controller;

import com.econovation.third_project.database.DesiredTime;
import com.econovation.third_project.database.Path;
import com.econovation.third_project.database.PersonalInformation;
import com.econovation.third_project.database.Registration;
import com.econovation.third_project.service.RegistrationService;
import lombok.AllArgsConstructor;
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.RestController;

import java.util.ArrayList;
import java.util.Map;

@RestController
@AllArgsConstructor
public class Test {
RegistrationService registrationService;

@PostMapping("/register")
public String register(@RequestBody Registration registration){
// 예외처리 필요할듯하다.
registrationService.register(registration);
return "success";
}

// 지원자 정보 생성
@PostMapping("/register-personal-inform")
public String registerPersonInform(@RequestBody PersonalInformation personalInformation){
registrationService.registerPersonalInform(personalInformation);
return "success";
}

// 지원자 지원 경로 생성
@PostMapping("/register-path")
public String registerPath(@RequestBody Path path){
registrationService.registerPath(path);
return "success";
}

// 지원자 면접 가능 시간 생성
@PostMapping("/register-desired-time")
public String registerDesiredTime(@RequestBody DesiredTime desiredTime){
registrationService.registerDesiredTime(desiredTime);
return "success";
}


// 전체 지원자 수
@GetMapping("/registrations-count")
public Integer getTotalRegisterCount(){
return registrationService.getRegistrationCount();
}

// 개발자, 기획자, 디자이너 별 지원자 수
@GetMapping("/registrations-hope-count")
public ArrayList<Integer> getHopeFieldsTotalRegisterCount(){
return registrationService.getHopeFieldsTotalCount();
}

// 희망 분야별 지원자 수
@GetMapping("/registrations/first-hope-field")
public Map<String, Integer> getFirstHopeFieldCount() {
return registrationService.getHopeFieldsFirstPriorityCount();
}
@GetMapping("/registrations/second-hope-field")
public Map<String, Integer> getSecondHopeFieldCount() {
return registrationService.getHopeFieldsSecondPriorityCount();
}

// 지원자 학과별 수
@GetMapping("/registrations/department-count")
public Map<String, Integer> getDepartmentCount(){
return registrationService.getDepartmentCount();
}

// 지원 경로별 수
@GetMapping("/registrations/path-count")
public Map<String, Integer> getPathCount(){
return registrationService.getPathCount();
}

}
Comment on lines +18 to +86
Copy link
Collaborator

Choose a reason for hiding this comment

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

인재님 앱 형태로 1개의 url로 합쳐보는 걸 과제로 드렸습니다. 이렇게 웹 요청으로 하게 되면 transmit delay가 엄청 발생할거에요.
최대한 요청 수를 줄일 수 있게 데이터를 구성해봅시다.

75 changes: 72 additions & 3 deletions src/main/java/com/econovation/third_project/database/Database.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.econovation.third_project.database;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;

import org.springframework.stereotype.Component;

/**
Expand All @@ -22,7 +21,77 @@ public void register(Registration registrationRequest) {
registration.put(UUID.randomUUID().toString(), registrationRequest);
}

// PersonalInformation 생성
public void savePersonalInformation(PersonalInformation personalInformationRequest){
personalInformation.put(UUID.randomUUID().toString(), personalInformationRequest);
}

// 지원 경로 생성
public void savePath(Path pathRequest){
path.put(UUID.randomUUID().toString(), pathRequest);
}

// 가능 시간 생성
public void saveDesiredTime(DesiredTime desiredTimeRequest){
desiredTime.put(UUID.randomUUID().toString(),desiredTimeRequest);
}

public Registration getRegistration(String userId) {
return registration.get(userId);
}

// 전체 등록 데이터
public Map<String,Registration> getAllRegistrations(){
return registration;
}

// 전체 소속 데이터
public Map<String,PersonalInformation> getAllPersionalInformation(){
return personalInformation;
}

// 전체 경로 데이터
public Map<String,Path> getAllPath(){
return path;
}

// 전체 시간 데이터
public Map<String,DesiredTime> getAllDesiredTime(){
return desiredTime;
}

// 서비스 파일에 작성해야 하는 로직인지 확인하기
public int getRegistrationCount(){
return registration.size();
}

// 개발자, 기획자, 디자이너 각각 Count // 서비스 파일에 작성해야 하는 로직인지 확인하기
public ArrayList<Integer> getHopeFieldsTotalCount(){
ArrayList<Integer> hopeFields = new ArrayList<Integer>(3);
// 초기화 방식도 뭔가 이상하다
hopeFields.add(0);
hopeFields.add(0);
hopeFields.add(0);
Integer count = 0;
// 할 수 있는 조회 방법, 너무 하드 코딩 같다
for(Map.Entry<String,Registration> entrySet : registration.entrySet()){
if(entrySet.getValue().getHopeField().equals("개발자")){ // == 의 경우 비교 연산이 이뤄지지 않음
count = hopeFields.get(0);
hopeFields.set(0,count+1);
}
else if(entrySet.getValue().getHopeField().equals("기획자")){
count = hopeFields.get(1);
hopeFields.set(1,count+1);
}
else if(entrySet.getValue().getHopeField().equals("디자이너")){
count = hopeFields.get(2);
hopeFields.set(2,count+1);
}
else{
// 예외 처리
}
}
return hopeFields;
}
Comment on lines +77 to +95
Copy link
Collaborator

Choose a reason for hiding this comment

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

조회를 index로 저렇게 숫자를 집어넣으시면 진짜 코드가 산으로갈겁니다. 가독성이 0거든요. 제가 분기처리하는 방법 많이 알려드렸으니 더 고민해보세요.


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public class Path {
String registrationId;
// 지원 경로
private String supportPath;
private PathType supportPath;
}
18 changes: 18 additions & 0 deletions src/main/java/com/econovation/third_project/database/PathType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.econovation.third_project.database;

public enum PathType {
POSTER("홍보 포스터"),
ANNOUNCEMENT("학과 공지사항"),
INTRODUCTION("지인 소개"),
INSTAGRAM("인스타그램"),
EVERYTIME("에브리타임"),
ETIC("기타");
Comment on lines +4 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

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

지원경로는 string으로 받으면 될텐데 굳이 이넘까지 쓴 이유가 있을까요?
실제로 개발을 해보시면 프론트들이 셀렉트 박스로 인풋값을 제한해주기 때문에 이런건 오히려 확장에 불리합니다.


final private String type;
public String getType(){
return type;
}
private PathType(String type){
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.econovation.third_project.service;

import com.econovation.third_project.database.*;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@AllArgsConstructor
public class RegistrationService {
private final Database database;

// 지원자 등록
public void register(Registration registration){
database.register(registration);
}

// 개인 정보 등록
public void registerPersonalInform(PersonalInformation personalInformation){database.savePersonalInformation(personalInformation);}

// 지원 경로 정보 등록
public void registerPath(Path path){database.savePath(path);}

// 면접 가능 시간 등록
public void registerDesiredTime(DesiredTime desiredTime){database.saveDesiredTime(desiredTime);}

// 전체 지원자 수 누적 합
public int getRegistrationCount(){
return database.getRegistrationCount();
}

// 각 분야별 합
// database의 registration을 조회, 조회하면서 getRegistration을 통해 Registration을 가져옴
// 들어있는 분야 별로 Count하기 (개발자, 기획자, 디자이너)
public ArrayList<Integer> getHopeFieldsTotalCount(){
return database.getHopeFieldsTotalCount();
}

// 희망 분야별 합
// 등록시 1지망 2지망을 나눠서 토탈 카운트
// 희망 분야별 합은 service 파일에서 작성
public Map<String, Integer> getHopeFieldsFirstPriorityCount() {
Map<String, Integer> firstHopeFieldCount = new HashMap<>();
for (Registration registration : database.getAllRegistrations().values()) {
String firstHopeField = registration.getFirstPriority();
firstHopeFieldCount.put(firstHopeField, firstHopeFieldCount.getOrDefault(firstHopeField, 0) + 1); // getOrDefault
}
return firstHopeFieldCount;
}

public Map<String, Integer> getHopeFieldsSecondPriorityCount() {
Map<String, Integer> secondHopeFieldCount = new HashMap<>();
for (Registration registration : database.getAllRegistrations().values()) {
String secondHopeField = registration.getSecondPriority();
secondHopeFieldCount.put(secondHopeField, secondHopeFieldCount.getOrDefault(secondHopeField, 0) + 1);
}
return secondHopeFieldCount;
}

// 소속 학과 합
public Map<String,Integer> getDepartmentCount(){
Map<String,Integer> departmentCount = new HashMap<>();
for(PersonalInformation personalInformation : database.getAllPersionalInformation().values()){
String major = personalInformation.getMajor();
departmentCount.put(major, departmentCount.getOrDefault(major,0)+1);
}
return departmentCount;
}

// 지원 경로 통계
public Map<String,Integer> getPathCount(){
Map<String,Integer> pathCount = new HashMap<>();
for(Path path : database.getAllPath().values()){
String p = path.getSupportPath().getType();
pathCount.put(p,pathCount.getOrDefault(p,0)+1);
}
Comment on lines +78 to +81
Copy link
Collaborator

Choose a reason for hiding this comment

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

집계를 for을 쓰는 순간부터 가독성은 현저히 떨어집니다. 이 코드는 해당 지원 경로를 순회하며 찾아서 1씩 추가해주는 것인데 그럽 map에 접근하는 횟수가 얼마나 될까요. map에 get하는 행위 없이 바로 집어넣어봅시다. stream을 쓰는 것도 방법일거구요.

return pathCount;
}

// 면접 희망 시간 통계


}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spring.application.name=HellStudy