From 77c6c6c19d88cdb097ce2b27f6212cbdc7599fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=98=81=EC=9D=B8?= <0inn1220@gmail.com> Date: Sat, 22 Apr 2023 22:19:32 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#199=20-=20=EC=B6=9C=EC=84=9D=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20Domain=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/UseCase/AttendanceUseCase.swift | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift index 9d8f148b..af5977c7 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift @@ -9,12 +9,12 @@ import Combine import Core +import Network public protocol AttendanceUseCase { - func fetchLectureRound(lectureId: Int) - func postAttendance(lectureRoundId: Int, code: Int) - var lectureRound: PassthroughSubject { get set } + func postAttendance(lectureRoundId: Int, code: String) var attendSuccess: PassthroughSubject { get set } + var attendErrorMsg: PassthroughSubject{ get set } } public class DefaultAttendanceUseCase { @@ -22,8 +22,8 @@ public class DefaultAttendanceUseCase { private let repository: AttendanceRepositoryInterface private var cancelBag = CancelBag() - public var lectureRound = PassthroughSubject() public var attendSuccess = PassthroughSubject() + public var attendErrorMsg = PassthroughSubject() public init(repository: AttendanceRepositoryInterface, cancelBag: CancelBag = CancelBag()) { self.repository = repository @@ -32,30 +32,18 @@ public class DefaultAttendanceUseCase { } extension DefaultAttendanceUseCase: AttendanceUseCase { - public func fetchLectureRound(lectureId: Int) { - repository.fetchLectureRound(lectureId: lectureId) - .sink(receiveCompletion: { event in - switch event { - case .failure(let error): - print("failure: fetchLectureRound \(error)") - case .finished: - print("completion: fetchLectureRound \(event)") - } - }, receiveValue: { result in - self.lectureRound.send(result) - }) - .store(in: cancelBag) - } - public func postAttendance(lectureRoundId: Int, code: Int) { + public func postAttendance(lectureRoundId: Int, code: String) { repository.postAttendance(lectureRoundId: lectureRoundId, code: code) - .sink(receiveCompletion: { event in - switch event { - case .failure(let error): - print("failure: postAttendance \(error)") - case .finished: - print("completion: postAttendance \(event)") + .catch({ error in + if let error = error as? OPAPIError { + self.attendErrorMsg.send(error.errorDescription ?? "") } + + return Just(false) + }) + .sink(receiveCompletion: { event in + print("completion: postAttendance \(event)") }, receiveValue: { result in self.attendSuccess.send(result) })