Skip to content
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

[FEAT] 유저 차단 관련 기능 구현 #55

Merged
merged 52 commits into from
Jun 14, 2024
Merged

[FEAT] 유저 차단 관련 기능 구현 #55

merged 52 commits into from
Jun 14, 2024

Conversation

Kim-TaeUk
Copy link
Contributor

@Kim-TaeUk Kim-TaeUk commented Jun 8, 2024

Related Issue

Key Changes

UserIdValidator

  • 기존: UserIdValidatoruserId가 0인 경우에도 valid함으로 판단했습니다. 공지사항에서 userId가 쓰이는데, 0인 경우 전체 유저 대상이기 때문입니다.
  • 변경 후: userId는 user 테이블의 PK이기 때문에 0보다 작거나 같을 수 없으므로, 0보다 작거나 같을 때 InvalidUserIdException(400 Bad Request)을 던집니다.
  • 존재할 수 없는 userId 값은 0보다 작거나 같거나, 유저 테이블에 존재하는 최대 userId 값보다 큰 값인데, 일단 최대 userId보다 큰 값에 대해서는 validation을 하지 않고 UserNotFoundException(404 Not Found)를 던집니다. -> 이 부분은 어떻게 validation하는지 좀 더 고민해보겠습니다.
  • UserIdValidator는 커스텀 어노테이션인 UserIdConstraint의 validation을 위해 쓰입니다.

UserIdInclusiveZeroValidator

  • userId 중 0을 허용하는 경우에 사용하기 위해 만들었습니다.
  • 변경된 UserIdValidator와 중복되는 로직이 있기 때문에, UserIdValidatorcomposition하여 사용합니다.
  • userId가 0인 경우(= inclusiveZero할 때)에는 바로 valid함을 return하고, userId가 0이 아닌 경우에는 UserIdValidator에게 판단을 위임합니다. 따라서 userId가 0일 때는 valid, 0보다 작을 때는 InvalidUserIdException(400 Bad Request)을 던집니다.
  • UserIdInclusiveZeroValidator는 커스텀 어노테이션인 UserIdInclusiveZeroConstraint의 validation을 위해 쓰입니다.

BlockIdValidator

  • UserIdValidator에서와 마찬가지로 존재할 수 없는(0보다 작거나 같은) PK에 대해서는 InvalidBlockIdException(400 Bad Request)을 던지고, 조회 후 결과가 없을 때는 BlockNotFoundException(404 Not Found)를 던집니다.
  • BlockIdValidator는 커스텀 어노테이션인 BlockIdConstraint의 validation을 위해 쓰입니다.

타 유저 차단 API

  • 이전에 논의했던 것처럼 엔드포인트 변경했습니다. users/blocks -> blocks
  • 기존에는 DB에 새로운 레코드를 추가할 때 Builder 패턴을 주로 사용했는데, 정적 팩터리 메서드 패턴을 사용해봤습니다. 코드가 훨씬 깔끔해진 것 같긴 한데, 의견 제시 부탁드립니다!! (ref1: 이펙티브 자바 item01에 빌더 패턴과 정적 팩터리 메서드 패턴을 비교하는 주제가 있어서 제가 정리한 자료 레퍼런스에 달아두었습니다.)
  • 실패 케이스를 좀 더 자세하게 분류해봤습니다. -> 관리자를 차단하는 경우도 반영하면 좋을 것 같다고 해서 추가 예정입니다
    • 400 Bad Request: 존재할 수 있는 userId가 아닐 경우(유효한 값이 아닌 경우 ex. 0, 음수), 자기 자신을 차단 시도한 경우
    • 401 Unauthorized: 토큰 문제
    • 404 Not Found: 존재할 수 있는 userId이지만, userId에 해당하는 유저가 없는 경우
    • 409 Conflict: 이미 차단된 유저인 경우

차단 목록 조회 API

  • 이전에 논의했던 것처럼 엔드포인트 변경했습니다. users/blocks -> blocks

차단 삭제 API

  • 이전에 논의했던 것처럼 엔드포인트 변경했습니다. users/blocks -> blocks
  • 실패 케이스를 좀 더 자세하게 분류해봤습니다.
    • 400 Bad Request: 존재할 수 있는 blockId가 아닌 경우(유효한 값이 아닌 경우 ex. 0, 음수)
    • 401 Unauthorized: 토큰 문제
    • 403 Forbidden: 존재할 수 있는 blockId이지만, 해당 유저의 차단이 아닌 경우
    • 404 Not Found: 존재할 수 있는 blockId지만, blockId에 해당하는 차단이 없는 경우

To Reviewers

  • custom validator를 정의해서 annotation을 사용한 이유는 검증해야하는 값이 들어오는 controller에서 즉시 처리하고 싶었기 때문입니다. 유효하지 않은 값 자체가 service layer로 가서 로직을 타는게 싫었습니다! (좋은 방법인지는 잘 모르겠습니다,, ㅎㅎ)
  • ref1: https://wooki99.notion.site/Item-1-93f967817dcb45c9b986ba3e3fae5738?pvs=4

@UserIdConstraint는 db에 존재하는 userId일 때와 userId=0일 때도 유효함
-> db에 존재하는 userId일 때만 유효함
userId=0일 때 로직 추가,
db에 존재하는 userId인지 검사는 composition으로 userIdValidator를 사용
validator로 UserIdInclusiveZeroValidator를 사용
BlockGetResponse
BlocksGetResponse
Copy link
Member

@ChaeAg ChaeAg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어후 대단히 고생하셨네요 🥹👍
코멘트 확인 해주시면 승인하겠습니다!

Copy link
Contributor

@rinarina0429 rinarina0429 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 양이 엄청 많네요! 여러 예외사항을 꼼꼼하게 막아두신거 보고 많이 배워갑니다.. 수고하셨습니다~

userId가 0을 허용한다는 의미 포함하여 리네임
유효한 값 검증만 하도록 변경
Copy link
Member

@ChaeAg ChaeAg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경사항 확인했습니당!~ 👍

Copy link
Contributor

@rinarina0429 rinarina0429 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~

@Kim-TaeUk Kim-TaeUk merged commit d37820a into dev Jun 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 유저 차단 관련 기능 구현
3 participants