From b5d9bcc3d66176a0deaa5d27dcd304aaabb4cdc7 Mon Sep 17 00:00:00 2001 From: Hyunmin Choi Date: Sat, 30 Nov 2024 14:36:54 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 로컬 DB 명 변경 (#102) * refactor: 메서드 순서 변경 (#102) * refactor: 회원 삭제 API validation 추가 (#102) --- .../domain/course/controller/CourseController.java | 12 ++++++------ .../domain/member/controller/MemberController.java | 12 ++++++------ .../domain/member/service/MemberCommandService.java | 9 +++++---- .../question/controller/QuestionController.java | 12 ++++++------ src/main/resources/application-local.yml | 2 +- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/smunity/server/domain/course/controller/CourseController.java b/src/main/java/com/smunity/server/domain/course/controller/CourseController.java index 3320bf8..69a3a35 100644 --- a/src/main/java/com/smunity/server/domain/course/controller/CourseController.java +++ b/src/main/java/com/smunity/server/domain/course/controller/CourseController.java @@ -30,12 +30,6 @@ public ResponseEntity> readCourses(@AuthMem return ResponseEntity.ok(responseDto); } - @PostMapping("/upload") - public ResponseEntity> uploadCourses(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) { - ResultResponseDto responseDto = courseCommandService.createCourses(memberId, requestDto); - return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); - } - @GetMapping("/credit") public ResponseEntity readCoursesCredit(@AuthMember Long memberId) { CreditResponseDto responseDto = courseQueryService.readCoursesCredit(memberId); @@ -47,4 +41,10 @@ public ResponseEntity> readCultureCourses( ResultResponseDto responseDto = courseQueryService.readCultureCourses(memberId, domain); return ResponseEntity.ok(responseDto); } + + @PostMapping("/upload") + public ResponseEntity> uploadCourses(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) { + ResultResponseDto responseDto = courseCommandService.createCourses(memberId, requestDto); + return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); + } } diff --git a/src/main/java/com/smunity/server/domain/member/controller/MemberController.java b/src/main/java/com/smunity/server/domain/member/controller/MemberController.java index b7987fe..f166f7e 100644 --- a/src/main/java/com/smunity/server/domain/member/controller/MemberController.java +++ b/src/main/java/com/smunity/server/domain/member/controller/MemberController.java @@ -44,12 +44,6 @@ public ResponseEntity readMemberInfo(@AuthMember Long mem return ResponseEntity.ok(responseDto); } - @DeleteMapping("/me") - public ResponseEntity deleteMember(@AuthMember Long memberId) { - memberCommandService.deleteMember(memberId); - return ResponseEntity.noContent().build(); - } - @PutMapping("/me") public ResponseEntity updateMember(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) { MemberInfoResponseDto responseDto = memberCommandService.updateMember(memberId, requestDto); @@ -73,4 +67,10 @@ public ResponseEntity changePasswordByAuth(@AuthVerified MemberInfoResponseDto responseDto = memberCommandService.changePasswordByAuth(memberName, requestDto); return ResponseEntity.ok(responseDto); } + + @DeleteMapping("/me") + public ResponseEntity deleteMember(@AuthMember Long memberId) { + memberCommandService.deleteMember(memberId); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java b/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java index cb4aa09..8d6c2ee 100644 --- a/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java +++ b/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java @@ -36,10 +36,6 @@ public MemberInfoResponseDto updateMember(Long memberId, AuthRequestDto requestD return MemberInfoResponseDto.from(member); } - public void deleteMember(Long memberId) { - memberRepository.deleteById(memberId); - } - public MemberInfoResponseDto changePassword(Long memberId, ChangePasswordRequestDto requestDto) { Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND)); String newEncodedPw = passwordEncoder.encode(requestDto.password()); @@ -61,4 +57,9 @@ public MemberInfoResponseDto changePasswordByAuth(String username, ChangePasswor Member member = memberRepository.findByUsername(username).orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND)); return changePassword(member.getId(), requestDto); } + + public void deleteMember(Long memberId) { + Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND)); + memberRepository.delete(member); + } } diff --git a/src/main/java/com/smunity/server/domain/question/controller/QuestionController.java b/src/main/java/com/smunity/server/domain/question/controller/QuestionController.java index 98b269e..eb1607e 100644 --- a/src/main/java/com/smunity/server/domain/question/controller/QuestionController.java +++ b/src/main/java/com/smunity/server/domain/question/controller/QuestionController.java @@ -34,17 +34,17 @@ public ResponseEntity> readQuestions( return ResponseEntity.ok(responseDtoPage); } - @PostMapping - public ResponseEntity createQuestion(@AuthMember Long memberId, @RequestBody @Valid QuestionRequestDto requestDto) { - QuestionResponseDto responseDto = questionCommandService.createQuestion(memberId, requestDto); - return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); - } - @GetMapping("/{questionId}") public ResponseEntity readQuestion(@AuthMember Long memberId, @PathVariable Long questionId) { QuestionReadResponseDto responseDto = questionQueryService.readQuestion(memberId, questionId); return ResponseEntity.ok(responseDto); } + + @PostMapping + public ResponseEntity createQuestion(@AuthMember Long memberId, @RequestBody @Valid QuestionRequestDto requestDto) { + QuestionResponseDto responseDto = questionCommandService.createQuestion(memberId, requestDto); + return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); + } @PutMapping("/{questionId}") public ResponseEntity updateQuestion( diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index ef5ede2..97f2f65 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:h2:file:~/db + url: jdbc:h2:file:~/db/smunity username: sa password: driver-class-name: org.h2.Driver