Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions MLS/MLS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -652,7 +635,6 @@
77FA68762F72C7360064B6EB /* Sources */,
77FA68772F72C7360064B6EB /* Frameworks */,
77FA68782F72C7360064B6EB /* Resources */,
77A293332F79989200845081 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public enum FactoryAssembly {
CollectionEditFactoryImpl(
bookmarkModalFactory: DIContainer.resolve(
type: BookmarkModalFactory.self
),
collectionRepository: DIContainer.resolve(
type: CollectionRepository.self
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import MLSAppFeatureInterface
import MLSAuthFeature
import MLSAuthFeatureInterface
import MLSBookmarkFeature
import MLSBookmarkFeatureInterface
import MLSCore
import MLSDictionaryFeature
import MLSDictionaryFeatureInterface
Expand Down Expand Up @@ -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)
// )
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -61,4 +66,9 @@ private extension CollectionRepositoryImpl {
let collectionIds: [Int]
let bookmarkIds: [Int]
}

struct DeleteBody: Encodable {
let collectionIds: [Int]
let bookmarkIds: [Int]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: "북마크 요청에 실패했어요. 다시 시도해주세요.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutation> {
switch action {
case .backButtonTapped:
return .just(.navigateTo(.dismiss))
case .deleteCollectionButtonTapped:
return .just(.navigateTo(.showAlert))
case .addCollectionButtonTapped:
return .just(.navigateTo(.collectionList))
case .itemTapped(let index):
Expand All @@ -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))
}
}

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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() {
Expand All @@ -58,6 +60,7 @@ private extension CollectionEditView {
addSubview(titleLabel)
addSubview(listCollectionView)
addSubview(divider)
addSubview(deleteButtton)
addSubview(addButtton)
}

Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MLSCore

public protocol CollectionEditFactory {
func make(bookmarks: [BookmarkResponse]) -> BaseViewController
func make(collection: CollectionResponse?) -> BaseViewController
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.