Skip to content
Open
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
@@ -1,5 +1,6 @@
package com.example.jpapractice.controller;

import com.example.jpapractice.dto.StudentDto;
import com.example.jpapractice.entity.Student;
import com.example.jpapractice.service.StudentService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -30,7 +31,7 @@ public ResponseEntity<Student> createStudent(@RequestBody Student student) {
* @return 학생 목록
*/
@GetMapping
public ResponseEntity<List<Student>> getAllStudents() {
public ResponseEntity<List<StudentDto>> getAllStudents() {
return ResponseEntity.ok(studentService.getAllStudents());
}

Expand All @@ -40,7 +41,7 @@ public ResponseEntity<List<Student>> getAllStudents() {
* @return 학생 정보
*/
@GetMapping("/{id}")
public ResponseEntity<Student> getStudentById(@PathVariable Long id) {
public ResponseEntity<StudentDto> getStudentById(@PathVariable Long id) {
return ResponseEntity.ok(studentService.getStudentById(id));
}

Expand All @@ -51,7 +52,7 @@ public ResponseEntity<Student> getStudentById(@PathVariable Long id) {
* @return 수정된 학생 정보
*/
@PutMapping("/{id}")
public ResponseEntity<Student> updateStudent(
public ResponseEntity<StudentDto> updateStudent(
@PathVariable Long id,
@RequestBody Student updatedStudent) {
return ResponseEntity.ok(studentService.updateStudent(id, updatedStudent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public StudentDto getStudentById(Long id) {
* @return 수정된 학생 정보
*/
@Transactional
public Student updateStudent(Long id, Student updatedStudent) {
Student existingStudent = getStudentById(id);
public StudentDto updateStudent(Long id, Student updatedStudent) {
StudentDto existingStudent = getStudentById(id);
existingStudent.setName(updatedStudent.getName());
existingStudent.setAge(updatedStudent.getAge());
existingStudent.setClassRoom(updatedStudent.getClassRoom());
existingStudent.setClassRoomName(updatedStudent.getClassRoom().getName());
existingStudent.setClassRoomId(updatedStudent.getClassRoom().getId());
return existingStudent;
}

Expand Down