-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 비회원 댓글 비밀번호만 체크하는 API 만들기 / 관리자 댓글 삭제 기능 (#217) #230
Changes from all commits
1178e98
31063c4
1136a9d
3d39cbe
e2e3367
4d0f40f
3f9252e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
/db | ||
db/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,16 @@ | |
|
||
import com.darass.darass.auth.oauth.domain.RequiredLogin; | ||
import com.darass.darass.comment.controller.dto.UserResponse; | ||
import com.darass.darass.user.controller.dto.PasswordCheckRequest; | ||
import com.darass.darass.user.controller.dto.PasswordCheckResponse; | ||
import com.darass.darass.user.controller.dto.UserUpdateRequest; | ||
import com.darass.darass.user.domain.User; | ||
import com.darass.darass.user.service.UserService; | ||
import javax.validation.Valid; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/users") | ||
|
@@ -42,4 +39,9 @@ public ResponseEntity<Void> delete(@RequiredLogin User user) { | |
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@GetMapping("/check-password") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. api 이름 괜찮다고 생각합니다! 👍 👍 |
||
public ResponseEntity<PasswordCheckResponse> checkGuestUserPassword(@ModelAttribute PasswordCheckRequest passwordCheckRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get요청일 때 @RequestParam이랑 @PathParam만 사용해봐서 그런데, @ModelAttribute의 역할이 어떻게 되나요~? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modelattribute를 사용하면 여러 쿼리파람들이 들어올때 그것을 하나의 dto 객체로 바인딩하여 받을 수 있습니다~ |
||
PasswordCheckResponse passwordCheckResponse = userService.checkGuestUserPassword(passwordCheckRequest); | ||
return ResponseEntity.ok(passwordCheckResponse); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.darass.darass.user.controller.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PasswordCheckRequest { | ||
|
||
@NotNull | ||
private Long guestUserId; | ||
|
||
@NotNull | ||
private String guestUserPassword; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.darass.darass.user.controller.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PasswordCheckResponse { | ||
|
||
private Boolean isCorrectPassword; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,8 @@ | |||||
|
||||||
import com.darass.darass.comment.controller.dto.UserResponse; | ||||||
import com.darass.darass.exception.ExceptionWithMessageAndCode; | ||||||
import com.darass.darass.user.controller.dto.PasswordCheckRequest; | ||||||
import com.darass.darass.user.controller.dto.PasswordCheckResponse; | ||||||
import com.darass.darass.user.controller.dto.UserUpdateRequest; | ||||||
import com.darass.darass.user.domain.User; | ||||||
import com.darass.darass.user.repository.UserRepository; | ||||||
|
@@ -18,8 +20,8 @@ public class UserService { | |||||
private final UserRepository users; | ||||||
|
||||||
public UserResponse findById(Long id) { | ||||||
Optional<User> expectedUser = users.findById(id); | ||||||
User user = expectedUser.orElseThrow(ExceptionWithMessageAndCode.NOT_FOUND_USER::getException); | ||||||
Optional<User> possibleUser = users.findById(id); | ||||||
User user = possibleUser.orElseThrow(ExceptionWithMessageAndCode.NOT_FOUND_USER::getException); | ||||||
|
||||||
return UserResponse.of(user, user.getUserType(), user.getProfileImageUrl()); | ||||||
} | ||||||
|
@@ -36,4 +38,13 @@ public void deleteById(Long id) { | |||||
users.deleteById(id); | ||||||
} | ||||||
|
||||||
public PasswordCheckResponse checkGuestUserPassword(PasswordCheckRequest passwordCheckRequest) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 부분에 대해 통합 테스트 코드 작성해주셔야 할 것 같아요! |
||||||
Optional<User> expectedUser = users.findById(passwordCheckRequest.getGuestUserId()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
우기랑 같은 피드백을 남겼는데, Optional 변수명은 "possible + Type" 방식으로 쓰는 것이 어떨지 이야기하는 포스팅이 있었어요. 저는 더 직관적이라고 생각이 드는데 아론은 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 지적 감사합니다~ 반영했습니다! |
||||||
User user = expectedUser.orElseThrow(ExceptionWithMessageAndCode.NOT_FOUND_USER::getException); | ||||||
|
||||||
if (user.isValidGuestPassword(passwordCheckRequest.getGuestUserPassword())) { | ||||||
return new PasswordCheckResponse(true); | ||||||
} | ||||||
return new PasswordCheckResponse(false); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실패가 맞지 않나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비밀번호가 일치하지 않더라도 조회 자체는 실패한 것이 아니고 성공이라고 생각했었습니다😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 꼼꼼하게 보지 못했네요 ㅠㅠ 데일리때 설명해준대로 이해했어요 😊