Skip to content

Commit

Permalink
feat: 반환값으로 count 받아서 업데이트하는 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chansooo committed Oct 1, 2024
1 parent ccbe62f commit 90371f0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoidResponse>.self)
let result = await networkservice.request(endpoint, dataType: BaseDTO<MemeReactionResponseDTO>.self)
switch result {
case .success:
return
case .success(let count):
return count.data?.count ?? 0
case .failure(let failure):
throw failure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 90371f0

Please sign in to comment.