Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class HomeController {
@GetMapping("/home")
public List<TrackProgressDto> getProgress() {
// 1. 반환 타입을 List<TrackProgressDto>로 변경
Long currentStudentId = 1L;
String currentStudentId = "1";
// 2. 서비스 호출 후 데이터를 바로 반환
return trackService.calculateTrackProgress(currentStudentId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.enjoy.controller;

public class UserController {
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/enjoy/dto/StudentCourseStatus.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
39 changes: 31 additions & 8 deletions src/main/java/com/example/enjoy/entity/StudentCourse.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

public interface StudentCourseRepository extends JpaRepository<StudentCourse, Long> {

List<StudentCourse> findByStudentId(Long studentId);
List<StudentCourse> findByStudentId(String studentId);


@Transactional
void deleteByStudentId(Long studentId); // 학생 ID로 이수과목 한번에 삭제
}
Original file line number Diff line number Diff line change
@@ -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<TrackCourse, Long> {

List<TrackCourse> findAllByTrack(Track track);
}
Original file line number Diff line number Diff line change
@@ -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<User,Long> {
}
6 changes: 3 additions & 3 deletions src/main/java/com/example/enjoy/service/TrackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Map<String, List<Track>> getAllTracksGroupedByDepartment() {
/**
* 학생이 이수한 과목 이름을 Set으로 반환하는 private 메서드
*/
public List<TrackProgressDto> calculateTrackProgress(Long studentId) {
public List<TrackProgressDto> calculateTrackProgress(String studentId) {
// 1. 학생의 이수 과목 목록 조회
Set<String> completedCourseNames = studentCourseRepository.findByStudentId(studentId)
.stream()
Expand Down Expand Up @@ -98,7 +98,7 @@ public List<TrackProgressDto> calculateTrackProgress(Long studentId) {
* 학생이 이수한 과목 이름을 Set으로 반환하는 메서드
*/
@Transactional(readOnly = true)
public TrackDetailDto getTrackDetails(Long studentId, Long trackId) {
public TrackDetailDto getTrackDetails(String studentId, Long trackId) {

// 1. [리팩토링] 학생 이수 과목 조회 로직을 private 메서드로 호출
Set<String> completedCourseNames = getCompletedCourseNames(studentId);
Expand Down Expand Up @@ -142,7 +142,7 @@ public TrackDetailDto getTrackDetails(Long studentId, Long trackId) {
/**
* 학생 ID로 해당 학생이 이수한 모든 과목명을 조회합니다.
*/
private Set<String> getCompletedCourseNames(Long studentId) {
private Set<String> getCompletedCourseNames(String studentId) {
return studentCourseRepository.findByStudentId(studentId)
.stream()
.map(StudentCourse::getCourseName)
Expand Down
Loading