From 36709fbabf74c233412308e46e341aa38193e6db Mon Sep 17 00:00:00 2001 From: chansooo Date: Sat, 29 Jun 2024 16:17:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20memedetailviewmodel=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/MemeDetailViewModel.swift | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Projects/Features/MemeDetail/Sources/Presentation/MemeDetailViewModel.swift diff --git a/Projects/Features/MemeDetail/Sources/Presentation/MemeDetailViewModel.swift b/Projects/Features/MemeDetail/Sources/Presentation/MemeDetailViewModel.swift new file mode 100644 index 0000000..6c8d5e7 --- /dev/null +++ b/Projects/Features/MemeDetail/Sources/Presentation/MemeDetailViewModel.swift @@ -0,0 +1,90 @@ +// +// MemeDetailViewModel.swift +// MemeDetail +// +// Created by kimchansoo on 6/29/24. +// + +import Foundation + +import Dependencies + +import PPACUtil +import PPACModels +import UIKit + +protocol MemeDetailRouting: AnyObject { + func popView() + func showShareView() +} + +final class MemeDetailViewModel: ViewModelType, ObservableObject { + + enum Action { + case likeButtonTapped + case copyButtonTapped + case shreButtonTapped + case farmemeButtonTapped + case naviBackButtonTapped + } + + struct State { + var meme: MemeDetail + } + + // MARK: - Properties + + weak var router: MemeDetailRouting? + @Published var state: State + + private let copyImageUseCase: CopyImageUseCase + private let postLikeUseCase: PostLikeUseCase + + + // MARK: - Initializers + + init( + meme: MemeDetail, + router: MemeDetailRouting?, + copyImageUseCase: CopyImageUseCase, + postLikeUseCase: PostLikeUseCase + ) { + self.router = router + self.state = State(meme: meme) + self.copyImageUseCase = copyImageUseCase + self.postLikeUseCase = postLikeUseCase + } + + // MARK: - Methods + + func dispatch(type: Action) { + switch type { + case .likeButtonTapped: + postLike() + case .copyButtonTapped: + copyImage() + case .shreButtonTapped: + router?.showShareView() + case .farmemeButtonTapped: + postSavedFarmeme() + case .naviBackButtonTapped: + router?.popView() + } + } +} + +private extension MemeDetailViewModel { + func postLike() { + + } + + func copyImage() { + // TODO: - 이미지 viewmodel이 알지 못하도록 수정 + let imageData: Data = try! Data(contentsOf: URL(string: state.meme.imageUrlString)!) + copyImageUseCase.execute(data: imageData) + } + + func postSavedFarmeme() { + + } +}