Skip to content

Commit 0310996

Browse files
committed
๐Ÿงฉ :: ์„œ๋ฒ„ ์ ๊ฒ€ ์•Œ๋ฆผ ์ถ”๊ฐ€
1 parent 56f7101 commit 0310996

File tree

9 files changed

+136
-2
lines changed

9 files changed

+136
-2
lines changed

โ€ŽProjects/Data/Sources/DI/DataSourceAssembly.swiftโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,9 @@ public final class DataSourceAssembly: Assembly {
7777
container.register(RemoteWinterInternDataSource.self) { resolver in
7878
RemoteWinterInternDataSourceImpl(keychain: self.keychain(resolver))
7979
}
80+
81+
container.register(RemoteSystemDataSource.self) { resolver in
82+
RemoteSystemDataSourceImpl(keychain: self.keychain(resolver))
83+
}
8084
}
8185
}

โ€ŽProjects/Data/Sources/DI/RepositoryAssembly.swiftโ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,11 @@ public final class RepositoryAssembly: Assembly {
9999
remoteWinterInternDataSource: resolver.resolve(RemoteWinterInternDataSource.self)!
100100
)
101101
}
102+
103+
container.register(SystemRepository.self) { resolver in
104+
SystemRepositoryImpl(
105+
remoteSystemDataSource: resolver.resolve(RemoteSystemDataSource.self)!
106+
)
107+
}
102108
}
103109
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Moya
2+
import Domain
3+
import AppNetwork
4+
5+
enum SystemAPI {
6+
case fetchServerStatus
7+
}
8+
9+
extension SystemAPI: JobisAPI {
10+
typealias ErrorType = UsersError
11+
12+
var domain: JobisDomain {
13+
.presignedURL
14+
}
15+
16+
var urlPath: String {
17+
switch self {
18+
case .fetchServerStatus:
19+
return ""
20+
}
21+
}
22+
23+
var method: Method {
24+
switch self {
25+
case .fetchServerStatus:
26+
return .get
27+
}
28+
}
29+
30+
var task: Task {
31+
switch self {
32+
default:
33+
return .requestPlain
34+
}
35+
}
36+
37+
var jwtTokenType: JwtTokenType {
38+
switch self {
39+
default:
40+
return .none
41+
}
42+
}
43+
44+
var errorMap: [Int: ErrorType]? {
45+
return nil
46+
}
47+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import RxSwift
2+
import Domain
3+
4+
protocol RemoteSystemDataSource {
5+
func fetchServerStatus() -> Completable
6+
}
7+
8+
final class RemoteSystemDataSourceImpl: RemoteBaseDataSource<SystemAPI>, RemoteSystemDataSource {
9+
func fetchServerStatus() -> Completable {
10+
request(.fetchServerStatus)
11+
.asCompletable()
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import RxSwift
2+
import Domain
3+
4+
struct SystemRepositoryImpl: SystemRepository {
5+
private let remoteSystemDataSource: any RemoteSystemDataSource
6+
7+
init(remoteSystemDataSource: any RemoteSystemDataSource) {
8+
self.remoteSystemDataSource = remoteSystemDataSource
9+
}
10+
11+
func fetchServerStatus() -> Completable {
12+
remoteSystemDataSource.fetchServerStatus()
13+
}
14+
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import RxSwift
2+
3+
public protocol SystemRepository {
4+
func fetchServerStatus() -> Completable
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import RxSwift
2+
3+
public struct FetchServerStatusUseCase {
4+
private let systemRepository: any SystemRepository
5+
6+
public init(systemRepository: any SystemRepository) {
7+
self.systemRepository = systemRepository
8+
}
9+
10+
public func execute() -> Completable {
11+
systemRepository.fetchServerStatus()
12+
}
13+
}

โ€ŽProjects/Presentation/Sources/Onboarding/OnboardingViewController.swiftโ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ public final class OnboardingViewController: BaseViewController<OnboardingViewMo
8888
}
8989
)
9090
}).disposed(by: disposeBag)
91+
92+
output.serverStatus.asObservable()
93+
.subscribe(onNext: {_ in
94+
AlertBuilder(viewController: self)
95+
.setTitle("ํ˜„์žฌ JOBIS ์„œ๋ฒ„๊ฐ€ ์ ๊ฒ€์ค‘์ด์—์š”")
96+
.setMessage("๋”์šฑ ์›ํ™œํ•œ ์„œ๋น„์Šค ์ด์šฉ์„ ์œ„ํ•ด\n๋…ธ๋ ฅ์ค‘์ด๋‹ˆ ์กฐ๊ธˆ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”!")
97+
.addActionConfirm("ํ™•์ธ")
98+
.setAlertType(.positive)
99+
.show()
100+
}).disposed(by: disposeBag)
91101
}
92102

93103
private func setNavigateButton() {

โ€ŽProjects/Presentation/Sources/Onboarding/OnboardingViewModel.swiftโ€Ž

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ import Utility
88
public final class OnboardingViewModel: BaseViewModel, Stepper {
99
public let steps = PublishRelay<Step>()
1010
private let disposeBag = DisposeBag()
11+
1112
private let reissueTokenUaseCase: ReissueTokenUaseCase
13+
private let fetchServerStatusUseCase: FetchServerStatusUseCase
1214

13-
init(reissueTokenUaseCase: ReissueTokenUaseCase) {
15+
init(
16+
reissueTokenUaseCase: ReissueTokenUaseCase,
17+
fetchServerStatusUseCase: FetchServerStatusUseCase
18+
) {
1419
self.reissueTokenUaseCase = reissueTokenUaseCase
20+
self.fetchServerStatusUseCase = fetchServerStatusUseCase
1521
}
1622

1723
public struct Input {
@@ -23,11 +29,13 @@ public final class OnboardingViewModel: BaseViewModel, Stepper {
2329
public struct Output {
2430
let animate: PublishRelay<Void>
2531
let showNavigationButton: PublishRelay<Void>
32+
let serverStatus: PublishRelay<Void>
2633
}
2734

2835
public func transform(_ input: Input) -> Output {
2936
let animate = PublishRelay<Void>()
3037
let showNavigationButton = PublishRelay<Void>()
38+
let serverStatus = PublishRelay<Void>()
3139

3240
input.navigateToSigninDidTap.asObservable()
3341
.avoidDuplication
@@ -55,9 +63,22 @@ public final class OnboardingViewModel: BaseViewModel, Stepper {
5563
.bind(to: steps)
5664
.disposed(by: disposeBag)
5765

66+
input.viewAppear.asObservable()
67+
.flatMap { [self] in
68+
return fetchServerStatusUseCase.execute()
69+
.catch {
70+
serverStatus.accept(())
71+
print($0.localizedDescription)
72+
return .never()
73+
}
74+
}
75+
.subscribe()
76+
.disposed(by: disposeBag)
77+
5878
return Output(
5979
animate: animate,
60-
showNavigationButton: showNavigationButton
80+
showNavigationButton: showNavigationButton,
81+
serverStatus: serverStatus
6182
)
6283
}
6384
}

0 commit comments

Comments
ย (0)