Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 졸업학점 계산 동의 API 및 학과, 시간표 수정 대응 #1154

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package in.koreatech.koin.domain.graduation.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
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;

/**
* 졸업 요건 계산 변경 여부를 업데이트할 controller 메서드.
*/
@AfterReturning(pointcut = "execution(* in.koreatech.koin.domain.timetable.controller.TimetableController.createTimetables(..)) || " +
Soundbar91 marked this conversation as resolved.
Show resolved Hide resolved
"execution(* in.koreatech.koin.domain.timetable.controller.TimetableController.updateTimetable(..)) || " +
"execution(* in.koreatech.koin.domain.timetable.controller.TimetableController.deleteTimetableById(..)) || " +
"execution(* in.koreatech.koin.domain.timetableV2.controller.TimetableControllerV2.createTimetableLecture(..)) || " +
"execution(* in.koreatech.koin.domain.timetableV2.controller.TimetableControllerV2.updateTimetableLecture(..)) || " +
"execution(* in.koreatech.koin.domain.timetableV2.controller.TimetableControllerV2.deleteTimetableLecture(..)) || " +
"execution(* in.koreatech.koin.domain.timetableV2.controller.TimetableControllerV2.deleteTimetablesFrame(..))",
returning = "result")
public void afterTimetableLecture(JoinPoint joinPoint, Object result) {
Integer userId = authContext.getUserId();

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

@Tag(name = "(Normal) Graduation: 졸업학점 계산기", description = "졸업학점 계산기 정보를 관리한다")
public interface GraduationApi {

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true)))
}
)
@Operation(summary = "졸업학점 계산 동의")
@SecurityRequirement(name = "Jwt Authentication")
@PostMapping("/graduation/agree")
ResponseEntity<Void> createStudentCourseCalculation(
@Auth(permit = {STUDENT}) Integer userId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package in.koreatech.koin.domain.graduation.controller;

import java.io.IOException;
import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import in.koreatech.koin.domain.graduation.dto.GraduationCourseCalculationResponse;
import in.koreatech.koin.domain.graduation.service.GraduationService;
import in.koreatech.koin.domain.user.model.UserType;
import in.koreatech.koin.global.auth.Auth;
Expand All @@ -19,6 +22,14 @@ public class GraduationController implements GraduationApi {

private final GraduationService graduationService;

@PostMapping("/graduation/agree")
public ResponseEntity<Void> createStudentCourseCalculation(
@Auth(permit = {STUDENT}) Integer userId)
{
graduationService.createStudentCourseCalculation(userId);
return ResponseEntity.ok().build();
}

@PostMapping("/graduation/excel/upload")
public ResponseEntity<String> uploadStudentGradeExcelFile(
@RequestParam(value = "file") MultipartFile file,
Expand All @@ -31,4 +42,11 @@ public ResponseEntity<String> uploadStudentGradeExcelFile(
return ResponseEntity.badRequest().build();
}
}

@GetMapping("/graduation/course/calculation")
public ResponseEntity<GraduationCourseCalculationResponse> getGraduationCourseCalculation(
@Auth(permit = {STUDENT}) Integer userId) {
GraduationCourseCalculationResponse response = graduationService.getGraduationCourseCalculationResponse(userId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package in.koreatech.koin.domain.graduation.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.*;

import java.util.List;

import com.fasterxml.jackson.databind.annotation.JsonNaming;

@JsonNaming(value = SnakeCaseStrategy.class)
public record GraduationCourseCalculationResponse(

List<InnerCalculationResponse> courseTypes
) {

public record InnerCalculationResponse(String courseType, int requiredGrades, int grades) {

public static InnerCalculationResponse of(String courseType, int requiredGrades, int grades) {
return new InnerCalculationResponse(courseType, requiredGrades, grades);
}
}

public static GraduationCourseCalculationResponse of (List<InnerCalculationResponse> courseTypes) {
return new GraduationCourseCalculationResponse(courseTypes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -36,6 +37,15 @@ public class DetectGraduationCalculation {
@Column(name = "is_changed", columnDefinition = "TINYINT")
private boolean isChanged = false;

@Builder
private DetectGraduationCalculation(
User user,
boolean isChanged
) {
this.user = user;
this.isChanged = isChanged;
}

public void updatedIsChanged(boolean isChanged) {
this.isChanged = isChanged;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.repository.Repository;
Expand All @@ -9,11 +10,14 @@
import in.koreatech.koin.domain.student.model.Department;

public interface CatalogRepository extends Repository<Catalog, Integer> {

Optional<Catalog> findByYearAndDepartmentAndCode(String year, Department department, String code);

default Catalog getByYearAndDepartmentAndCode(String year, Department department, String code) {
return findByYearAndDepartmentAndCode(year, department, code)
.orElseThrow(() -> CatalogNotFoundException.withDetail(
"year: " + year + ", department: " + department + ", code: " + code));
}

List<Catalog> findByLectureNameAndYearAndDepartment(String lectureName, String studentYear, Department department);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.Optional;

import org.springframework.data.repository.Repository;

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

public interface DetectGraduationCalculationRepository extends Repository<DetectGraduationCalculation, Integer> {

Optional<DetectGraduationCalculation> findByUserId(Integer userId);

void save(DetectGraduationCalculation detectGraduationCalculation);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.List;

import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.graduation.model.StandardGraduationRequirements;
import in.koreatech.koin.domain.student.model.Department;

public interface StandardGraduationRequirementsRepository extends Repository<StandardGraduationRequirements, Integer> {

List<StandardGraduationRequirements> findAllByDepartmentAndYear(Department department, String year);

List<StandardGraduationRequirements> findByDepartmentIdAndCourseTypeIdAndYear(Integer id, Integer id1, String studentYear);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.Optional;

import org.springframework.data.repository.Repository;

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

public interface StudentCourseCalculationRepository extends Repository<StudentCourseCalculation, Integer> {

Optional<StudentCourseCalculation> findByUserId(Integer userId);

void deleteAllByUserId(Integer userId);

void save(StudentCourseCalculation studentCourseCalculation);

StudentCourseCalculation findByUserIdAndStandardGraduationRequirementsId(Integer userId, Integer id);

void delete(StudentCourseCalculation existingCalculation);
}
Loading
Loading