diff --git a/MLS/MLS.xcodeproj/project.pbxproj b/MLS/MLS.xcodeproj/project.pbxproj index 416b2436..34043151 100644 --- a/MLS/MLS.xcodeproj/project.pbxproj +++ b/MLS/MLS.xcodeproj/project.pbxproj @@ -31,8 +31,6 @@ 77660AD52DD0D3DD007A4EF3 /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 77660AD42DD0D3DD007A4EF3 /* KakaoSDKAuth */; }; 77660AD72DD0D3DD007A4EF3 /* KakaoSDKUser in Frameworks */ = {isa = PBXBuildFile; productRef = 77660AD62DD0D3DD007A4EF3 /* KakaoSDKUser */; }; 77947A342FD802FC0010E7E9 /* MLSAppFeatureInterface in Frameworks */ = {isa = PBXBuildFile; productRef = 77947A332FD802FC0010E7E9 /* MLSAppFeatureInterface */; }; - 77A293312F79989200845081 /* DesignSystem.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77A293302F79989200845081 /* DesignSystem.framework */; }; - 77A293322F79989200845081 /* DesignSystem.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 77A293302F79989200845081 /* DesignSystem.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 77AB59ED2FBE20FD00BAB8A3 /* MLSAuthFeatureTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 77AB59EC2FBE20FD00BAB8A3 /* MLSAuthFeatureTesting */; }; 77AB59EF2FBE20FD00BAB8A3 /* MLSMyPageFeatureTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 77AB59EE2FBE20FD00BAB8A3 /* MLSMyPageFeatureTesting */; }; 77AF68822FD839E9008AAE68 /* MLSCore in Frameworks */ = {isa = PBXBuildFile; productRef = 77AF68812FD839E9008AAE68 /* MLSCore */; }; @@ -66,20 +64,6 @@ }; /* End PBXContainerItemProxy section */ -/* Begin PBXCopyFilesBuildPhase section */ - 77A293332F79989200845081 /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 77A293322F79989200845081 /* DesignSystem.framework in Embed Frameworks */, - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ 0801759E2DCD27E600D0919F /* DomainInterface.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DomainInterface.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 080D22992DB9188800294C28 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = Data.xcodeproj; sourceTree = ""; }; @@ -334,7 +318,6 @@ files = ( 77FA68BC2F72C9C70064B6EB /* SnapKit in Frameworks */, 77FA68BA2F72C9C10064B6EB /* RxSwift in Frameworks */, - 77A293312F79989200845081 /* DesignSystem.framework in Frameworks */, 77FA68BE2F72CA490064B6EB /* MLSDesignSystem in Frameworks */, 77FA68B82F72C9C10064B6EB /* RxCocoa in Frameworks */, ); @@ -652,7 +635,6 @@ 77FA68762F72C7360064B6EB /* Sources */, 77FA68772F72C7360064B6EB /* Frameworks */, 77FA68782F72C7360064B6EB /* Resources */, - 77A293332F79989200845081 /* Embed Frameworks */, ); buildRules = ( ); diff --git a/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/FactoryAssembly.swift b/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/FactoryAssembly.swift index e95bb306..2b6c2af0 100644 --- a/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/FactoryAssembly.swift +++ b/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/FactoryAssembly.swift @@ -358,6 +358,9 @@ public enum FactoryAssembly { CollectionEditFactoryImpl( bookmarkModalFactory: DIContainer.resolve( type: BookmarkModalFactory.self + ), + collectionRepository: DIContainer.resolve( + type: CollectionRepository.self ) ) } diff --git a/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/UseCaseAssembly.swift b/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/UseCaseAssembly.swift index 65cffb41..e6f50cce 100644 --- a/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/UseCaseAssembly.swift +++ b/MLS/MLSAppFeature/Sources/MLSAppFeature/Dependency/UseCaseAssembly.swift @@ -1,6 +1,8 @@ import MLSAppFeatureInterface import MLSAuthFeature import MLSAuthFeatureInterface +import MLSBookmarkFeature +import MLSBookmarkFeatureInterface import MLSCore import MLSDictionaryFeature import MLSDictionaryFeatureInterface @@ -89,5 +91,13 @@ public enum UseCaseAssembly { skipRepository: DIContainer.resolve(type: UpdateSkipRepositoryProtocol.self) ) } +// DIContainer.register(type: DeleteBookmarksUseCase.self) { +// DeleteBookmarksUseCaseImpl( +// bookmarkRepository: DIContainer +// .resolve(type: BookmarkRepository.self), +// collectionRepository: DIContainer +// .resolve(type: CollectionRepository.self) +// ) +// } } } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Endpoints/CollectionEndPoint.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Endpoints/CollectionEndPoint.swift index a5821920..6aba0b1a 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Endpoints/CollectionEndPoint.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Endpoints/CollectionEndPoint.swift @@ -23,6 +23,10 @@ enum CollectionEndPoint { .init(baseURL: base, path: "/api/v1/collections/\(id)", method: .DELETE) } + static func deleteBookmarksToCollection(body: Encodable) -> EndPoint { + .init(baseURL: base, path: "/api/v1/bookmark-collections", method: .DELETE, body: body) + } + static func addCollectionAndBookmark(body: Encodable) -> EndPoint { .init(baseURL: base, path: "/api/v1/bookmark-collections", method: .POST, body: body) } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Repositories/CollectionRepositoryImpl.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Repositories/CollectionRepositoryImpl.swift index 57a7e926..608ed7c8 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Repositories/CollectionRepositoryImpl.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Data/Repositories/CollectionRepositoryImpl.swift @@ -38,6 +38,11 @@ public final class CollectionRepositoryImpl: CollectionRepository { return provider.requestData(endPoint: endpoint, interceptor: interceptor) } + public func deleteBookmarksToCollection(collectionIds: [Int], bookmarkIds: [Int]) -> Completable { + let endpoint = CollectionEndPoint.deleteBookmarksToCollection(body: DeleteBody(collectionIds: collectionIds, bookmarkIds: bookmarkIds)) + return provider.requestData(endPoint: endpoint, interceptor: interceptor) + } + public func addCollectionAndBookmark(collectionIds: [Int], bookmarkIds: [Int]) -> Completable { let endpoint = CollectionEndPoint.addCollectionAndBookmark(body: AddBody(collectionIds: collectionIds, bookmarkIds: bookmarkIds)) return provider.requestData(endPoint: endpoint, interceptor: interceptor) @@ -61,4 +66,9 @@ private extension CollectionRepositoryImpl { let collectionIds: [Int] let bookmarkIds: [Int] } + + struct DeleteBody: Encodable { + let collectionIds: [Int] + let bookmarkIds: [Int] + } } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/BookmarkList/BookmarkListViewController.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/BookmarkList/BookmarkListViewController.swift index 0bb75f3f..dc95a171 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/BookmarkList/BookmarkListViewController.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/BookmarkList/BookmarkListViewController.swift @@ -187,7 +187,7 @@ extension BookmarkListViewController { DictionaryTabRegistry.changeTab(index: reactor.currentState.type.tabIndex) } case .edit: - let viewController = owner.collectionEditFactory.make(bookmarks: reactor.currentState.items) + let viewController = owner.collectionEditFactory.make(collection: nil) owner.navigationController?.pushViewController(viewController, animated: true) case .bookmarkError: ToastFactory.createToast(message: "북마크 요청에 실패했어요. 다시 시도해주세요.") diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionDetail/CollectionDetailViewController.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionDetail/CollectionDetailViewController.swift index 3473fb96..f543d4f2 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionDetail/CollectionDetailViewController.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionDetail/CollectionDetailViewController.swift @@ -125,7 +125,7 @@ extension CollectionDetailViewController { .bind(onNext: { owner, menu in switch menu { case .editBookmark: - let vc = owner.collectionEditFactory.make(bookmarks: reactor.currentState.collection.recentBookmarks) + let vc = owner.collectionEditFactory.make(collection: reactor.currentState.collection) owner.navigationController?.pushViewController(vc, animated: true) case .editName: let vc = owner.addCollectionFactory.make(collection: reactor.currentState.collection) diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditFactoryImpl.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditFactoryImpl.swift index 910c97b2..d5ea2bdb 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditFactoryImpl.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditFactoryImpl.swift @@ -3,13 +3,15 @@ import MLSCore public final class CollectionEditFactoryImpl: CollectionEditFactory { private let bookmarkModalFactory: BookmarkModalFactory + private let collectionRepository: CollectionRepository - public init(bookmarkModalFactory: BookmarkModalFactory) { + public init(bookmarkModalFactory: BookmarkModalFactory, collectionRepository: CollectionRepository) { self.bookmarkModalFactory = bookmarkModalFactory + self.collectionRepository = collectionRepository } - public func make(bookmarks: [BookmarkResponse]) -> BaseViewController { - let reactor = CollectionEditReactor(bookmarks: bookmarks) + public func make(collection: CollectionResponse?) -> BaseViewController { + let reactor = CollectionEditReactor(collectionRepository: collectionRepository, collection: collection) let viewController = CollectionEditViewController(bookmarkModalFactory: bookmarkModalFactory) viewController.reactor = reactor viewController.isBottomTabbarHidden = true diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditReactor.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditReactor.swift index f5c517b8..bf798589 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditReactor.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditReactor.swift @@ -7,35 +7,44 @@ final class CollectionEditReactor: Reactor { case none case dismiss case collectionList + case showAlert } enum Action { case backButtonTapped + case deleteCollectionButtonTapped case addCollectionButtonTapped case itemTapped(Int) + case deleteCollection } enum Mutation { case navigateTo(Route) case checkBookmarks([BookmarkResponse]) + case removeSelectedBookmarks } struct State { @Pulse var route: Route + var collection: CollectionResponse? var bookmarks: [BookmarkResponse] var selectedItems = [BookmarkResponse]() } var initialState: State + private let collectionRepository: CollectionRepository - init(bookmarks: [BookmarkResponse]) { - self.initialState = State(route: .none, bookmarks: bookmarks) + init(collectionRepository: CollectionRepository, collection: CollectionResponse?) { + self.collectionRepository = collectionRepository + self.initialState = State(route: .none, collection: collection, bookmarks: collection?.recentBookmarks ?? []) } func mutate(action: Action) -> Observable { switch action { case .backButtonTapped: return .just(.navigateTo(.dismiss)) + case .deleteCollectionButtonTapped: + return .just(.navigateTo(.showAlert)) case .addCollectionButtonTapped: return .just(.navigateTo(.collectionList)) case .itemTapped(let index): @@ -47,6 +56,16 @@ final class CollectionEditReactor: Reactor { newItems.append(item) } return .just(.checkBookmarks(newItems)) + case .deleteCollection: + guard let collectionId = currentState.collection?.collectionId else { + return .empty() + } + + return collectionRepository.deleteBookmarksToCollection( + collectionIds: [collectionId], + bookmarkIds: currentState.selectedItems.map(\.bookmarkId) + ) + .andThen(.just(.removeSelectedBookmarks)) } } @@ -57,6 +76,10 @@ final class CollectionEditReactor: Reactor { newState.route = route case .checkBookmarks(let bookmarks): newState.selectedItems = bookmarks + case .removeSelectedBookmarks: + let selectedIds = Set(newState.selectedItems.map(\.originalId)) + newState.bookmarks.removeAll { selectedIds.contains($0.originalId) } + newState.selectedItems = [] } return newState } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditView.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditView.swift index 13c43a62..0b0606ff 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditView.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditView.swift @@ -8,6 +8,7 @@ final class CollectionEditView: UIView { static let iconSize: CGFloat = 24 static let horizontalMargin: CGFloat = 16 static let topMargin: CGFloat = 12 + static let spacing: CGFloat = 8 static let bottomMargin: CGFloat = 14 } @@ -38,6 +39,7 @@ final class CollectionEditView: UIView { }() private let divider = DividerView() + let deleteButtton = CommonButton(style: .normal, title: "선택 북마크 삭제하기", disabledTitle: nil) let addButtton = CommonButton(style: .normal, title: "컬렉션에 추가하기", disabledTitle: nil) init() { @@ -58,6 +60,7 @@ private extension CollectionEditView { addSubview(titleLabel) addSubview(listCollectionView) addSubview(divider) + addSubview(deleteButtton) addSubview(addButtton) } @@ -83,9 +86,14 @@ private extension CollectionEditView { make.horizontalEdges.equalToSuperview() } - addButtton.snp.makeConstraints { make in + deleteButtton.snp.makeConstraints { make in make.top.equalTo(divider.snp.bottom).offset(Constant.topMargin) make.horizontalEdges.equalToSuperview().inset(Constant.horizontalMargin) + } + + addButtton.snp.makeConstraints { make in + make.top.equalTo(deleteButtton.snp.bottom).offset(Constant.spacing) + make.horizontalEdges.equalToSuperview().inset(Constant.horizontalMargin) make.bottom.equalToSuperview().inset(Constant.bottomMargin) } } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditViewController.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditViewController.swift index eb836cde..1744cee6 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditViewController.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeature/Presentation/CollectionEdit/CollectionEditViewController.swift @@ -53,6 +53,11 @@ extension CollectionEditViewController { .bind(to: reactor.action) .disposed(by: disposeBag) + mainView.deleteButtton.rx.tap + .map { Reactor.Action.deleteCollectionButtonTapped } + .bind(to: reactor.action) + .disposed(by: disposeBag) + mainView.addButtton.rx.tap .map { Reactor.Action.addCollectionButtonTapped } .bind(to: reactor.action) @@ -96,6 +101,10 @@ extension CollectionEditViewController { } } owner.present(vc, animated: true) + case .showAlert: + GuideAlertFactory.show(mainText: "선택한 북마크를 삭제하시겠습니까?\n컬렉션 뿐만 아니라 북마크에서도 삭제 됩니다.", ctaText: "확인", cancelText: "취소", ctaAction: { + reactor.action.onNext(.deleteCollection) + }) default: break } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Factories/CollectionEditFactory.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Factories/CollectionEditFactory.swift index e2986af9..faebfe4d 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Factories/CollectionEditFactory.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Factories/CollectionEditFactory.swift @@ -1,5 +1,5 @@ import MLSCore public protocol CollectionEditFactory { - func make(bookmarks: [BookmarkResponse]) -> BaseViewController + func make(collection: CollectionResponse?) -> BaseViewController } diff --git a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Repositories/CollectionRepository.swift b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Repositories/CollectionRepository.swift index d839bb4b..5bf337a3 100644 --- a/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Repositories/CollectionRepository.swift +++ b/MLS/MLSBookmarkFeature/Sources/MLSBookmarkFeatureInterface/Repositories/CollectionRepository.swift @@ -6,5 +6,6 @@ public protocol CollectionRepository { func fetchCollection(id: Int) -> Observable<[BookmarkResponse]> func updateCollectionName(collectionId: Int, name: String) -> Completable func deleteCollection(collectionId: Int) -> Completable + func deleteBookmarksToCollection(collectionIds: [Int], bookmarkIds: [Int]) -> Completable func addCollectionAndBookmark(collectionIds: [Int], bookmarkIds: [Int]) -> Completable } diff --git a/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/Contents.json b/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/Contents.json new file mode 100644 index 00000000..5fbe0641 --- /dev/null +++ b/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "checkSquareBlank.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/checkSquareBlank.svg b/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/checkSquareBlank.svg new file mode 100644 index 00000000..03355642 --- /dev/null +++ b/MLS/MLSDesignSystem/Sources/MLSDesignSystem/Resources/Image.xcassets/checkSquareBlank.imageset/checkSquareBlank.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +