From 90371f0adfb4576a017b30448614e73ddce19b10 Mon Sep 17 00:00:00 2001 From: chansooo Date: Wed, 2 Oct 2024 00:33:33 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B0=98=ED=99=98=EA=B0=92=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20count=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PPACData/Sources/Repository/MemeRepositoryImpl.swift | 8 ++++---- .../PPACDomain/Sources/Repository/MemeRepository.swift | 2 +- .../Sources/UseCase/Meme/ReactToMemeUseCase.swift | 4 ++-- .../Features/MemeDetail/Sources/MemeDetailViewModel.swift | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Projects/Core/PPACData/Sources/Repository/MemeRepositoryImpl.swift b/Projects/Core/PPACData/Sources/Repository/MemeRepositoryImpl.swift index 41079c1..4fe58ae 100644 --- a/Projects/Core/PPACData/Sources/Repository/MemeRepositoryImpl.swift +++ b/Projects/Core/PPACData/Sources/Repository/MemeRepositoryImpl.swift @@ -114,12 +114,12 @@ public class MemeRepositoryImpl: MemeRepository { } } - public func reactToMeme(memeId: String, count: Int) async throws { + public func reactToMeme(memeId: String, count: Int) async throws -> Int { let endpoint = MemeEndpoint.reaction(memeId: memeId, count: count) - let result = await networkservice.request(endpoint, dataType: BaseDTO.self) + let result = await networkservice.request(endpoint, dataType: BaseDTO.self) switch result { - case .success: - return + case .success(let count): + return count.data?.count ?? 0 case .failure(let failure): throw failure } diff --git a/Projects/Core/PPACDomain/Sources/Repository/MemeRepository.swift b/Projects/Core/PPACDomain/Sources/Repository/MemeRepository.swift index 8d880c1..a8b4eed 100644 --- a/Projects/Core/PPACDomain/Sources/Repository/MemeRepository.swift +++ b/Projects/Core/PPACDomain/Sources/Repository/MemeRepository.swift @@ -19,7 +19,7 @@ public protocol MemeRepository { func deleteBookmarkMeme(memeId: String) async throws func shareMeme(memeId: String) async throws func watchMeme(memeId: String, type: String) async throws - func reactToMeme(memeId: String, count: Int) async throws + func reactToMeme(memeId: String, count: Int) async throws -> Int func registerMeme(formData: FormData, title: String, source: String, keywordIds: [String]) async throws } diff --git a/Projects/Core/PPACDomain/Sources/UseCase/Meme/ReactToMemeUseCase.swift b/Projects/Core/PPACDomain/Sources/UseCase/Meme/ReactToMemeUseCase.swift index 26987bf..9208dff 100644 --- a/Projects/Core/PPACDomain/Sources/UseCase/Meme/ReactToMemeUseCase.swift +++ b/Projects/Core/PPACDomain/Sources/UseCase/Meme/ReactToMemeUseCase.swift @@ -10,7 +10,7 @@ import Foundation import PPACModels public protocol ReactToMemeUseCase { - func execute(memeId: String, count: Int) async throws + func execute(memeId: String, count: Int) async throws -> Int } public class ReactToMemeUseCaseImpl: ReactToMemeUseCase { @@ -20,7 +20,7 @@ public class ReactToMemeUseCaseImpl: ReactToMemeUseCase { self.repository = repository } - public func execute(memeId: String, count: Int) async throws { + public func execute(memeId: String, count: Int) async throws -> Int { try await repository.reactToMeme(memeId: memeId, count: count) } } diff --git a/Projects/Features/MemeDetail/Sources/MemeDetailViewModel.swift b/Projects/Features/MemeDetail/Sources/MemeDetailViewModel.swift index dc7342a..8397504 100644 --- a/Projects/Features/MemeDetail/Sources/MemeDetailViewModel.swift +++ b/Projects/Features/MemeDetail/Sources/MemeDetailViewModel.swift @@ -150,7 +150,10 @@ private extension MemeDetailViewModel { } reactionCount = 0 do { - try await reactToMemeUseCase.execute(memeId: state.meme.id, count: count) + let count = try await reactToMemeUseCase.execute(memeId: state.meme.id, count: count) + print("currentMeme count: \(self.state.meme.reaction)") + print("new count: \(count)") + self.state.meme.reaction = count print("Reactions sent successfully with count: \(count)") } catch { print("Failed to send reactions: \(error)")