diff --git a/src/main/java/com/example/enjoy/controller/StudentDataController.java b/src/main/java/com/example/enjoy/controller/StudentDataController.java index 37eb5ef..ca85090 100644 --- a/src/main/java/com/example/enjoy/controller/StudentDataController.java +++ b/src/main/java/com/example/enjoy/controller/StudentDataController.java @@ -12,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/student-data") @@ -19,7 +20,7 @@ public class StudentDataController { private final StudentDataService studentDataService; - private TrackService trackService; + private final TrackService trackService; @Operation( summary = "엑셀 파일 업로드", @@ -27,17 +28,30 @@ public class StudentDataController { ) @ApiResponse(responseCode = "200", description = "업로드 성공") @PostMapping(value = "/upload/{studentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseEntity> uploadCourseExcel( + public ResponseEntity uploadCourseExcel( @RequestParam("file") MultipartFile file, @PathVariable String studentId ) { - // 1. 엑셀 파싱 및 DB 저장 - studentDataService.parseAndSaveCourses(file, studentId); + try { + // 1. 엑셀 파싱 및 DB 저장 + studentDataService.parseAndSaveCourses(file, studentId); - // 2. 트랙 진행률 계산 (업로드 직후 기준) - List progress = trackService.calculateTrackProgress(studentId); + // 2. 트랙 진행률 계산 (업로드 직후 기준) + List progress = trackService.calculateTrackProgress(studentId); + if (progress.isEmpty()) { + return ResponseEntity.ok(Map.of("message", "현재 진행 중인 트랙이 없습니다.")); + } + // 3. 진행률 반환 + return ResponseEntity.ok(progress); - // 3. 진행률 반환 - return ResponseEntity.ok(progress); + } catch (RuntimeException e) { + return ResponseEntity.badRequest().body( + Map.of( + "status", 400, + "code", "BAD_REQUEST", + "message", e.getMessage() + ) + ); + } } } diff --git a/src/main/java/com/example/enjoy/entity/StudentCourse.java b/src/main/java/com/example/enjoy/entity/StudentCourse.java index cf431ba..c049768 100644 --- a/src/main/java/com/example/enjoy/entity/StudentCourse.java +++ b/src/main/java/com/example/enjoy/entity/StudentCourse.java @@ -27,7 +27,7 @@ public class StudentCourse extends BaseTimeEntity { @Column(nullable = false) private StudentCourseStatus status; - @Column(nullable = false) + @Column(nullable = false, name = "`manual`") private boolean manual; @Column(nullable = false) diff --git a/src/main/java/com/example/enjoy/service/StudentDataService.java b/src/main/java/com/example/enjoy/service/StudentDataService.java index c148d43..9fa4a07 100644 --- a/src/main/java/com/example/enjoy/service/StudentDataService.java +++ b/src/main/java/com/example/enjoy/service/StudentDataService.java @@ -24,16 +24,32 @@ public void parseAndSaveCourses(MultipartFile file, String studentId) { try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { Sheet sheet = workbook.getSheetAt(0); + + int rowIndex = 0; for (Row row : sheet) { - if (row.getRowNum() == 0) continue; + rowIndex++; + if (row.getRowNum() <= 1) continue; + + Cell courseCell = row.getCell(4); + Cell gradeCell = row.getCell(10); - Cell courseCell = row.getCell(4); // 교과목명 - Cell gradeCell = row.getCell(10); // 등급 + // 헤더 행 무시 + if (courseCell != null && "교과목명".equals(courseCell.getStringCellValue().trim())) { + continue; + } - if (courseCell == null || gradeCell == null) continue; + // 완전 빈 행 무시 + if ((courseCell == null || courseCell.getStringCellValue().trim().isEmpty()) && + (gradeCell == null || gradeCell.getStringCellValue().trim().isEmpty())) { + continue; + } String courseName = courseCell.getStringCellValue().trim(); String grade = gradeCell.getStringCellValue().trim(); + System.out.println(">> row " + rowIndex + ": " + courseName + " / " + grade); + if (grade.isEmpty()) { + throw new RuntimeException("엑셀 파일 파싱 실패: 등급이 비어있습니다."); + } StudentCourseStatus status = mapGradeToStatus(grade); diff --git a/src/main/java/com/example/enjoy/service/TrackService.java b/src/main/java/com/example/enjoy/service/TrackService.java index 39ed361..149e802 100644 --- a/src/main/java/com/example/enjoy/service/TrackService.java +++ b/src/main/java/com/example/enjoy/service/TrackService.java @@ -56,8 +56,6 @@ public List calculateTrackProgress(String studentId) { }).toList(); } - - /** * 학생이 이수한 과목 이름을 Set으로 반환하는 메서드 */