Skip to content
Closed
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 @@ -20,7 +20,7 @@ public class HomeController {
@GetMapping("/home")
public String showMyProgress(Model model) { // 1. Model 객체를 파라미터로 추가
// TODO: 추후 Spring Security 등과 연동하여 실제 로그인한 사용자 ID를 가져와야 함
Long currentStudentId = 1L; // 2. 테스트용 임시 학생 ID 사용
String currentStudentId = "1"; // 2. 테스트용 임시 학생 ID 사용

// 3. 학생의 이수 현황을 계산하는 새로운 서비스 메서드 호출
List<TrackProgressDto> progressData = trackService.calculateTrackProgress(currentStudentId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.example.enjoy.controller;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentDataController {
}
28 changes: 28 additions & 0 deletions src/main/java/com/example/enjoy/controller/TrackController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
package com.example.enjoy.controller;

import com.example.enjoy.dto.TrackDetailDto;
import com.example.enjoy.service.TrackService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/tracks")
public class TrackController {

private final TrackService trackService;

/**
* 특정 트랙의 상세 정보를 조회하는 API
* @param trackId 조회할 트랙의 ID
* @return TrackDetailDto - 트랙의 상세 정보
*/
@GetMapping("/{trackId}")
public TrackDetailDto getTrackDetailsById(@PathVariable Long trackId) {

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

// 5. 서비스의 메서드를 호출하여 결과를 받아온 후, 그대로 반환
return trackService.getTrackDetails(currentStudentId, trackId);
}
}
77 changes: 77 additions & 0 deletions src/main/java/com/example/enjoy/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.example.enjoy.controller;

import com.example.enjoy.dto.AddManualCourseRequest;
import com.example.enjoy.dto.StudentCourseStatus;
import com.example.enjoy.dto.loginDto.MemberCommand;
import com.example.enjoy.dto.loginDto.MemberDto;
import com.example.enjoy.entity.StudentCourse;
import com.example.enjoy.entity.Track;
import com.example.enjoy.service.loginService.SejongLoginService;
import com.example.enjoy.service.userService.UserService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import okhttp3.OkHttpClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/student")
public class UserController {

private final SejongLoginService sejongLoginService;
private final UserService userService;

public UserController(SejongLoginService sejongLoginService, UserService userService) {
this.sejongLoginService = sejongLoginService;
this.userService = userService;
}

@Operation(summary = "학생 정보 조회", description = "세종대학교 포털 인증을 통해 학생 정보를 조회합니다.")
@GetMapping("/detail")
public ResponseEntity<MemberDto> getStudentDetail(@RequestBody MemberCommand command) throws IOException {
MemberDto memberInfo = sejongLoginService.getMemberAuthInfos(command);
return ResponseEntity.ok(memberInfo);
}

@Operation(summary = "수동 과목 등록", description = "학생이 직접 수강한 과목을 등록합니다.")
@PostMapping("/courses")
public ResponseEntity<Void> addManualCourse(@Valid @RequestBody AddManualCourseRequest request) {
userService.addManualCourse(request);
return ResponseEntity.ok().build();
}

@Operation(summary = "수동 과목 삭제", description = "수동으로 등록한 과목을 삭제합니다.")
@DeleteMapping("/courses")
public ResponseEntity<Void> removeManualCourse(
@RequestParam String studentId,
@RequestParam String courseName) {
userService.removeManualCourse(studentId, courseName);
return ResponseEntity.ok().build();
}

@Operation(summary = "완료 과목 조회", description = "학생이 수강 완료한 과목 목록을 조회합니다.")
@GetMapping("/{studentId}/courses/completed")
public ResponseEntity<List<StudentCourse>> getCompletedCourses(@PathVariable String studentId) {
return ResponseEntity.ok(userService.getCompletedCourses(studentId));
}

@Operation(summary = "트랙 진행률 조회", description = "학생의 각 트랙별 진행률을 조회합니다.")
@GetMapping("/{studentId}/tracks/progress")
public ResponseEntity<Map<Track, Double>> getTrackProgress(@PathVariable String studentId) {
return ResponseEntity.ok(userService.getTrackProgress(studentId));
}

@Operation(summary = "과목 상태 변경", description = "등록된 과목의 수강 상태를 변경합니다.")
@PatchMapping("/courses/status")
public ResponseEntity<Void> updateCourseStatus(
@RequestParam String studentId,
@RequestParam String courseName,
@RequestParam StudentCourseStatus newStatus) {
userService.updateCourseStatus(studentId, courseName, newStatus);
return ResponseEntity.ok().build();
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/example/enjoy/dto/AddManualCourseRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.enjoy.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AddManualCourseRequest {

@NotBlank(message = "학번은 필수입니다.")
private String studentId;

@NotBlank(message = "과목명은 필수입니다.")
private String courseName;

@NotNull(message = "수강 상태는 필수입니다.")
private StudentCourseStatus status;
}
5 changes: 3 additions & 2 deletions src/main/java/com/example/enjoy/dto/CourseStatusDto.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.example.enjoy.dto;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
* 과목 정보 DTO
* (title, year, semester, code, status)
*/
@Getter
@Setter

@Data
public class CourseStatusDto {

private String title; // 과목명 (기존 courseName)
Expand Down
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;
}
}
18 changes: 8 additions & 10 deletions src/main/java/com/example/enjoy/dto/TrackDetailDto.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.example.enjoy.dto;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;

/**
* 상세 UI 화면의 트랙 탭 하나의 전체 정보를 담는 DTO
* 새로 정의된 CourseStatusDto를 사용
*/
@Getter
@Setter
public class TrackDetailDto {

private String trackName; // 트랙 이름
private int completedCount; // 이수한 과목 수
private int requiredCount = 6; // 이수 필요 과목 수

// 리스트의 타입이 새로운 CourseStatusDto로 변경
private List<CourseStatusDto> courses;
@Data // 또는 @Getter, @Setter 등
public class TrackDetailDto {
private Long trackId;
private String trackName;
private String department;
private String description; // 트랙에 대한 설명 추가
private List<CourseStatusDto> courses; // 트랙에 포함된 과목 목록
}
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;
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/example/enjoy/entity/TrackCertification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.enjoy.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class TrackCertification {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
3 changes: 2 additions & 1 deletion src/main/java/com/example/enjoy/entity/TrackCourse.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.example.enjoy.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.Getter;

@Entity
@Getter
@Data
public class TrackCourse {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.example.enjoy.repository;

import com.example.enjoy.dto.StudentCourseStatus;
import com.example.enjoy.entity.StudentCourse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Repository
public interface StudentCourseRepository extends JpaRepository<StudentCourse, Long> {

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


boolean existsByStudentIdAndCourseName(String studentId, String courseName);

Optional<StudentCourse> findByStudentIdAndCourseNameAndManualIsTrue(String studentId, String courseName);

List<StudentCourse> findAllByStudentIdAndStatus(String studentId, StudentCourseStatus status);

Optional<StudentCourse> findByStudentIdAndCourseName(String studentId, String courseName);

@Transactional
void deleteByStudentId(Long studentId); // 학생 ID로 이수과목 한번에 삭제
}
Original file line number Diff line number Diff line change
@@ -1,7 +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);
}
11 changes: 11 additions & 0 deletions src/main/java/com/example/enjoy/repository/TrackRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
import com.example.enjoy.entity.Track;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface TrackRepository extends JpaRepository<Track, Long> {

@Query("SELECT DISTINCT t FROM Track t LEFT JOIN FETCH t.courses")
List<Track> findAllWithCourses();

/**
* 특정 ID의 트랙을 과목 정보와 함께 조회합니다 (N+1 문제 해결).
* @param trackId 트랙 ID
* @return 트랙 정보 (Optional)
*/
@Query("SELECT t FROM Track t JOIN FETCH t.courses WHERE t.id = :trackId")
Optional<Track> findByIdWithCourses(@Param("trackId") Long trackId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package com.example.enjoy.repository;

public interface UserRepository {
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> {
}
Loading