-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: [FN-246] 카드셋 삭제 API #58
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package project.flipnote.bookmark.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import project.flipnote.bookmark.entity.BookmarkTargetType; | ||
| import project.flipnote.bookmark.repository.BookmarkRepository; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class BookmarkWriter { | ||
| private final BookmarkRepository bookmarkRepository; | ||
|
|
||
| /** | ||
| * 즐겨찾기를 삭제합니다. | ||
| * | ||
| * @param targetType 즐겨찾기 삭제할 대상의 타입 | ||
| * @param targetId 즐겨찾기 삭제할 대상의 ID | ||
| * @author 윤정환 | ||
| */ | ||
| public void delete(BookmarkTargetType targetType, Long targetId) { | ||
| bookmarkRepository.deleteByTargetTypeAndTargetId(targetType, targetId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package project.flipnote.cardset.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Lob; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import project.flipnote.common.entity.BaseEntity; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "cardset_contents") | ||
| @Entity | ||
| public class CardSetContent extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "cardset_id", nullable = false) | ||
| private Long cardSetId; | ||
|
|
||
| @Lob | ||
| @Column(nullable = false) | ||
| private String content; | ||
|
|
||
| @Builder | ||
| private CardSetContent(Long cardSetId, String content) { | ||
| this.cardSetId = cardSetId; | ||
| this.content = content; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package project.flipnote.cardset.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Lob; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import project.flipnote.common.entity.BaseEntity; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "cardset_incrementals") | ||
| @Entity | ||
| public class CardSetIncremental extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "cardset_id", nullable = false) | ||
| private Long cardSetId; | ||
|
|
||
| @Lob | ||
| @Column(name = "incremental_value", nullable = false) | ||
| private byte[] incrementalValue; | ||
|
|
||
| @Column(name = "is_flushed") | ||
| private boolean flushed; | ||
|
|
||
| @Builder | ||
| private CardSetIncremental(Long cardSetId, byte[] incrementalValue, boolean flushed) { | ||
| this.cardSetId = cardSetId; | ||
| this.incrementalValue = incrementalValue; | ||
| this.flushed = flushed; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package project.flipnote.cardset.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import project.flipnote.cardset.entity.CardSetContent; | ||
|
|
||
| public interface CardSetContentRepository extends JpaRepository<CardSetContent, Long> { | ||
| void deleteByCardSetId(Long cardSetId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package project.flipnote.cardset.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import project.flipnote.cardset.entity.CardSetIncremental; | ||
|
|
||
| public interface CardSetIncrementalRepository extends JpaRepository<CardSetIncremental, Long> { | ||
| void deleteByCardSetId(Long cardSetId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| import lombok.extern.slf4j.Slf4j; | ||
| import project.flipnote.bookmark.entity.BookmarkTargetType; | ||
| import project.flipnote.bookmark.service.BookmarkReader; | ||
| import project.flipnote.bookmark.service.BookmarkService; | ||
| import project.flipnote.bookmark.service.BookmarkWriter; | ||
| import project.flipnote.cardset.entity.CardSet; | ||
| import project.flipnote.cardset.entity.CardSetManager; | ||
| import project.flipnote.cardset.entity.CardSetMetadata; | ||
|
|
@@ -25,10 +25,13 @@ | |
| import project.flipnote.cardset.model.CardSetUpdateRequest; | ||
| import project.flipnote.cardset.model.CreateCardSetRequest; | ||
| import project.flipnote.cardset.model.CreateCardSetResponse; | ||
| import project.flipnote.cardset.repository.CardSetContentRepository; | ||
| import project.flipnote.cardset.repository.CardSetIncrementalRepository; | ||
| import project.flipnote.cardset.repository.CardSetManagerRepository; | ||
| import project.flipnote.cardset.repository.CardSetMetadataRepository; | ||
| import project.flipnote.cardset.repository.CardSetRepository; | ||
| import project.flipnote.common.exception.BizException; | ||
| import project.flipnote.common.model.response.IdResponse; | ||
| import project.flipnote.common.model.response.PagingResponse; | ||
| import project.flipnote.common.security.dto.AuthPrinciple; | ||
| import project.flipnote.group.entity.Category; | ||
|
|
@@ -44,6 +47,7 @@ | |
| import project.flipnote.image.service.ImageService; | ||
| import project.flipnote.like.entity.LikeTargetType; | ||
| import project.flipnote.like.service.LikeReader; | ||
| import project.flipnote.like.service.LikeWriter; | ||
| import project.flipnote.user.entity.UserProfile; | ||
| import project.flipnote.user.entity.UserStatus; | ||
| import project.flipnote.user.exception.UserErrorCode; | ||
|
|
@@ -67,6 +71,10 @@ public class CardSetService { | |
| private final GroupService groupService; | ||
| private final LikeReader likeReader; | ||
| private final BookmarkReader bookmarkReader; | ||
| private final LikeWriter likeWriter; | ||
| private final BookmarkWriter bookmarkWriter; | ||
| private final CardSetContentRepository cardSetContentRepository; | ||
| private final CardSetIncrementalRepository cardSetIncrementalRepository; | ||
|
|
||
| @Value("${image.default.cardSet}") | ||
| private String defaultCardSetImage; | ||
|
|
@@ -357,4 +365,40 @@ public PagingResponse<CardSetSummaryResponse> getCardSets(long groupId, CardSetS | |
|
|
||
| return PagingResponse.from(res); | ||
| } | ||
|
|
||
| @Transactional | ||
| public IdResponse deleteCardSet(Long userId, Long groupId, Long cardSetId) { | ||
| CardSet cardSet = cardSetPolicyService.findByIdAndGroupIdOrThrow(groupId, cardSetId); | ||
|
|
||
| cardSetPolicyService.validateCardSetEditable(userId, cardSetId); | ||
|
|
||
| // 카드셋 관리자 | ||
| cardSetManagerRepository.deleteByCardSet_Id(cardSetId); | ||
|
|
||
| // 카드셋 내용 | ||
| cardSetContentRepository.deleteByCardSetId(cardSetId); | ||
|
|
||
| // 카드셋 증분값 | ||
| cardSetIncrementalRepository.deleteByCardSetId(cardSetId); | ||
|
|
||
| // 카드셋 스냅샷 | ||
|
|
||
|
Comment on lines
+384
to
+385
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. CardSetSnapshot 삭제 로직을 구현하거나 TODO로 명확히 표시하세요. 카드셋 스냅샷 삭제가 주석 처리되어 있어 해당 데이터가 고아 데이터로 남을 수 있습니다. 스냅샷 기능이 아직 구현되지 않았다면 TODO 주석을 추가하고, 구현되었다면 삭제 로직을 추가해야 합니다. 스냅샷 삭제 구현이 필요하다면 코드를 생성해드릴 수 있습니다. 필요하신가요? 🤖 Prompt for AI Agents |
||
| // 카드셋 메타데이터 | ||
| cardSetMetadataRepository.deleteById(cardSetId); | ||
|
|
||
| // 이미지 | ||
| imageRefService.findByTypeAndReferenceId(REFERENCE_TYPE, cardSetId) | ||
| .ifPresent(imageRef -> imageRefService.deleteByReferenceAndId(REFERENCE_TYPE, imageRef.getId())); | ||
|
|
||
| // 카드셋 | ||
| cardSetRepository.delete(cardSet); | ||
|
Comment on lines
+375
to
+394
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. 이미지 리소스 정리 로직이 누락되었습니다. CardSet에 연관된 이미지(ImageRef, ImageMeta)를 삭제하는 로직이 없습니다. createCardSet 메서드(line 120, 135)와 updateCardSet 메서드(line 212)에서 이미지를 관리하는 것처럼, 삭제 시에도 imageService 또는 imageRefService를 통해 연관된 이미지를 정리해야 합니다. CardSet 삭제 전에 이미지 정리 로직을 추가하세요: cardSetPolicyService.validateCardSetEditable(userId, cardSetId);
+
+ // 이미지 정리
+ imageRefService.findByTypeAndReferenceId(REFERENCE_TYPE, cardSetId)
+ .ifPresent(imageRef -> imageService.deleteImageRef(imageRef.getId()));
// 카드셋 관리자
cardSetManagerRepository.deleteByCardSet_Id(cardSetId);
🤖 Prompt for AI Agents |
||
|
|
||
| // 좋아요 | ||
| likeWriter.delete(LikeTargetType.CARD_SET, cardSetId); | ||
|
|
||
| // 즐겨찾기 | ||
| bookmarkWriter.delete(BookmarkTargetType.CARD_SET, cardSetId); | ||
|
|
||
| return IdResponse.from(cardSetId); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package project.flipnote.like.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import project.flipnote.like.entity.LikeTargetType; | ||
| import project.flipnote.like.repository.LikeRepository; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class LikeWriter { | ||
| private final LikeRepository likeRepository; | ||
|
|
||
| /** | ||
| * 좋아요를 삭제합니다. | ||
| * | ||
| * @param targetType 좋아요 삭제 대상의 타입 | ||
| * @param targetId 좋아요 삭제 대상의 ID | ||
| * @author 윤정환 | ||
| */ | ||
| public void delete(LikeTargetType targetType, Long targetId) { | ||
| likeRepository.deleteByTargetTypeAndTargetId(targetType, targetId); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.