Skip to content

Commit

Permalink
[DEV-21] 유저정보 조회 API 수정 (#263)
Browse files Browse the repository at this point in the history
* refactor: User 필드 추가 - 총학점, 수강학점, 졸엽 가능 여부

* refactor: user정보 수정 로직 변경

* refactor: 오타 수정

* refactor: 졸업 계산 시 유저 정보 수정 로직 추가

* refactor: 유저 정보 조회 response 수정

* build: 불필요 의존성 제거

* refactor: 성적표 파싱 로직 수정
  • Loading branch information
5uhwann authored May 26, 2024
1 parent b84c10b commit 204ca95
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 96 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'com.auth0:java-jwt:4.2.1'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation "com.google.guava:guava:32.1.3-jre"
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.College;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;
Expand All @@ -43,6 +45,7 @@ class CalculateGraduationService implements CalculateGraduationUseCase {
private final CalculatePrimaryMandatoryMajorDetailGraduationUseCase calculatePrimaryMandatoryMajorDetailGraduationUseCase;
private final CalculatePrimaryElectiveMajorDetailGraduationUseCase calculatePrimaryElectiveMajorDetailGraduationUseCase;
private final CalculatePrimaryBasicAcademicalCultureDetailGraduationService calculatePrimaryBasicAcademicalCultureDetailGraduationService;
private final UpdateStudentInformationUseCase updateStudentInformationUseCase;

@Override
public GraduationResult calculateGraduation(User user) {
Expand All @@ -53,8 +56,10 @@ public GraduationResult calculateGraduation(User user) {
List<DetailGraduationResult> detailGraduationResults = generateDetailGraduationResults(user,
takenLectureInventory, graduationRequirement);

return generateGraduationResult(chapelResult, detailGraduationResults,
GraduationResult graduationResult = generateGraduationResult(chapelResult, detailGraduationResults,
takenLectureInventory, graduationRequirement);
updateUserGraduationInformation(user, graduationResult);
return graduationResult;
}

private GraduationRequirement determineGraduationRequirement(User user) {
Expand Down Expand Up @@ -141,4 +146,19 @@ private GraduationResult generateGraduationResult(ChapelResult chapelResult,
graduationResult.checkGraduated();
return graduationResult;
}

private void updateUserGraduationInformation(User user, GraduationResult graduationResult) {
UpdateStudentInformationCommand updateStudentInformationCommand = UpdateStudentInformationCommand.builder()
.user(user)
.name(user.getName())
.studentCategory(user.getStudentCategory())
.major(user.getPrimaryMajor())
.dualMajor(user.getDualMajor())
.subMajor(user.getSubMajor())
.totalCredit(graduationResult.getTotalCredit())
.takenCredit(graduationResult.getTakenCredit())
.graduate(graduationResult.isGraduated())
.build();
updateStudentInformationUseCase.updateUser(updateStudentInformationCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public void enrollParsingText(Long userId, String parsingText) {
ParsingInformation parsingInformation = ParsingInformation.parsing(parsingText);
checkUnSupportedUser(parsingInformation);
validateStudentNumber(user, parsingInformation);
updateUser(user, parsingInformation);
deleteTakenLecturesIfAlreadyEnrolled(user);
saveTakenLectures(user, parsingInformation);
generateOrModifyCompletedCreditUseCase.generateOrModifyCompletedCredit(user);
User updatedUser = updateUser(user, parsingInformation);
deleteTakenLecturesIfAlreadyEnrolled(updatedUser);
saveTakenLectures(updatedUser, parsingInformation);
generateOrModifyCompletedCreditUseCase.generateOrModifyCompletedCredit(updatedUser);
} catch (InvalidPdfException | IllegalArgumentException e) {
throw e;
} catch (Exception e) {
Expand All @@ -68,12 +68,9 @@ private void saveTakenLectures(User user, ParsingInformation parsingInformation)
saveTakenLectureFromParsingTextUseCase.saveTakenLectures(user, saveTakenLectureCommand);
}

private void updateUser(User user, ParsingInformation parsingInformation) {
UpdateStudentInformationCommand updateStudentInfoCommand = UpdateStudentInformationCommand.of(user,
parsingInformation.getStudentName(), parsingInformation.getMajor(),
parsingInformation.getChangeMajor(), parsingInformation.getDualMajor(),
parsingInformation.getSubMajor(), parsingInformation.getStudentCategory());
updateStudentInformationUseCase.updateUser(updateStudentInfoCommand);
private User updateUser(User user, ParsingInformation parsingInformation) {
UpdateStudentInformationCommand updateStudentInfoCommand = UpdateStudentInformationCommand.of(user, parsingInformation);
return updateStudentInformationUseCase.updateUser(updateStudentInfoCommand);
}

private void validateParsingText(String parsingText) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.plzgraduate.myongjigraduatebe.user.api.finduserinformation.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
public class CompleteDivisionResponse {

private final String majorType;

private final String major;

@Builder
private CompleteDivisionResponse(String majorType, String major) {
this.majorType = majorType;
this.major = major;
}

public static CompleteDivisionResponse of(String majorType, String major) {
return CompleteDivisionResponse.builder()
.majorType(majorType)
.major(major)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.plzgraduate.myongjigraduatebe.user.api.finduserinformation.dto.response;

import java.util.ArrayList;
import java.util.List;

import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -13,20 +16,39 @@ public class UserInformationResponse {
private final String studentNumber;
@Schema(name = "studentName", example = "홍길동")
private final String studentName;
@Schema(name = "major", example = "디지털콘텐츠디자인학과")
private final String major;
@Schema(name = "completeDivision")
private final List<CompleteDivisionResponse> completeDivision = new ArrayList<>(3);
private final int totalCredit;
private final double takenCredit;
private final boolean graduated;

@Builder
private UserInformationResponse(String studentNumber, String studentName, String major) {
private UserInformationResponse(String studentNumber, String studentName, int totalCredit, double takenCredit,
boolean graduated) {
this.studentNumber = studentNumber;
this.studentName = studentName;
this.major = major;
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.graduated = graduated;
}

public static UserInformationResponse from(User user) {
return UserInformationResponse.builder()
UserInformationResponse userInformation = UserInformationResponse.builder()
.studentNumber(user.getStudentNumber())
.studentName(user.getName())
.major(user.getPrimaryMajor()).build();
.totalCredit(user.getTotalCredit())
.takenCredit(user.getTakenCredit())
.graduated(user.isGraduated())
.build();
if (user.getPrimaryMajor() != null) {
userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("PRIMARY", user.getPrimaryMajor()));
}
if (user.getDualMajor() != null) {
userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("DUAL", user.getDualMajor()));
}
if (user.getSubMajor() != null) {
userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("SUB", user.getSubMajor()));
}
return userInformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ class UpdateStudentInformationService implements UpdateStudentInformationUseCase
private final UpdateUserPort updateUserPort;

@Override
public void updateUser(UpdateStudentInformationCommand updateStudentInformationCommand) {
public User updateUser(UpdateStudentInformationCommand updateStudentInformationCommand) {
User user = updateStudentInformationCommand.getUser();
user.updateStudentInformation(updateStudentInformationCommand.getName(),
updateStudentInformationCommand.getMajor(),
updateStudentInformationCommand.getChangeMajor(),
updateStudentInformationCommand.getDualMajor(),
updateStudentInformationCommand.getSubMajor(),
updateStudentInformationCommand.getStudentCategory()
updateStudentInformationCommand.getStudentCategory(),
updateStudentInformationCommand.getTotalCredit(),
updateStudentInformationCommand.getTakenCredit(),
updateStudentInformationCommand.isGraduate()
);
updateUserPort.updateUser(user);
return user;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.plzgraduate.myongjigraduatebe.user.application.usecase.update;

import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingInformation;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

Expand All @@ -16,36 +17,40 @@ public class UpdateStudentInformationCommand {

private String major;

private String changeMajor;

private String dualMajor;

private String subMajor;

private StudentCategory studentCategory;

private int totalCredit;

private double takenCredit;

private boolean graduate;

@Builder
private UpdateStudentInformationCommand(User user, String name, String major, String changeMajor, String dualMajor,
String subMajor, StudentCategory studentCategory) {
private UpdateStudentInformationCommand(User user, String name, String major, String dualMajor,
String subMajor, StudentCategory studentCategory, int totalCredit, double takenCredit, boolean graduate) {
this.user = user;
this.name = name;
this.major = major;
this.changeMajor = changeMajor;
this.dualMajor = dualMajor;
this.subMajor = subMajor;
this.studentCategory = studentCategory;
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.graduate = graduate;
}

public static UpdateStudentInformationCommand of(User user, String name, String major, String changeMajor,
String dualMajor, String subMajor, StudentCategory studentCategory) {
public static UpdateStudentInformationCommand of(User user, ParsingInformation parsingInformation) {
return UpdateStudentInformationCommand.builder()
.user(user)
.name(name)
.major(major)
.changeMajor(changeMajor)
.dualMajor(dualMajor)
.subMajor(subMajor)
.studentCategory(studentCategory)
.name(parsingInformation.getStudentName())
.major(parsingInformation.getMajor())
.dualMajor(parsingInformation.getDualMajor())
.subMajor(parsingInformation.getSubMajor())
.studentCategory(parsingInformation.getStudentCategory())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.plzgraduate.myongjigraduatebe.user.application.usecase.update;

import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

public interface UpdateStudentInformationUseCase {
void updateUser(UpdateStudentInformationCommand updateStudentInformationCommand);
User updateUser(UpdateStudentInformationCommand updateStudentInformationCommand);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ public class User {
private final String studentNumber;
private final int entryYear;
private String primaryMajor;
private String changeMajor;
private String subMajor;
private String dualMajor;
private StudentCategory studentCategory;
private int totalCredit;
private double takenCredit;
private boolean graduated;
private final Instant createdAt;
private Instant updatedAt;

@Builder
private User(Long id, String authId, String password, EnglishLevel englishLevel, String name, String studentNumber,
int entryYear, String primaryMajor, String changeMajor, String subMajor, String dualMajor, StudentCategory studentCategory,
Instant createdAt, Instant updatedAt) {
int entryYear, String primaryMajor, String subMajor, String dualMajor, StudentCategory studentCategory,
int totalCredit, double takenCredit, boolean graduated, Instant createdAt, Instant updatedAt) {
this.id = id;
this.authId = authId;
this.password = password;
Expand All @@ -38,34 +40,39 @@ private User(Long id, String authId, String password, EnglishLevel englishLevel,
this.studentNumber = studentNumber;
this.entryYear = entryYear;
this.primaryMajor = primaryMajor;
this.changeMajor = changeMajor;
this.subMajor = subMajor;
this.dualMajor = dualMajor;
this.studentCategory = studentCategory;
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.graduated = graduated;
this.createdAt = createdAt;
this.updatedAt = updatedAt;

}


public static User create(String authId, String password, EnglishLevel englishLevel, String studentNumber) {
return User.builder()
.authId(authId)
.password(password)
.englishLevel(englishLevel)
.studentNumber(studentNumber)
.entryYear(parseEntryYearInStudentNumber(studentNumber))
.totalCredit(0)
.takenCredit(0)
.graduated(false)
.build();
}

public void updateStudentInformation(String name, String major, String changeMajor, String subMajor, String dualMajor,
StudentCategory studentCategory) {
public void updateStudentInformation(String name, String major, String subMajor, String dualMajor,
StudentCategory studentCategory, int totalCredit, double takenCredit, boolean graduate) {
this.name = name;
this.primaryMajor = major;
this.changeMajor = changeMajor;
this.dualMajor = dualMajor;
this.subMajor = subMajor;
this.studentCategory = studentCategory;
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.graduated = graduate;
}

public boolean checkBeforeEntryYear(int entryYear) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ public class UserJpaEntity extends TimeBaseEntity {

private String major;

private String dualMajor;

private String subMajor;

private int totalCredit;

private double takenCredit;

private boolean graduated;

@Enumerated(value = EnumType.STRING)
private StudentCategory studentCategory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public class UserMapper {

public User mapToDomainEntity(UserJpaEntity user) {

return User.builder()
.id(user.getId())
.authId(user.getAuthId())
Expand All @@ -19,8 +18,12 @@ public User mapToDomainEntity(UserJpaEntity user) {
.entryYear(user.getEntryYear())
.englishLevel(user.getEnglishLevel())
.primaryMajor(user.getMajor())
.dualMajor(user.getDualMajor())
.subMajor(user.getSubMajor())
.studentCategory(user.getStudentCategory())
.totalCredit(user.getTotalCredit())
.takenCredit(user.getTakenCredit())
.graduated(user.isGraduated())
.createdAt(user.getCreatedAt())
.updatedAt(user.getUpdatedAt())
.build();
Expand All @@ -39,6 +42,9 @@ public UserJpaEntity mapToJpaEntity(User user) {
.major(user.getPrimaryMajor())
.subMajor(user.getSubMajor())
.studentCategory(user.getStudentCategory())
.totalCredit(user.getTotalCredit())
.takenCredit(user.getTakenCredit())
.graduated(user.isGraduated())
.createdAt(user.getCreatedAt())
.updatedAt(user.getUpdatedAt())
.build();
Expand Down
Loading

0 comments on commit 204ca95

Please sign in to comment.