diff --git a/src/main/java/com/example/enjoy/controller/HomeController.java b/src/main/java/com/example/enjoy/controller/HomeController.java index 0b9d4fb..be98c93 100644 --- a/src/main/java/com/example/enjoy/controller/HomeController.java +++ b/src/main/java/com/example/enjoy/controller/HomeController.java @@ -17,7 +17,7 @@ public class HomeController { @GetMapping("/home") public List getProgress() { // 1. 반환 타입을 List로 변경 - Long currentStudentId = 1L; + String currentStudentId = "1"; // 2. 서비스 호출 후 데이터를 바로 반환 return trackService.calculateTrackProgress(currentStudentId); } diff --git a/src/main/java/com/example/enjoy/controller/TrackController.java b/src/main/java/com/example/enjoy/controller/TrackController.java index e77fa79..425bbd3 100644 --- a/src/main/java/com/example/enjoy/controller/TrackController.java +++ b/src/main/java/com/example/enjoy/controller/TrackController.java @@ -24,7 +24,7 @@ public class TrackController { public TrackDetailDto getTrackDetailsById(@PathVariable Long trackId) { // TODO: 추후 Spring Security 연동 후 실제 로그인한 학생 ID를 가져와야 함 - Long currentStudentId = 1L; + String currentStudentId = "1"; // 5. 서비스의 메서드를 호출하여 결과를 받아온 후, 그대로 반환 return trackService.getTrackDetails(currentStudentId, trackId); diff --git a/src/main/java/com/example/enjoy/controller/UserController.java b/src/main/java/com/example/enjoy/controller/UserController.java new file mode 100644 index 0000000..368d040 --- /dev/null +++ b/src/main/java/com/example/enjoy/controller/UserController.java @@ -0,0 +1,4 @@ +package com.example.enjoy.controller; + +public class UserController { +} diff --git a/src/main/java/com/example/enjoy/dto/StudentCourseStatus.java b/src/main/java/com/example/enjoy/dto/StudentCourseStatus.java new file mode 100644 index 0000000..e4631ca --- /dev/null +++ b/src/main/java/com/example/enjoy/dto/StudentCourseStatus.java @@ -0,0 +1,18 @@ +package com.example.enjoy.dto; + +public enum StudentCourseStatus { + COMPLETED("완료"), + IN_PROGRESS("수강중"), + PLANNED("수강예정"), + FAILED("미이수"); + + private final String description; + + StudentCourseStatus(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/enjoy/entity/StudentCourse.java b/src/main/java/com/example/enjoy/entity/StudentCourse.java index af517cb..cf431ba 100644 --- a/src/main/java/com/example/enjoy/entity/StudentCourse.java +++ b/src/main/java/com/example/enjoy/entity/StudentCourse.java @@ -1,17 +1,40 @@ package com.example.enjoy.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import lombok.Getter; +import com.example.enjoy.dto.StudentCourseStatus; +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDateTime; @Entity @Getter -public class StudentCourse { // 학생이 실제로 이수한 과목 +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +public class StudentCourse extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private Long studentId; // 학생 ID (로그인 연동) + + @Column(nullable = false) + private String studentId; + + @Column(nullable = false) private String courseName; -} + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private StudentCourseStatus status; + + @Column(nullable = false) + private boolean manual; + + @Column(nullable = false) + private LocalDateTime createdAt; + + public void updateStatus(StudentCourseStatus status) { + this.status = status; + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/enjoy/repository/StudentCourseRepository.java b/src/main/java/com/example/enjoy/repository/StudentCourseRepository.java index 72e9871..88ab1d0 100644 --- a/src/main/java/com/example/enjoy/repository/StudentCourseRepository.java +++ b/src/main/java/com/example/enjoy/repository/StudentCourseRepository.java @@ -8,8 +8,7 @@ public interface StudentCourseRepository extends JpaRepository { - List findByStudentId(Long studentId); + List findByStudentId(String studentId); + - @Transactional - void deleteByStudentId(Long studentId); // 학생 ID로 이수과목 한번에 삭제 } \ No newline at end of file diff --git a/src/main/java/com/example/enjoy/repository/TrackCourseRepository.java b/src/main/java/com/example/enjoy/repository/TrackCourseRepository.java new file mode 100644 index 0000000..f314330 --- /dev/null +++ b/src/main/java/com/example/enjoy/repository/TrackCourseRepository.java @@ -0,0 +1,13 @@ +package com.example.enjoy.repository; + +import com.example.enjoy.entity.Track; +import com.example.enjoy.entity.TrackCourse; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +@Repository +public interface TrackCourseRepository extends JpaRepository { + + List findAllByTrack(Track track); +} \ No newline at end of file diff --git a/src/main/java/com/example/enjoy/repository/UserRepository.java b/src/main/java/com/example/enjoy/repository/UserRepository.java new file mode 100644 index 0000000..3cc6d9c --- /dev/null +++ b/src/main/java/com/example/enjoy/repository/UserRepository.java @@ -0,0 +1,9 @@ +package com.example.enjoy.repository; + +import com.example.enjoy.entity.user.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/example/enjoy/service/TrackService.java b/src/main/java/com/example/enjoy/service/TrackService.java index dd1d328..ef11a9a 100644 --- a/src/main/java/com/example/enjoy/service/TrackService.java +++ b/src/main/java/com/example/enjoy/service/TrackService.java @@ -41,7 +41,7 @@ public Map> getAllTracksGroupedByDepartment() { /** * 학생이 이수한 과목 이름을 Set으로 반환하는 private 메서드 */ - public List calculateTrackProgress(Long studentId) { + public List calculateTrackProgress(String studentId) { // 1. 학생의 이수 과목 목록 조회 Set completedCourseNames = studentCourseRepository.findByStudentId(studentId) .stream() @@ -98,7 +98,7 @@ public List calculateTrackProgress(Long studentId) { * 학생이 이수한 과목 이름을 Set으로 반환하는 메서드 */ @Transactional(readOnly = true) - public TrackDetailDto getTrackDetails(Long studentId, Long trackId) { + public TrackDetailDto getTrackDetails(String studentId, Long trackId) { // 1. [리팩토링] 학생 이수 과목 조회 로직을 private 메서드로 호출 Set completedCourseNames = getCompletedCourseNames(studentId); @@ -142,7 +142,7 @@ public TrackDetailDto getTrackDetails(Long studentId, Long trackId) { /** * 학생 ID로 해당 학생이 이수한 모든 과목명을 조회합니다. */ - private Set getCompletedCourseNames(Long studentId) { + private Set getCompletedCourseNames(String studentId) { return studentCourseRepository.findByStudentId(studentId) .stream() .map(StudentCourse::getCourseName)