From 10acf034a9eacc4b5369df680da0036e4bc0bb39 Mon Sep 17 00:00:00 2001 From: MaraMincho <103064352+MaraMincho@users.noreply.github.com> Date: Sun, 10 Dec 2023 17:30:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Cancel=20API=20WorkoutID=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=98=EC=97=AC=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Data/DTO/MatchCancelRequest.swift | 17 +++++++++++++++++ .../WorkoutPeerRandomMatchingRepository.swift | 10 +++++----- ...rRandomMatchingRepositoryRepresentable.swift | 2 +- .../WorkoutPeerRandomMatchingUseCase.swift | 6 +++--- .../WorkoutPeerRandomMatchingViewModel.swift | 3 ++- 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 iOS/Projects/Features/Record/Sources/Data/DTO/MatchCancelRequest.swift diff --git a/iOS/Projects/Features/Record/Sources/Data/DTO/MatchCancelRequest.swift b/iOS/Projects/Features/Record/Sources/Data/DTO/MatchCancelRequest.swift new file mode 100644 index 00000000..46db6cb1 --- /dev/null +++ b/iOS/Projects/Features/Record/Sources/Data/DTO/MatchCancelRequest.swift @@ -0,0 +1,17 @@ +// +// MatchCancelRequest.swift +// RecordFeature +// +// Created by MaraMincho on 12/10/23. +// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved. +// + +import Foundation + +struct MatchCancelRequest: Encodable { + let workoutID: Int + + enum CodingKeys: String, CodingKey { + case workoutID = "workoutId" + } +} diff --git a/iOS/Projects/Features/Record/Sources/Data/Repositories/WorkoutPeerRandomMatchingRepository.swift b/iOS/Projects/Features/Record/Sources/Data/Repositories/WorkoutPeerRandomMatchingRepository.swift index b05d8812..0852a630 100644 --- a/iOS/Projects/Features/Record/Sources/Data/Repositories/WorkoutPeerRandomMatchingRepository.swift +++ b/iOS/Projects/Features/Record/Sources/Data/Repositories/WorkoutPeerRandomMatchingRepository.swift @@ -43,10 +43,10 @@ extension WorkoutPeerRandomMatchingRepository: WorkoutPeerRandomMatchingReposito }.eraseToAnyPublisher() } - func matchCancel() { + func matchCancel(workoutTypeCode: Int) { Task { do { - let _ = try await provider.request(.matchCancel, interceptor: TNKeychainInterceptor.shared) + let _ = try await provider.request(.matchCancel(matchCancelRequest: .init(workoutID: workoutTypeCode)), interceptor: TNKeychainInterceptor.shared) } catch { // TODO: ERROR Handling } @@ -81,7 +81,7 @@ extension WorkoutPeerRandomMatchingRepository: WorkoutPeerRandomMatchingReposito enum RepositoryError: LocalizedError { case serverError - case unkwonError + case unknwonError } // MARK: - WorkoutPeerRandomMatchingRepository.WorkoutPeerRandomMatchingRepositoryEndPoint @@ -90,7 +90,7 @@ extension WorkoutPeerRandomMatchingRepository { enum WorkoutPeerRandomMatchingRepositoryEndPoint: TNEndPoint { /// Property case matchStart(matchStartRequest: MatchStartRequest) - case matchCancel + case matchCancel(matchCancelRequest: MatchCancelRequest) case isMatchedRandomPeer(isMatchedRandomPeersRequest: IsMatchedRandomPeersRequest) /// TNEndPoint @@ -123,7 +123,7 @@ extension WorkoutPeerRandomMatchingRepository { switch self { case let .matchStart(matchStartRequest): return matchStartRequest case let .isMatchedRandomPeer(isMatchedRandomPeersRequest): return isMatchedRandomPeersRequest - case .matchCancel: return nil + case let .matchCancel(typeCode): return typeCode } } diff --git a/iOS/Projects/Features/Record/Sources/Domain/UseCases/Protocol/WorkoutPeerRandomMatchingRepositoryRepresentable.swift b/iOS/Projects/Features/Record/Sources/Domain/UseCases/Protocol/WorkoutPeerRandomMatchingRepositoryRepresentable.swift index 178d8118..bcc79dba 100644 --- a/iOS/Projects/Features/Record/Sources/Domain/UseCases/Protocol/WorkoutPeerRandomMatchingRepositoryRepresentable.swift +++ b/iOS/Projects/Features/Record/Sources/Domain/UseCases/Protocol/WorkoutPeerRandomMatchingRepositoryRepresentable.swift @@ -13,6 +13,6 @@ import Foundation protocol WorkoutPeerRandomMatchingRepositoryRepresentable { func matchStart(workoutTypeCode: Int) -> AnyPublisher, Never> - func matchCancel() + func matchCancel(workoutTypeCode: Int) func isMatchedRandomPeer(isMatchedRandomPeersRequest: IsMatchedRandomPeersRequest) -> AnyPublisher, Never> } diff --git a/iOS/Projects/Features/Record/Sources/Domain/UseCases/WorkoutPeerRandomMatchingUseCase.swift b/iOS/Projects/Features/Record/Sources/Domain/UseCases/WorkoutPeerRandomMatchingUseCase.swift index 1b6fdc51..00ca267e 100644 --- a/iOS/Projects/Features/Record/Sources/Domain/UseCases/WorkoutPeerRandomMatchingUseCase.swift +++ b/iOS/Projects/Features/Record/Sources/Domain/UseCases/WorkoutPeerRandomMatchingUseCase.swift @@ -13,7 +13,7 @@ import Foundation protocol WorkoutPeerRandomMatchingUseCaseRepresentable { func matchStart(workoutSetting: WorkoutSetting) -> AnyPublisher, Never> - func matchCancel() + func matchCancel(workoutTypeCode: Int) func isMatchedRandomPeer(isMatchedRandomPeersRequest: IsMatchedRandomPeersRequest) -> AnyPublisher, Never> } @@ -33,8 +33,8 @@ extension WorkoutPeerRandomMatchingUseCase: WorkoutPeerRandomMatchingUseCaseRepr return repository.matchStart(workoutTypeCode: workoutSetting.workoutType.typeCode) } - func matchCancel() { - return repository.matchCancel() + func matchCancel(workoutTypeCode: Int) { + return repository.matchCancel(workoutTypeCode: workoutTypeCode) } /// 만약 매칭이 잡혔으면 response의 값을 내려주고, diff --git a/iOS/Projects/Features/Record/Sources/Presentation/WorkoutPeerMatchingScene/ViewModel/WorkoutPeerRandomMatchingViewModel.swift b/iOS/Projects/Features/Record/Sources/Presentation/WorkoutPeerMatchingScene/ViewModel/WorkoutPeerRandomMatchingViewModel.swift index 341cd4f6..7fe532f0 100644 --- a/iOS/Projects/Features/Record/Sources/Presentation/WorkoutPeerMatchingScene/ViewModel/WorkoutPeerRandomMatchingViewModel.swift +++ b/iOS/Projects/Features/Record/Sources/Presentation/WorkoutPeerMatchingScene/ViewModel/WorkoutPeerRandomMatchingViewModel.swift @@ -176,7 +176,8 @@ extension WorkoutPeerRandomMatchingViewModel: WorkoutPeerRandomMatchingViewModel } private func cancelPeerRandomMatching() { - workoutPeerRandomMatchingUseCase.matchCancel() + let workoutTypeCode = workoutSetting.workoutType.typeCode + workoutPeerRandomMatchingUseCase.matchCancel(workoutTypeCode: workoutTypeCode) coordinating?.popPeerRandomMatchingViewController() }