Skip to content

Commit 19a3f53

Browse files
authored
Merge pull request #11 from enjoy-hack/jiwoo
feat: plz
2 parents 8f26180 + 42fc3c2 commit 19a3f53

9 files changed

Lines changed: 82 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class HomeController {
1717
@GetMapping("/home")
1818
public List<TrackProgressDto> getProgress() {
1919
// 1. 반환 타입을 List<TrackProgressDto>로 변경
20-
Long currentStudentId = 1L;
20+
String currentStudentId = "1";
2121
// 2. 서비스 호출 후 데이터를 바로 반환
2222
return trackService.calculateTrackProgress(currentStudentId);
2323
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TrackController {
2424
public TrackDetailDto getTrackDetailsById(@PathVariable Long trackId) {
2525

2626
// TODO: 추후 Spring Security 연동 후 실제 로그인한 학생 ID를 가져와야 함
27-
Long currentStudentId = 1L;
27+
String currentStudentId = "1";
2828

2929
// 5. 서비스의 메서드를 호출하여 결과를 받아온 후, 그대로 반환
3030
return trackService.getTrackDetails(currentStudentId, trackId);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.example.enjoy.controller;
2+
3+
public class UserController {
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.enjoy.dto;
2+
3+
public enum StudentCourseStatus {
4+
COMPLETED("완료"),
5+
IN_PROGRESS("수강중"),
6+
PLANNED("수강예정"),
7+
FAILED("미이수");
8+
9+
private final String description;
10+
11+
StudentCourseStatus(String description) {
12+
this.description = description;
13+
}
14+
15+
public String getDescription() {
16+
return description;
17+
}
18+
}
Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
package com.example.enjoy.entity;
22

3-
import jakarta.persistence.Entity;
4-
import jakarta.persistence.GeneratedValue;
5-
import jakarta.persistence.GenerationType;
6-
import jakarta.persistence.Id;
7-
import lombok.Getter;
3+
import com.example.enjoy.dto.StudentCourseStatus;
4+
import jakarta.persistence.*;
5+
import lombok.*;
6+
7+
import java.time.LocalDateTime;
88

99
@Entity
1010
@Getter
11-
public class StudentCourse { // 학생이 실제로 이수한 과목
11+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
12+
@AllArgsConstructor
13+
@Builder
14+
public class StudentCourse extends BaseTimeEntity {
15+
1216
@Id
1317
@GeneratedValue(strategy = GenerationType.IDENTITY)
1418
private Long id;
15-
private Long studentId; // 학생 ID (로그인 연동)
19+
20+
@Column(nullable = false)
21+
private String studentId;
22+
23+
@Column(nullable = false)
1624
private String courseName;
17-
}
25+
26+
@Enumerated(EnumType.STRING)
27+
@Column(nullable = false)
28+
private StudentCourseStatus status;
29+
30+
@Column(nullable = false)
31+
private boolean manual;
32+
33+
@Column(nullable = false)
34+
private LocalDateTime createdAt;
35+
36+
public void updateStatus(StudentCourseStatus status) {
37+
this.status = status;
38+
}
39+
40+
}

src/main/java/com/example/enjoy/repository/StudentCourseRepository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
public interface StudentCourseRepository extends JpaRepository<StudentCourse, Long> {
1010

11-
List<StudentCourse> findByStudentId(Long studentId);
11+
List<StudentCourse> findByStudentId(String studentId);
12+
1213

13-
@Transactional
14-
void deleteByStudentId(Long studentId); // 학생 ID로 이수과목 한번에 삭제
1514
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.enjoy.repository;
2+
3+
import com.example.enjoy.entity.Track;
4+
import com.example.enjoy.entity.TrackCourse;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
import java.util.List;
9+
@Repository
10+
public interface TrackCourseRepository extends JpaRepository<TrackCourse, Long> {
11+
12+
List<TrackCourse> findAllByTrack(Track track);
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.enjoy.repository;
2+
3+
import com.example.enjoy.entity.user.User;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.stereotype.Repository;
6+
7+
@Repository
8+
public interface UserRepository extends JpaRepository<User,Long> {
9+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Map<String, List<Track>> getAllTracksGroupedByDepartment() {
4141
/**
4242
* 학생이 이수한 과목 이름을 Set으로 반환하는 private 메서드
4343
*/
44-
public List<TrackProgressDto> calculateTrackProgress(Long studentId) {
44+
public List<TrackProgressDto> calculateTrackProgress(String studentId) {
4545
// 1. 학생의 이수 과목 목록 조회
4646
Set<String> completedCourseNames = studentCourseRepository.findByStudentId(studentId)
4747
.stream()
@@ -98,7 +98,7 @@ public List<TrackProgressDto> calculateTrackProgress(Long studentId) {
9898
* 학생이 이수한 과목 이름을 Set으로 반환하는 메서드
9999
*/
100100
@Transactional(readOnly = true)
101-
public TrackDetailDto getTrackDetails(Long studentId, Long trackId) {
101+
public TrackDetailDto getTrackDetails(String studentId, Long trackId) {
102102

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

0 commit comments

Comments
 (0)