-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: main
Are you sure you want to change the base?
Conversation
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
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.
고민한 흔적들이 느껴지네요 고생하셨어요! 👍🏻
이제 다음은 슬롯!?
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; | ||
} |
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.
@Nonnull Long userId, | ||
List<Long> memberUserIds, | ||
List<Long> guestUserIds) { | ||
Set<Long> userIds = new HashSet<>(); |
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.
Set을 사용한 이유가 중복해서 사용자가 추가되지 않도록 하기위해서지?
밑에서 add 해서 새롭게 추가되었을 때만 디비에 적재하는거구.
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.
딱 맞음! 동일 사용자가 여러 권한을 갖지 않도록.
parameterWithName("albumId") | ||
.description("앨범 아이디") | ||
.type(SimpleType.NUMBER)) | ||
.requestSchema(Schema.schema("UpdateAlbumRequest")) |
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.
requestSchema만 지정해도 swagger가 잘나오나 궁금해서요. 내부 필드들에 대한 선언 없이도 잘나오나요??
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.
앗... 수정하겠습니다.
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); | ||
} | ||
} | ||
} | ||
} |
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.
- 고생하셨어요~
- 코드 중복 때문에 소나클라우드 터진 것 같아요!
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; | ||
} |
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.
if (album != null) { | ||
album.softDelete(); | ||
entityManager.merge(album); | ||
} |
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.
- 혹시 위에서 find를 했는데 entityManager.merge(album)를 꼭 사용해야할 이유가 있을까요?
- merge를 안 해주더라도 JPA 더티 체킹으로 자동 업데이트 되지 않을까하는 생각이 들어서요!
- 더티 체킹 참고 자료
- (제가 모르는 무엇인가) 이유가 있다면 merge를 사용해도 상관 없을 것 같습니다.
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.
감사해요. merge
사용한 부분들 체크해보고 불필요한 부분은 제거하겠습니다!
작업 내용
고민
참고사항
#29