diff --git a/MemorialHouse/MHApplication/MHApplication/Source/App/SceneDelegate.swift b/MemorialHouse/MHApplication/MHApplication/Source/App/SceneDelegate.swift index 96f9137..1774b1e 100644 --- a/MemorialHouse/MHApplication/MHApplication/Source/App/SceneDelegate.swift +++ b/MemorialHouse/MHApplication/MHApplication/Source/App/SceneDelegate.swift @@ -255,15 +255,6 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { ) ) - // MARK: - BookCover ViewModel - let createBookCoverUseCase = try DIContainer.shared.resolve(CreateBookCoverUseCase.self) - DIContainer.shared.register( - CreateBookViewModelFactory.self, - object: CreateBookViewModelFactory( - createBookCoverUseCase: createBookCoverUseCase - ) - ) - // MARK: Category ViewModel let createBookCategoryUseCase = try DIContainer.shared.resolve(CreateBookCategoryUseCase.self) let fetchBookCategoriesUseCase = try DIContainer.shared.resolve(FetchBookCategoriesUseCase.self) diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewController.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewController.swift index e7e109d..b253385 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewController.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewController.swift @@ -78,7 +78,6 @@ final class CreateBookViewController: UIViewController { // MARK: - Property @Published private var viewModel: CreateBookViewModel - private let input = PassthroughSubject() private var cancellables: Set = [] private let maxTitleLength = 10 @@ -89,10 +88,7 @@ final class CreateBookViewController: UIViewController { super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { - guard let createBookViewModelFactory = try? DIContainer.shared.resolve(CreateBookViewModelFactory.self) else { - return nil - } - viewModel = createBookViewModelFactory.make(houseName: "") + viewModel = CreateBookViewModel() super.init(coder: coder) } diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModel.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModel.swift index 3a8aee0..432868f 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModel.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModel.swift @@ -1,20 +1,8 @@ -import Combine -import Photos -import MHCore import MHDomain import MHFoundation +import Photos -final class CreateBookViewModel: ViewModelType { - enum Input { - case createBook - case updateTextField(text: String) - } - - enum Output { - case createdBook - case updatedBookCover - } - +struct CreateBookViewModel { var bookTitle: String = "" var bookCategory: String = "" var previousColorNumber: Int = -1 @@ -30,50 +18,5 @@ final class CreateBookViewModel: ViewModelType { default: .blue } } - private let createBookCoverUseCase: CreateBookCoverUseCase - private let output = PassthroughSubject() - private var cancellables = Set() - let houseName: String - - init( - createBookCoverUseCase: CreateBookCoverUseCase, - houseName: String - ) { - self.createBookCoverUseCase = createBookCoverUseCase - self.houseName = houseName - } - - func transform(input: AnyPublisher) -> AnyPublisher { - input.sink { [weak self] event in - switch event { - case .createBook: - Task { await self?.createBookInCoreData() } - case .updateTextField(let text): - self?.vaildateBookTitle(text: text) - } - }.store(in: &cancellables) - - return output.eraseToAnyPublisher() - } - - private func createBookInCoreData() async { - let bookCover = BookCover( - order: 0, - title: bookTitle, - imageURL: nil, - color: currentColor, - category: bookCategory, - favorite: false - ) - do { - try await createBookCoverUseCase.execute(with: bookCover) - output.send(.createdBook) - } catch { - MHLogger.error("Create BookCover 실패: \(error.localizedDescription)") - } - } - - private func vaildateBookTitle(text: String) { - bookTitle = text - } + let houseName: String = UserDefaults.standard.string(forKey: Constant.houseNameUserDefaultKey) ?? "" } diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModelFactory.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModelFactory.swift deleted file mode 100644 index 3c9dc8f..0000000 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/BookCreation/CreateBookViewModelFactory.swift +++ /dev/null @@ -1,18 +0,0 @@ -import MHDomain - -public struct CreateBookViewModelFactory { - private let createBookCoverUseCase: CreateBookCoverUseCase - - public init( - createBookCoverUseCase: CreateBookCoverUseCase - ) { - self.createBookCoverUseCase = createBookCoverUseCase - } - - func make(houseName: String) -> CreateBookViewModel { - CreateBookViewModel( - createBookCoverUseCase: createBookCoverUseCase, - houseName: houseName - ) - } -} diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewController.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewController.swift index e053fa3..fa93f0c 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewController.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/Home/HomeViewController.swift @@ -170,14 +170,8 @@ public final class HomeViewController: UIViewController { } private func moveMakingBookViewController() { - do { - let createBookViewModelFactory = try DIContainer.shared.resolve(CreateBookViewModelFactory.self) - let createBookViewModel = createBookViewModelFactory.make(houseName: viewModel.houseName) - let bookCreationViewController = CreateBookViewController(viewModel: createBookViewModel) - navigationController?.pushViewController(bookCreationViewController, animated: true) - } catch { - MHLogger.error(error.localizedDescription) - } + let bookCreationViewController = CreateBookViewController(viewModel: CreateBookViewModel()) + navigationController?.pushViewController(bookCreationViewController, animated: true) } private func configureConstraints() {