Skip to content

Commit

Permalink
[REFACTOR] 코드 리팩토링 (#103)
Browse files Browse the repository at this point in the history
* chore: 로컬 DB 명 변경 (#102)

* refactor: 메서드 순서 변경 (#102)

* refactor: 회원 삭제 API validation 추가 (#102)
  • Loading branch information
hyunmin0317 authored Nov 30, 2024
1 parent deb028f commit b5d9bcc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public ResponseEntity<ResultResponseDto<CourseResponseDto>> readCourses(@AuthMem
return ResponseEntity.ok(responseDto);
}

@PostMapping("/upload")
public ResponseEntity<ResultResponseDto<CourseResponseDto>> uploadCourses(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) {
ResultResponseDto<CourseResponseDto> responseDto = courseCommandService.createCourses(memberId, requestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}

@GetMapping("/credit")
public ResponseEntity<CreditResponseDto> readCoursesCredit(@AuthMember Long memberId) {
CreditResponseDto responseDto = courseQueryService.readCoursesCredit(memberId);
Expand All @@ -47,4 +41,10 @@ public ResponseEntity<ResultResponseDto<CultureResponseDto>> readCultureCourses(
ResultResponseDto<CultureResponseDto> responseDto = courseQueryService.readCultureCourses(memberId, domain);
return ResponseEntity.ok(responseDto);
}

@PostMapping("/upload")
public ResponseEntity<ResultResponseDto<CourseResponseDto>> uploadCourses(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) {
ResultResponseDto<CourseResponseDto> responseDto = courseCommandService.createCourses(memberId, requestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public ResponseEntity<MemberInfoResponseDto> readMemberInfo(@AuthMember Long mem
return ResponseEntity.ok(responseDto);
}

@DeleteMapping("/me")
public ResponseEntity<Void> deleteMember(@AuthMember Long memberId) {
memberCommandService.deleteMember(memberId);
return ResponseEntity.noContent().build();
}

@PutMapping("/me")
public ResponseEntity<MemberInfoResponseDto> updateMember(@AuthMember Long memberId, @RequestBody @Valid AuthRequestDto requestDto) {
MemberInfoResponseDto responseDto = memberCommandService.updateMember(memberId, requestDto);
Expand All @@ -73,4 +67,10 @@ public ResponseEntity<MemberInfoResponseDto> changePasswordByAuth(@AuthVerified
MemberInfoResponseDto responseDto = memberCommandService.changePasswordByAuth(memberName, requestDto);
return ResponseEntity.ok(responseDto);
}

@DeleteMapping("/me")
public ResponseEntity<Void> deleteMember(@AuthMember Long memberId) {
memberCommandService.deleteMember(memberId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public ResponseEntity<Page<QuestionReadResponseDto>> readQuestions(
return ResponseEntity.ok(responseDtoPage);
}

@PostMapping
public ResponseEntity<QuestionResponseDto> 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<QuestionReadResponseDto> readQuestion(@AuthMember Long memberId, @PathVariable Long questionId) {
QuestionReadResponseDto responseDto = questionQueryService.readQuestion(memberId, questionId);
return ResponseEntity.ok(responseDto);
}

@PostMapping
public ResponseEntity<QuestionResponseDto> 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<QuestionResponseDto> updateQuestion(
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b5d9bcc

Please sign in to comment.