-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentDataController.java
More file actions
57 lines (50 loc) · 2.12 KB
/
StudentDataController.java
File metadata and controls
57 lines (50 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.example.enjoy.controller;
import com.example.enjoy.dto.TrackProgressDto;
import com.example.enjoy.service.StudentDataService;
import com.example.enjoy.service.TrackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/student-data")
@RequiredArgsConstructor
public class StudentDataController {
private final StudentDataService studentDataService;
private final TrackService trackService;
@Operation(
summary = "엑셀 파일 업로드",
description = "기이수 성적 엑셀 파일(.xlsx)을 업로드하고, 과목 정보를 서버에 저장합니다."
)
@ApiResponse(responseCode = "200", description = "업로드 성공")
@PostMapping(value = "/upload/{studentId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> uploadCourseExcel(
@RequestParam("file") MultipartFile file,
@PathVariable String studentId
) {
try {
// 1. 엑셀 파싱 및 DB 저장
studentDataService.parseAndSaveCourses(file, studentId);
// 2. 트랙 진행률 계산 (업로드 직후 기준)
List<TrackProgressDto> progress = trackService.calculateTrackProgress(studentId);
if (progress.isEmpty()) {
return ResponseEntity.ok(Map.of("message", "현재 진행 중인 트랙이 없습니다."));
}
// 3. 진행률 반환
return ResponseEntity.ok(progress);
} catch (RuntimeException e) {
return ResponseEntity.badRequest().body(
Map.of(
"status", 400,
"code", "BAD_REQUEST",
"message", e.getMessage()
)
);
}
}
}