Skip to content

Commit

Permalink
[Feat] sopt-makers#199 - 출석하기 Domain 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Apr 22, 2023
1 parent b303633 commit 77c6c6c
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/AttendanceUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import Combine

import Core
import Network

public protocol AttendanceUseCase {
func fetchLectureRound(lectureId: Int)
func postAttendance(lectureRoundId: Int, code: Int)
var lectureRound: PassthroughSubject<Int, Never> { get set }
func postAttendance(lectureRoundId: Int, code: String)
var attendSuccess: PassthroughSubject<Bool, Never> { get set }
var attendErrorMsg: PassthroughSubject<String, Never>{ get set }
}

public class DefaultAttendanceUseCase {

private let repository: AttendanceRepositoryInterface
private var cancelBag = CancelBag()

public var lectureRound = PassthroughSubject<Int, Never>()
public var attendSuccess = PassthroughSubject<Bool, Never>()
public var attendErrorMsg = PassthroughSubject<String, Never>()

public init(repository: AttendanceRepositoryInterface, cancelBag: CancelBag = CancelBag()) {
self.repository = repository
Expand All @@ -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)
})
Expand Down

0 comments on commit 77c6c6c

Please sign in to comment.