Skip to content

Commit

Permalink
200~24-25-Server-Assignment-04_어경빈
Browse files Browse the repository at this point in the history
  • Loading branch information
Ek, Kyungbin committed Nov 5, 2024
1 parent f6c7c32 commit e738513
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public ResponseEntity<StudentCourseInfoResponseDto> save(@RequestBody StudentCou
}

@GetMapping("/{studentcourseId}")
public ResponseEntity<StudentCourseInfoResponseDto> findByBookId(@PathVariable(name = "studentCoursed") int studentCourseId) {
return new ResponseEntity<>(studentCourseService.findByStudentCourseId(studentCourseId), HttpStatus.OK);
public ResponseEntity<StudentCourseInfoResponseDto> findByStudentCourseId(@PathVariable(name = "studentcourseId") int studentcourseId) {
return new ResponseEntity<>(studentCourseService.findByStudentCourseId(studentcourseId), HttpStatus.OK);
}
@DeleteMapping("/{studentCourseId}")
public ResponseEntity<StudentCourseInfoResponseDto> deleteByStudentCourseId(@PathVariable(name = "studentCourseId") int studentCourseId) {
Expand All @@ -33,4 +33,9 @@ public ResponseEntity<StudentCourseInfoResponseDto> deleteByStudentCourseId(@Pat
return new ResponseEntity<>(HttpStatus.OK);
}

@GetMapping
public ResponseEntity<List<StudentCourseInfoResponseDto>> findAll() {
return new ResponseEntity<>(studentCourseService.findAll(), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class CourseSaveRequestDto {
private String subjectName;
private int roomNum;

public Course toEntity(){
public Course toEntity(CourseSaveRequestDto dto){
return Course.builder()
.subjectName(subjectName)
.roomNum(roomNum)
.subjectName(dto.getSubjectName())
.roomNum(dto.getRoomNum())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.jpaproject.dto.StudentCourseDto;

import com.example.jpaproject.domain.StudentCourse;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -12,5 +13,14 @@ public class StudentCourseSaveRequestDto {
private int studentId;
private int courseId;

// 여기선 toEntity 안해줘도 되는건가??
/*
이미 service에서 이미 형변환해주었기 때문에 여기서 또 할 필요는 없음.
public StudentCourse toEntity(StudentCourseSaveRequestDto dto){
return StudentCourse.builder()
.id(studentId)
.build();
}
*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CourseService {
//Create : 새로운 과목을 생성한다.
public CourseInfoResponseDto save(CourseSaveRequestDto courseSaveRequestDto) {
// 전달받은 Dto를 엔터티로 변환하여 Repository에 저장한다.
Course cours = courseSaveRequestDto.toEntity();
Course cours = courseSaveRequestDto.toEntity(courseSaveRequestDto);
courseRepository.save(cours);

return CourseInfoResponseDto.from(cours); //클라이언트한테 갈 정보
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.example.jpaproject.repository.CourseRepository;
import com.example.jpaproject.repository.StudentCourseRepository;
import com.example.jpaproject.repository.StudentRepository;
import jakarta.persistence.Id;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -32,6 +31,7 @@ public StudentCourseInfoResponseDto save(StudentCourseSaveRequestDto studentCour
Student student = studentRepository.findById(studentCourseSaveRequestDto.getStudentId())
.orElseThrow(() -> new RuntimeException("없는 학생입니다."));

// setvice에서 builder한거임
StudentCourse studentCourse = StudentCourse.builder()
.student(student)
.course(course)
Expand All @@ -44,8 +44,8 @@ public StudentCourseInfoResponseDto save(StudentCourseSaveRequestDto studentCour

// 수강신청 조회 기능
@Transactional(readOnly = true)
public StudentCourseInfoResponseDto findByStudentCourseId(int studentCourseId) {
StudentCourse studentCourse = studentCourseRepository.findById(studentCourseId)
public StudentCourseInfoResponseDto findByStudentCourseId(int studentcourseId) {
StudentCourse studentCourse = studentCourseRepository.findById(studentcourseId)
.orElseThrow(()-> new RuntimeException("없는 수강신청 기록입니다."));

return StudentCourseInfoResponseDto.from(studentCourse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public StudentInfoResponseDto findByStudentId(int id) {
public StudentInfoResponseDto updateByStudentId(int id, StudentSaveRequestDto studentSaveRequestDto) {
Student student = studentRepository.findById(id)
.orElseThrow(() -> new RuntimeException("없는 학생 id입니다."));
student.update(studentSaveRequestDto.getName(), studentSaveRequestDto.getMajor());
student.update(studentSaveRequestDto.getName(), studentSaveRequestDto.getMajor());

return StudentInfoResponseDto.from(student);

Expand Down
2 changes: 1 addition & 1 deletion kyungbin/JpaProject/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:

jpa:
hibernate:
ddl-auto: create
ddl-auto: update
properties:
hibernate:
show_sql: true
Expand Down
Binary file added kyungbin/poastman/post(수강신청).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e738513

Please sign in to comment.