|
12 | 12 | import org.springframework.web.multipart.MultipartFile; |
13 | 13 |
|
14 | 14 | import java.util.List; |
| 15 | +import java.util.Map; |
15 | 16 |
|
16 | 17 | @RestController |
17 | 18 | @RequestMapping("/student-data") |
18 | 19 | @RequiredArgsConstructor |
19 | 20 | public class StudentDataController { |
20 | 21 |
|
21 | 22 | private final StudentDataService studentDataService; |
22 | | - private TrackService trackService; |
| 23 | + private final TrackService trackService; |
23 | 24 |
|
24 | 25 | @Operation( |
25 | 26 | summary = "엑셀 파일 업로드", |
26 | 27 | description = "기이수 성적 엑셀 파일(.xlsx)을 업로드하고, 과목 정보를 서버에 저장합니다." |
27 | 28 | ) |
28 | 29 | @ApiResponse(responseCode = "200", description = "업로드 성공") |
29 | 30 | @PostMapping(value = "/upload/{studentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
30 | | - public ResponseEntity<List<TrackProgressDto>> uploadCourseExcel( |
| 31 | + public ResponseEntity<?> uploadCourseExcel( |
31 | 32 | @RequestParam("file") MultipartFile file, |
32 | 33 | @PathVariable String studentId |
33 | 34 | ) { |
34 | | - // 1. 엑셀 파싱 및 DB 저장 |
35 | | - studentDataService.parseAndSaveCourses(file, studentId); |
| 35 | + try { |
| 36 | + // 1. 엑셀 파싱 및 DB 저장 |
| 37 | + studentDataService.parseAndSaveCourses(file, studentId); |
36 | 38 |
|
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); |
39 | 46 |
|
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 | + } |
42 | 56 | } |
43 | 57 | } |
0 commit comments