Skip to content

Commit 0ee84f4

Browse files
authored
Merge pull request #19 from enjoy-hack/jiwoo
feat: ---
2 parents 9ddf928 + c9e8633 commit 0ee84f4

4 files changed

Lines changed: 43 additions & 15 deletions

File tree

src/main/java/com/example/enjoy/controller/StudentDataController.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,46 @@
1212
import org.springframework.web.multipart.MultipartFile;
1313

1414
import java.util.List;
15+
import java.util.Map;
1516

1617
@RestController
1718
@RequestMapping("/student-data")
1819
@RequiredArgsConstructor
1920
public class StudentDataController {
2021

2122
private final StudentDataService studentDataService;
22-
private TrackService trackService;
23+
private final TrackService trackService;
2324

2425
@Operation(
2526
summary = "엑셀 파일 업로드",
2627
description = "기이수 성적 엑셀 파일(.xlsx)을 업로드하고, 과목 정보를 서버에 저장합니다."
2728
)
2829
@ApiResponse(responseCode = "200", description = "업로드 성공")
2930
@PostMapping(value = "/upload/{studentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
30-
public ResponseEntity<List<TrackProgressDto>> uploadCourseExcel(
31+
public ResponseEntity<?> uploadCourseExcel(
3132
@RequestParam("file") MultipartFile file,
3233
@PathVariable String studentId
3334
) {
34-
// 1. 엑셀 파싱 및 DB 저장
35-
studentDataService.parseAndSaveCourses(file, studentId);
35+
try {
36+
// 1. 엑셀 파싱 및 DB 저장
37+
studentDataService.parseAndSaveCourses(file, studentId);
3638

37-
// 2. 트랙 진행률 계산 (업로드 직후 기준)
38-
List<TrackProgressDto> progress = trackService.calculateTrackProgress(studentId);
39+
// 2. 트랙 진행률 계산 (업로드 직후 기준)
40+
List<TrackProgressDto> progress = trackService.calculateTrackProgress(studentId);
41+
if (progress.isEmpty()) {
42+
return ResponseEntity.ok(Map.of("message", "현재 진행 중인 트랙이 없습니다."));
43+
}
44+
// 3. 진행률 반환
45+
return ResponseEntity.ok(progress);
3946

40-
// 3. 진행률 반환
41-
return ResponseEntity.ok(progress);
47+
} catch (RuntimeException e) {
48+
return ResponseEntity.badRequest().body(
49+
Map.of(
50+
"status", 400,
51+
"code", "BAD_REQUEST",
52+
"message", e.getMessage()
53+
)
54+
);
55+
}
4256
}
4357
}

src/main/java/com/example/enjoy/entity/StudentCourse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class StudentCourse extends BaseTimeEntity {
2727
@Column(nullable = false)
2828
private StudentCourseStatus status;
2929

30-
@Column(nullable = false)
30+
@Column(nullable = false, name = "`manual`")
3131
private boolean manual;
3232

3333
@Column(nullable = false)

src/main/java/com/example/enjoy/service/StudentDataService.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,32 @@ public void parseAndSaveCourses(MultipartFile file, String studentId) {
2424

2525
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
2626
Sheet sheet = workbook.getSheetAt(0);
27+
28+
int rowIndex = 0;
2729
for (Row row : sheet) {
28-
if (row.getRowNum() == 0) continue;
30+
rowIndex++;
31+
if (row.getRowNum() <= 1) continue;
32+
33+
Cell courseCell = row.getCell(4);
34+
Cell gradeCell = row.getCell(10);
2935

30-
Cell courseCell = row.getCell(4); // 교과목명
31-
Cell gradeCell = row.getCell(10); // 등급
36+
// 헤더 행 무시
37+
if (courseCell != null && "교과목명".equals(courseCell.getStringCellValue().trim())) {
38+
continue;
39+
}
3240

33-
if (courseCell == null || gradeCell == null) continue;
41+
// 완전 빈 행 무시
42+
if ((courseCell == null || courseCell.getStringCellValue().trim().isEmpty()) &&
43+
(gradeCell == null || gradeCell.getStringCellValue().trim().isEmpty())) {
44+
continue;
45+
}
3446

3547
String courseName = courseCell.getStringCellValue().trim();
3648
String grade = gradeCell.getStringCellValue().trim();
49+
System.out.println(">> row " + rowIndex + ": " + courseName + " / " + grade);
50+
if (grade.isEmpty()) {
51+
throw new RuntimeException("엑셀 파일 파싱 실패: 등급이 비어있습니다.");
52+
}
3753

3854
StudentCourseStatus status = mapGradeToStatus(grade);
3955

src/main/java/com/example/enjoy/service/TrackService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public List<TrackProgressDto> calculateTrackProgress(String studentId) {
5656
}).toList();
5757
}
5858

59-
60-
6159
/**
6260
* 학생이 이수한 과목 이름을 Set으로 반환하는 메서드
6361
*/

0 commit comments

Comments
 (0)