Skip to content

Commit

Permalink
refactor: response에 메시지 제거
Browse files Browse the repository at this point in the history
StudyCreateResponse에서 message를 제거하고 id만 반환하도록 함
MessageResponse DTO 제거
  • Loading branch information
ybkang1108 committed Jan 17, 2025
1 parent 52858dc commit 33b6e77
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/gdgoc/study_group/study/api/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public StudyController(StudyService studyService, StudyRepository studyRepositor

@PostMapping()
public ResponseEntity<StudyCreateResponse> createStudy(@RequestBody StudyCreateRequest request) {
StudyCreateResponse newStudy = studyService.createStudy(1L, request); // 임시 유저
Long createdStudyId = studyService.createStudy(1L, request); // 임시 유저

return ResponseEntity.status(HttpStatus.CREATED).body(newStudy);
return ResponseEntity.status(HttpStatus.CREATED)
.body(StudyCreateResponse.builder().id(createdStudyId).build());
}

@GetMapping()
Expand All @@ -37,8 +38,7 @@ public ResponseEntity<?> getStudyDetail(@PathVariable("studyId") Long studyId) {
StudyDetailResponse studyDetail = studyService.getStudyDetail(studyId);

if (studyDetail == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("해당하는 스터디가 없습니다.");
}

return ResponseEntity.status(HttpStatus.OK).body(studyDetail);
Expand All @@ -47,26 +47,26 @@ public ResponseEntity<?> getStudyDetail(@PathVariable("studyId") Long studyId) {
@PatchMapping("/{studyId}")
public ResponseEntity<?> updateStudy(
@PathVariable("studyId") Long studyId, @RequestBody StudyCreateRequest updateRequest) {

Long updatedStudyId = studyService.updateStudy(studyId, updateRequest);

if (updatedStudyId == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다").build());
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}

return ResponseEntity.status(HttpStatus.OK)
.body(StudyCreateResponse.builder().message("스터디가 수정되었습니다.").id(updatedStudyId).build());
.body(StudyCreateResponse.builder().id(updatedStudyId).build());
}

@DeleteMapping("/{studyId}")
public ResponseEntity<MessageResponse> deleteStudy(@PathVariable("studyId") Long studyId) {
public ResponseEntity<String> deleteStudy(@PathVariable("studyId") Long studyId) {

boolean isStudyExist = studyService.deleteStudy(studyId);

if (isStudyExist) {
return ResponseEntity.status(HttpStatus.NO_CONTENT)
.body(MessageResponse.builder().message("스터디가 삭제되었습니다.").build());
return ResponseEntity.status(HttpStatus.NO_CONTENT).body("스터디가 삭제되었습니다.");
}

return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("해당하는 스터디가 없습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Day createDay(DayDTO dayDTO, Study study) {
* @param createRequest 스터디 생성 DTO
* @return ResponseDTO 반환
*/
public StudyCreateResponse createStudy(Long userId, StudyCreateRequest createRequest) {
public Long createStudy(Long userId, StudyCreateRequest createRequest) {

Study study =
Study.builder()
Expand Down Expand Up @@ -87,7 +87,7 @@ public StudyCreateResponse createStudy(Long userId, StudyCreateRequest createReq

studyRepository.save(study);

return StudyCreateResponse.builder().message("스터디가 생성되었습니다").id(study.getId()).build();
return study.getId();
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/gdgoc/study_group/study/dto/MessageResponse.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
@Getter
@Builder
public class StudyCreateResponse {
private String message;
private Long id;
}

0 comments on commit 33b6e77

Please sign in to comment.