From fc5691db0fb06603747b68f7436edb474527bdb6 Mon Sep 17 00:00:00 2001 From: lina Date: Wed, 4 Sep 2024 15:33:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=83=81=EC=84=B8=20=EB=B3=BC=20=EB=95=8C?= =?UTF-8?q?,=20watch=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/View/Result/SearchResultRouter.swift | 3 ++- .../View/Result/SearchResultViewModel.swift | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Projects/Features/Search/Sources/View/Result/SearchResultRouter.swift b/Projects/Features/Search/Sources/View/Result/SearchResultRouter.swift index 2ad1161..521d027 100644 --- a/Projects/Features/Search/Sources/View/Result/SearchResultRouter.swift +++ b/Projects/Features/Search/Sources/View/Result/SearchResultRouter.swift @@ -43,7 +43,8 @@ public final class SearchResultRouter: Router, SearchResultRouting { keyword: keyword, router: self, searchKeywordUseCase: SearchKeywordUseCaseImpl(repository: repository), - copyImageUseCase: CopyImageUseCaseImpl() + copyImageUseCase: CopyImageUseCaseImpl(), + watchMemeUseCase: WatchMemeUseCaseImpl(repository: repository) )) ) } diff --git a/Projects/Features/Search/Sources/View/Result/SearchResultViewModel.swift b/Projects/Features/Search/Sources/View/Result/SearchResultViewModel.swift index 26035fe..cee88c3 100644 --- a/Projects/Features/Search/Sources/View/Result/SearchResultViewModel.swift +++ b/Projects/Features/Search/Sources/View/Result/SearchResultViewModel.swift @@ -44,6 +44,7 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject { private let searchKeywordUseCase: SearchKeywordUseCase private let copyImageUseCase: CopyImageUseCase + private let watchMemeUseCase: WatchMemeUseCase // MARK: - Initializers @@ -51,12 +52,14 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject { keyword: String, router: SearchResultRouting?, searchKeywordUseCase: SearchKeywordUseCase, - copyImageUseCase: CopyImageUseCase + copyImageUseCase: CopyImageUseCase, + watchMemeUseCase: WatchMemeUseCase ) { self.router = router self.state = State(keyword: keyword, memeList: []) self.searchKeywordUseCase = searchKeywordUseCase self.copyImageUseCase = copyImageUseCase + self.watchMemeUseCase = watchMemeUseCase } // MARK: - Methods @@ -69,6 +72,7 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject { await fetchData() case .memeDetailTapped(let meme): router?.showMemeDetail(memeDetail: meme) + await postShownMeme(memeId: meme.id) case .memeCopyTapped(let meme): await copyImage(urlString: meme.imageUrlString) break @@ -98,4 +102,14 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject { debugPrint("error = \(error)") } } + + @MainActor + func postShownMeme(memeId: String?) async { + guard let memeId else { return } + do { + try await watchMemeUseCase.execute(memeId: memeId, type: "search") + } catch { + debugPrint("Failed show recommnedMeme : \(error)") + } + } }