Skip to content

Commit

Permalink
fix: 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
김원경 committed Dec 29, 2024
1 parent dea52f0 commit e437327
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.springframework.stereotype.Component;

import in.koreatech.koin.domain.graduation.repository.DetectGraduationCalculationRepository;
import in.koreatech.koin.global.auth.AuthContext;
import lombok.RequiredArgsConstructor;

@Aspect
@Component
@RequiredArgsConstructor
public class GraduationAspect {

private final AuthContext authContext;
private final DetectGraduationCalculationRepository detectGraduationCalculationRepository;

/**
Expand All @@ -27,11 +29,10 @@ public class GraduationAspect {
"execution(* in.koreatech.koin.domain.timetableV2.controller.TimetableControllerV2.deleteTimetablesFrame(..))",
returning = "result")
public void afterTimetableLecture(JoinPoint joinPoint, Object result) {
Object[] args = joinPoint.getArgs();
Integer userId = (Integer) args[1];
Integer userId = authContext.getUserId();

detectGraduationCalculationRepository.findByUserId(userId).ifPresent(detectGraduationCalculation -> {
detectGraduationCalculation.updatedIsChanged(true);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.graduation.model.StudentCourseCalculation;

@Repository
public interface StudentCourseCalculationRepository extends JpaRepository<StudentCourseCalculation, Integer> {
public interface StudentCourseCalculationRepository extends Repository<StudentCourseCalculation, Integer> {

Optional<StudentCourseCalculation> findByUserId(Integer userId);

void deleteAllByUserId(Integer userId);

void save(StudentCourseCalculation studentCourseCalculation);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package in.koreatech.koin.domain.graduation.service;

import static in.koreatech.koin.domain.student.util.StudentUtil.parseStudentNumberYear;

import java.util.List;

import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -31,23 +33,10 @@ public class GraduationService {
public void createStudentCourseCalculation(Integer userId) {
Student student = studentRepository.getById(userId);

if (student.getDepartment() == null) {
DepartmentNotFoundException.withDetail("학과를 추가하세요.");
}
if (student.getStudentNumber() == null) {
DepartmentNotFoundException.withDetail("학번을 추가하세요.");
}

List<StandardGraduationRequirements> requirementsList =
standardGraduationRequirementsRepository.findAllByDepartmentAndYear(
student.getDepartment(), student.getStudentNumber().substring(0, 4));
validateStudentField(student.getDepartment(), "학과를 추가하세요.");
validateStudentField(student.getStudentNumber(), "학번을 추가하세요.");

requirementsList.forEach(requirement -> studentCourseCalculationRepository.save(
StudentCourseCalculation.builder()
.completedGrades(0)
.user(student.getUser())
.standardGraduationRequirements(requirement)
.build()));
initializeStudentCourseCalculation(student, student.getDepartment());

DetectGraduationCalculation detectGraduationCalculation = DetectGraduationCalculation.builder()
.user(student.getUser())
Expand All @@ -63,10 +52,27 @@ public void resetStudentCourseCalculation(Student student, Department newDepartm
.ifPresent(studentCourseCalculation -> {
studentCourseCalculationRepository.deleteAllByUserId(student.getUser().getId());
});

initializeStudentCourseCalculation(student, newDepartment);

detectGraduationCalculationRepository.findByUserId(student.getUser().getId())
.ifPresent(detectGraduationCalculation -> {
detectGraduationCalculation.updatedIsChanged(true);
});
}

private void validateStudentField(Object field, String message) {
if (field == null) {
throw DepartmentNotFoundException.withDetail(message);
}
}

private void initializeStudentCourseCalculation(Student student, Department department) {
// 학번에 맞는 이수요건 정보 조회
List<StandardGraduationRequirements> requirementsList =
standardGraduationRequirementsRepository.findAllByDepartmentAndYear(
newDepartment, student.getStudentNumber().substring(0, 4));
department, student.getStudentNumber().substring(0, 4));

// 학생 졸업요건 계산 정보 초기화
requirementsList.forEach(requirement ->
studentCourseCalculationRepository.save(
Expand All @@ -77,10 +83,5 @@ public void resetStudentCourseCalculation(Student student, Department newDepartm
.build()
)
);
// DetectGraduationCalculation 정보 업데이트
detectGraduationCalculationRepository.findByUserId(student.getUser().getId())
.ifPresent(detectGraduationCalculation -> {
detectGraduationCalculation.updatedIsChanged(true);
});
}
}

0 comments on commit e437327

Please sign in to comment.