Skip to content

Commit

Permalink
feat: 검색 결과에서 상세 볼 때, watch api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
lina0322 committed Sep 4, 2024
1 parent fb322a1 commit fc5691d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject {

private let searchKeywordUseCase: SearchKeywordUseCase
private let copyImageUseCase: CopyImageUseCase
private let watchMemeUseCase: WatchMemeUseCase

// MARK: - Initializers

public init(
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
Expand All @@ -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
Expand Down Expand Up @@ -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)")
}
}
}

0 comments on commit fc5691d

Please sign in to comment.