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

[NB-176, NB-188, NB-189] Album-Post 연관 관계 연결 및 삭제, 조회 기능 구현 #38

Merged
merged 7 commits into from
Aug 5, 2024

Conversation

Aram-su
Copy link
Contributor

@Aram-su Aram-su commented Aug 5, 2024

개요

NB-176

  • Album과 Post에 연결 관계 설정
  • Post 생성 시 사용된 Album과 연결하고 Album에 해당 정보를 표시 한다.

NB-188

  • Post와 연결되지 않은 Album을 조회하는 기능 추가

NB-189

  • Post 삭제 시 Album과 연결을 끊는 로직 구현

PR 유형

어떤 변경 사항이 있나요?

  • 새로운 기능 추가
  • 코드 리팩토링
  • 파일 혹은 폴더명 수정

PR Checklist

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • 커밋 메시지 컨벤션에 맞게 작성했습니다. Commit message convention 참고 (Ctrl + 클릭하세요.)
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

Aram-su added 6 commits August 5, 2024 12:18
1. Album 엔티티 개선
 - boolean postLinked 필드 추가 : Post 연결 상태 추적
 - linkPost() 메소드 구현 : Post와 연결 로직 및 중복 연결 방지

2. Post 엔티티 수정
 - Album과 일대일 매핑으로 수정
 - linkAlbum() 메소드 구현 : Album과 양방향 연결 설정

3. 연관관계 관리 로직 구현
 - PostService.createPost() : Post 생성 시 Album 연결 로직 호출

4. AlbumAlreadyLinkedToPostException 예외 추가
 - 중복 연결 시도 시 예외 발생
1. Album 엔티티 개선
 - unlinkPost() 메소드 구현 : Post와 연결 해제 로직 구현

2. Post 엔티티 개선
 - unlinkAlbum() 메소드 구현 : Album과 연결 해제 로직 구현
 - Post 삭제 시 album_id 도 null로 변경

3. PostControllerV1 메소드 수정
 - validatePostExist() 메소드 호출 삭제 : validatePostOwner() 호출과정에서 존재하는 Post가 아니면 Exception을 발생시킴

4. PostService 클래스의 메소드 개선
 - validatePostOwner() 파라미터 변경 및 로직 간소화 : User의 모든 Post와 Post를 비교하는 로직에서 User의 userId와 Post의 userId를 비교하도록 수정
1. UnauthorizedAlbumAccessException 클래스 구현
 - Album에 대한 권한이 없는 사용자 접근 시 발생

2. UnauthorizedAccessException 이름 변경
 - Post에 대한 권한이 없는 사용자라는 의미를 담기 위해 이름 변경
 - 변경 전 : UnauthorizedAccessException
 - 변경 후 : UnauthorizedPostAccessException
1. validateAlbumOwner() 클래스 구현
 - Album을 생성한 사용자의 userId와 접근한 사용자의 userId를 비교하여 접근 권한을 확인한다

2. findById() 메소드 수정
 - 반환값 변경 : Optional 에서 Album으로 수정
 - 호출자가 null 체크를 하지 않아도 됨
 - 예외처리 로직 추가 : 존재하지 않을 시 AlbumNotFoundException 발생
1. createPost() 메소드 로직 수정
 - post 생성 시 validateAlbumOwner 메소드 호출
 - post를 생성하는 사용자가 연결될 album에 대해 소유권을 가진 사용자인지 검증
1. AlbumControllerV1 기능 확장
 - getMyAlbums() 메소드에 'unlinked' 파라미터 추가
  - @RequestParam(required = false, defaultValue = "false")
  - Post 연결 여부에 따른 Album 필터링

2. AlbumService 기능 확장
 - findAlbumsByCurrentUser() 메소드 수정
  - unlinked 파라미터로 조건부 Album 조회
  - 연결 상태에 따라 모든 앨범, 연결되지 않은 앨범을 조회한다

3. AlbumRepository 쿼리 추가
 - findUnlinkedAlbumsByEmail() 메소드 구현
  - Post와 연결되지 않은 Album 조회
@liljoon liljoon self-requested a review August 5, 2024 08:10
- Post와 Album은 일대일 매핑 되어야 함.
- 그러나 2개의 Post 생성에 대해 같은 Album을 사용하였고 에러가 발생, 수정함
Copy link
Contributor

@liljoon liljoon left a comment

Choose a reason for hiding this comment

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

넵 확인했습니다.

@Aram-su Aram-su merged commit 06520d0 into dev Aug 5, 2024
1 check passed
@Aram-su Aram-su deleted the refactor/album branch August 5, 2024 08:30
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.

2 participants