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: album 생성, 수정, 삭제 API #68

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: album 생성, 수정, 삭제 API #68

wants to merge 6 commits into from

Conversation

yongseok-dev
Copy link
Member

@yongseok-dev yongseok-dev commented Nov 19, 2023

  • 이슈 연결하기

작업 내용

  • API 작성
  • 생성
    • album 생성
    • userAlbum 생성
      • 동일 유저 앨범 권한 중복 저장 방지
        • HOST, MEMBER, GUEST 순으로 저장하면서 확인
  • 수정
    • HOST만 수정 가능하며 album 업데이트, userAlbum 삭제 후 생성
  • 삭제(소프트 딜리트)
    • 앨범 권한에 따른 삭제 방법
      • HOST: 앨범 삭제, 앨범의 모든 유저의 권한 삭제
      • MEMBER/GUEST: 본인 권한 삭제

고민

  • userId로 공유 유저를 설정하다보니, 악의적 사용자가 스팸을 보낼 수 있을 것 같습니다.

참고사항

#29

Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
8.7% 8.7% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link
Contributor

@username1103 username1103 left a comment

Choose a reason for hiding this comment

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

고민한 흔적들이 느껴지네요 고생하셨어요! 👍🏻

이제 다음은 슬롯!?

Comment on lines +44 to +63
public static UserAlbum createHost(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.HOST);
}

public static UserAlbum createMember(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.MEMBER);
}

public static UserAlbum createGuest(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.GUEST);
}

private static UserAlbum createUserAlbum(
@Nonnull Long albumId, @Nonnull Long userId, @Nonnull UserAlbumRole role) {
UserAlbum userAlbum = new UserAlbum();
userAlbum.albumId = albumId;
userAlbum.userId = userId;
userAlbum.role = role;
return userAlbum;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

Copy link
Member

Choose a reason for hiding this comment

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

image

@Nonnull Long userId,
List<Long> memberUserIds,
List<Long> guestUserIds) {
Set<Long> userIds = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Set을 사용한 이유가 중복해서 사용자가 추가되지 않도록 하기위해서지?

밑에서 add 해서 새롭게 추가되었을 때만 디비에 적재하는거구.

Copy link
Member Author

Choose a reason for hiding this comment

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

딱 맞음! 동일 사용자가 여러 권한을 갖지 않도록.

parameterWithName("albumId")
.description("앨범 아이디")
.type(SimpleType.NUMBER))
.requestSchema(Schema.schema("UpdateAlbumRequest"))
Copy link
Contributor

Choose a reason for hiding this comment

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

requestSchema만 지정해도 swagger가 잘나오나 궁금해서요. 내부 필드들에 대한 선언 없이도 잘나오나요??

Copy link
Member Author

Choose a reason for hiding this comment

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

앗... 수정하겠습니다.

Comment on lines +105 to +128
Set<Long> userIds = new HashSet<>();

UserAlbum hostUserAlbum = UserAlbum.createHost(albumId, userId);

userAlbumRepository.save(hostUserAlbum);
userIds.add(userId);

if (memberUserIds != null) {
for (Long memberId : memberUserIds) {
if (userIds.add(memberId)) {
UserAlbum memberUserAlbum = UserAlbum.createMember(albumId, memberId);
userAlbumRepository.save(memberUserAlbum);
}
}
}
if (guestUserIds != null) {
for (Long guestId : guestUserIds) {
if (userIds.add(guestId)) {
UserAlbum guestUserAlbum = UserAlbum.createGuest(albumId, guestId);
userAlbumRepository.save(guestUserAlbum);
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

생성쪽과 동일한 로직인 것 같은데 맞다면 메서드로 빼도 좋을 것 같아

Copy link
Member Author

Choose a reason for hiding this comment

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

맞아요👍 반영하겠습니다.

Copy link
Member

@pythonstrup pythonstrup left a comment

Choose a reason for hiding this comment

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

  • 고생하셨어요~
  • 코드 중복 때문에 소나클라우드 터진 것 같아요!

Comment on lines +44 to +63
public static UserAlbum createHost(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.HOST);
}

public static UserAlbum createMember(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.MEMBER);
}

public static UserAlbum createGuest(@Nonnull Long albumId, @Nonnull Long userId) {
return createUserAlbum(albumId, userId, UserAlbumRole.GUEST);
}

private static UserAlbum createUserAlbum(
@Nonnull Long albumId, @Nonnull Long userId, @Nonnull UserAlbumRole role) {
UserAlbum userAlbum = new UserAlbum();
userAlbum.albumId = albumId;
userAlbum.userId = userId;
userAlbum.role = role;
return userAlbum;
}
Copy link
Member

Choose a reason for hiding this comment

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

image

Comment on lines +41 to +44
if (album != null) {
album.softDelete();
entityManager.merge(album);
}
Copy link
Member

Choose a reason for hiding this comment

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

  • 혹시 위에서 find를 했는데 entityManager.merge(album)를 꼭 사용해야할 이유가 있을까요?
  • merge를 안 해주더라도 JPA 더티 체킹으로 자동 업데이트 되지 않을까하는 생각이 들어서요!
  • 더티 체킹 참고 자료
  • (제가 모르는 무엇인가) 이유가 있다면 merge를 사용해도 상관 없을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

감사해요. merge 사용한 부분들 체크해보고 불필요한 부분은 제거하겠습니다!

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.

3 participants