Skip to content

Commit 7326d11

Browse files
authored
[NL-87] : 미비점 보안 (#62)
* [NL-87] : 로또 번호 받을 시 Home에서 갱신하도록 수정 * [NL-87] : Fortune Network Error 처리 + 다시 시도
1 parent 2ed8fc7 commit 7326d11

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

Common/Base/Sources/BaseViewController.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Combine
99
import SnapKit
1010
import UIKit
11+
import DesignSystem
1112

1213
open class BaseViewController: UIViewController {
1314

@@ -27,12 +28,17 @@ open class BaseViewController: UIViewController {
2728
$0.hidesWhenStopped = true
2829
}
2930

31+
private lazy var errorPopup = PopUp(style: .one).then {
32+
$0.isHidden = true
33+
}
34+
3035
public override var title: String? {
3136
get { navigationBar.title }
3237
set { navigationBar.title = newValue }
3338
}
3439
private var navigationAreaHeight: Constraint?
3540
public var cancellables = Set<AnyCancellable>()
41+
private var errorPopupCancellables = Set<AnyCancellable>()
3642

3743
open override func viewDidLoad() {
3844
super.viewDidLoad()
@@ -49,6 +55,12 @@ open class BaseViewController: UIViewController {
4955
activityIndicator.snp.makeConstraints { make in
5056
make.center.equalToSuperview()
5157
}
58+
59+
view.addSubview(errorPopup)
60+
errorPopup.snp.makeConstraints { make in
61+
make.centerX.centerY.equalToSuperview()
62+
make.leading.trailing.equalToSuperview().inset(24)
63+
}
5264
}
5365

5466
open override func viewDidLayoutSubviews() {
@@ -115,3 +127,23 @@ extension BaseViewController {
115127
activityIndicator.stopAnimating()
116128
}
117129
}
130+
131+
extension BaseViewController {
132+
public func showErrorPopup( action: @escaping () -> Void) {
133+
errorPopup.update(
134+
titile: "문제가 발생하였소", description: "잠시 후 다시 시도해 주시오.", actionButtonTitle: "확인")
135+
errorPopup.update(style: .one)
136+
errorPopup.isHidden = false
137+
138+
view.bringSubviewToFront(errorPopup)
139+
140+
errorPopupCancellables.removeAll()
141+
142+
errorPopup.actionButton.tapPublisher
143+
.sink { _ in
144+
action()
145+
self.errorPopup.isHidden = true
146+
}
147+
.store(in: &errorPopupCancellables)
148+
}
149+
}

Feature/Fortune/Sources/FortuneViewController.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ enum FortuneSection {
2121
public final class FortuneViewController: BaseViewController {
2222

2323
private let viewModel: FortuneViewModel
24-
private var store: Set<AnyCancellable> = Set<AnyCancellable>()
2524

2625
private lazy var ellips = UIImageView().then {
2726
$0.image = STImages.ellipseBackground.image.withRenderingMode(.alwaysTemplate)
@@ -184,7 +183,7 @@ extension FortuneViewController {
184183
guard let self else { return }
185184
self.collectionView.reloadData()
186185
}
187-
.store(in: &store)
186+
.store(in: &cancellables)
188187

189188
viewModel.output.isLoading
190189
.receive(on: DispatchQueue.main)
@@ -196,7 +195,15 @@ extension FortuneViewController {
196195
self.hideLoading()
197196
}
198197
}
199-
.store(in: &store)
198+
.store(in: &cancellables)
199+
200+
viewModel.output.showError
201+
.receive(on: DispatchQueue.main)
202+
.sink { [weak self] retryAction in
203+
guard let self else { return }
204+
self.showErrorPopup(action: retryAction)
205+
}
206+
.store(in: &cancellables)
200207
}
201208
}
202209

Feature/Fortune/Sources/FourtuneViewModel.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class FortuneViewModel {
1818
struct Output {
1919
let sections = CurrentValueSubject<[FortuneSection], Never>([])
2020
let isLoading = PassthroughSubject<Bool, Never>()
21+
let showError = PassthroughSubject<()->Void, Never>()
2122
}
2223

2324
@Injected private var fortuneService: FortuneService
@@ -53,7 +54,12 @@ extension FortuneViewModel {
5354
self.output.sections.send(sections)
5455
output.isLoading.send(false)
5556
} catch {
56-
// TODO: 에러 처리
57+
output.isLoading.send(false)
58+
output.showError.send { [weak self] in
59+
guard let self else { return }
60+
self.fetchUser()
61+
62+
}
5763
}
5864
}
5965
}

Feature/Home/Sources/Home/HomeViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public final class HomeViewModel {
3939
fetchUser()
4040
}
4141
.store(in: &cancellables)
42+
43+
RecommendationDetailService
44+
.getPublisher()
45+
.sink { [weak self] _ in
46+
guard let self = self else { return }
47+
fetchUser()
48+
}
49+
.store(in: &cancellables)
4250
}
4351

4452
func send(input: Input) {

Feature/Home/Sources/RecommendationDetail/RecommendationDetailService.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import Auth
99
import DIInjector
1010
import Foundation
1111
import NetworkCore
12+
import Combine
1213

1314
final class RecommendationDetailService {
1415

1516
@Injected private var userDataManager: UserDataManager
1617
@Injected private var networkProvider: NetworkProvider
18+
19+
private static var recommentPublisher = PassthroughSubject<Void, Never>()
20+
1721
private var username: String? { userDataManager.user?.name }
1822
var navigationTitle: String {
1923
guard let username else {
@@ -26,6 +30,7 @@ final class RecommendationDetailService {
2630
func createRecommendation() async throws -> [any RecommendationDetailCellModel] {
2731
let target = HomeTarget.CreateLottoRecommendation(userID: userDataManager.userID)
2832
let lottoRecommendation = try await networkProvider.request(target: target)
33+
RecommendationDetailService.recommentPublisher.send()
2934
return try makeSections(from: lottoRecommendation)
3035
}
3136

@@ -88,4 +93,9 @@ final class RecommendationDetailService {
8893
),
8994
]
9095
}
96+
97+
public static func getPublisher() -> AnyPublisher<Void, Never> {
98+
RecommendationDetailService.recommentPublisher
99+
.eraseToAnyPublisher()
100+
}
91101
}

0 commit comments

Comments
 (0)