Skip to content

Commit abe4b88

Browse files
committed
feat: 제보완료 VC 뷰 모델 추가
1 parent da2ae77 commit abe4b88

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

Projects/Presentation/Sources/Report/View/ReportCompleteViewController.swift

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
// Created by 최정인 on 11/19/25.
66
//
77

8+
import Combine
89
import SnapKit
910
import UIKit
1011

11-
final class ReportCompleteViewController: UIViewController {
12+
final class ReportCompleteViewController: BaseViewController<ReportDetailViewModel> {
1213
private enum Layout {
1314
static let horizontalMargin: CGFloat = 20
1415
static let completeImageViewTopSpacing: CGFloat = 78
@@ -65,15 +66,27 @@ final class ReportCompleteViewController: UIViewController {
6566
private let descriptionLabel = UILabel()
6667
private let photoStackView = UIStackView()
6768
private let confirmButton = PrimaryButton(buttonState: .default, buttonTitle: "확인")
69+
private let reportId: Int
70+
private var cancellables: Set<AnyCancellable> = []
71+
72+
init(viewModel: ReportDetailViewModel, reportId: Int) {
73+
self.reportId = reportId
74+
75+
super.init(viewModel: viewModel)
76+
}
77+
78+
required init?(coder: NSCoder) {
79+
fatalError("init(coder:) has not been implemented")
80+
}
6881

6982
override func viewDidLoad() {
7083
super.viewDidLoad()
7184
configureAttribute()
7285
configureLayout()
73-
fetchReport()
86+
viewModel.action(input: .fetchReportDetail(reportId: reportId))
7487
}
7588

76-
private func configureAttribute() {
89+
override func configureAttribute() {
7790
view.backgroundColor = .white
7891
scrollView.showsVerticalScrollIndicator = false
7992

@@ -105,7 +118,7 @@ final class ReportCompleteViewController: UIViewController {
105118
photoStackView.spacing = Layout.photoStackViewSpacing
106119
}
107120

108-
private func configureLayout() {
121+
override func configureLayout() {
109122
let safeArea = view.safeAreaLayoutGuide
110123

111124
view.addSubview(scrollView)
@@ -171,8 +184,30 @@ final class ReportCompleteViewController: UIViewController {
171184
}
172185
}
173186

174-
private func bind() {
175-
fetchReport()
187+
override func bind() {
188+
viewModel.output.reportDetailPublisher
189+
.receive(on: DispatchQueue.main)
190+
.sink(receiveValue: { [weak self] reportDetail in
191+
guard let reportDetail else { return }
192+
193+
self?.titleLabel.text = reportDetail.title
194+
self?.categoryLabel.text = reportDetail.category.name
195+
self?.locationLabel.text = reportDetail.location
196+
let descriptionText = reportDetail.description
197+
self?.descriptionLabel.attributedText = BitnagilFont(style: .body1, weight: .medium)
198+
.attributedString(text: descriptionText, alignment: .right)
199+
200+
for photoURL in reportDetail.photoUrls {
201+
guard
202+
let photoView = self?.makePhotoView(),
203+
let url = URL(string: photoURL)
204+
else { continue }
205+
206+
photoView.kf.setImage(with: url)
207+
self?.photoStackView.addArrangedSubview(photoView)
208+
}
209+
})
210+
.store(in: &cancellables)
176211
}
177212

178213
private func makeContentView(contentType: ReportCompleteContent) -> UIView {
@@ -223,25 +258,8 @@ final class ReportCompleteViewController: UIViewController {
223258
return contentContainerView
224259
}
225260

226-
// TODO: 추후 ViewModel로 옮기기
227-
private func fetchReport() {
228-
titleLabel.text = "가로등이 깜박거려요."
229-
categoryLabel.text = "교통시설"
230-
locationLabel.text = "서울특별시 강남구 삼성동"
231-
let descriptionText = "150자 내용 채우기"
232-
descriptionLabel.attributedText = BitnagilFont(style: .body1, weight: .medium)
233-
.attributedString(text: descriptionText, alignment: .right)
234-
235-
let photoView1 = makePhotoView()
236-
let photoView2 = makePhotoView()
237-
let photoView3 = makePhotoView()
238-
[photoView1, photoView2, photoView3].forEach {
239-
photoStackView.addArrangedSubview($0)
240-
}
241-
}
242-
243-
private func makePhotoView() -> UIView {
244-
let photoView = UIView()
261+
private func makePhotoView() -> UIImageView {
262+
let photoView = UIImageView()
245263
photoView.backgroundColor = BitnagilColor.gray30
246264
photoView.layer.masksToBounds = true
247265
photoView.layer.cornerRadius = 6

0 commit comments

Comments
 (0)