Skip to content

Commit 4239784

Browse files
committed
fix: 제보하기 로직 수정
1 parent c5f69a3 commit 4239784

7 files changed

Lines changed: 38 additions & 24 deletions

File tree

Projects/DataSource/Sources/Repository/ReportRepository.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ReportRepository: ReportRepositoryProtocol {
1717
category: ReportType,
1818
location: LocationEntity?,
1919
photoURLs: [String]
20-
) async throws {
20+
) async throws -> Int? {
2121
let reportDTO = ReportDTO(
2222
reportId: nil,
2323
reportDate: nil,
@@ -33,7 +33,9 @@ final class ReportRepository: ReportRepositoryProtocol {
3333
)
3434

3535
let endpoint = ReportEndpoint.register(report: reportDTO)
36-
guard let response = try await networkService.request(endpoint: endpoint, type: EmptyResponseDTO.self) else { return }
36+
guard let id = try await networkService.request(endpoint: endpoint, type: Int.self) else { return nil }
37+
38+
return id
3739
}
3840

3941
func fetchReports() async throws -> [ReportEntity] {

Projects/Domain/Sources/Protocol/Repository/ReportRepositoryProtocol.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ public protocol ReportRepositoryProtocol {
1616
/// - category: 제보 카테고리
1717
/// - location: 제보 위치
1818
/// - photos: 업로드한 사진의 presigned urls
19+
/// - Returns: 제보 id
1920
func report(
2021
title: String,
2122
content: String?,
2223
category: ReportType,
2324
location: LocationEntity?,
2425
photoURLs: [String]
25-
) async throws
26+
) async throws -> Int?
2627

2728
/// 제보 목록을 조회합니다.
2829
/// - Returns: 조회된 제보 목록

Projects/Domain/Sources/Protocol/UseCase/ReportUseCaseProtocol.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@
88
import Foundation
99

1010
public protocol ReportUseCaseProtocol {
11+
/// 현위치를 가져옵니다.
12+
/// - Returns: 현재 위치
1113
func fetchCurrentLocation() async throws -> LocationEntity?
1214

15+
/// 제보 목록을 가져옵니다.
16+
/// - Returns: 제보 목록
1317
func fetchReports() async throws -> [ReportEntity]
1418

19+
/// 제보 단건의 상세 정보를 조회합니다.
20+
/// - Parameter reportId: 제보 id
21+
/// - Returns: 제보 상세 정보
1522
func fetchReport(reportId: Int) async throws -> ReportEntity?
1623

24+
/// 제보를 등록합니다.
25+
/// - Parameters:
26+
/// - title: 제보 제목
27+
/// - content: 제보 내용
28+
/// - category: 제보 카테고리 (교통, 상하수도 등)
29+
/// - location: 제보 위치
30+
/// - photos: 제보 사진 배열
31+
/// - Returns: 등록한 제보 id
1732
func report(
1833
title: String,
1934
content: String?,
2035
category: ReportType,
2136
location: LocationEntity?,
2237
photos: [Data]
23-
) async throws
38+
) async throws -> Int?
2439
}

Projects/Domain/Sources/UseCase/Report/ReportUseCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public final class ReportUseCase: ReportUseCaseProtocol {
4242
category: ReportType,
4343
location: LocationEntity?,
4444
photos: [Data]
45-
) async throws {
45+
) async throws -> Int? {
4646
let fileNames = (1...photos.count).map { "\($0).jpg" }
4747

4848
// TODO: - 사진 업로드 실패 시 에러 처리 필요
4949
guard
5050
let presignedDict = try await fileRepository.fetchPresignedURL(prefix: "report", fileNames: fileNames),
5151
presignedDict.count == photos.count
52-
else { return }
52+
else { return nil }
5353

5454
let presignedURLs = Array(presignedDict.values)
5555

@@ -67,7 +67,7 @@ public final class ReportUseCase: ReportUseCaseProtocol {
6767
.first ?? url
6868
}
6969

70-
try await reportRepository.report(
70+
return try await reportRepository.report(
7171
title: title,
7272
content: content,
7373
category: category,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ final class ReportLoadingViewController: UIViewController {
8080
}
8181

8282
extension ReportLoadingViewController: ReportRegistrationViewControllerDelegate {
83-
func reportRegistrationViewController(_ sender: ReportRegistrationViewController, completeRegistration: Bool) {
84-
if completeRegistration {
83+
func reportRegistrationViewController(_ sender: ReportRegistrationViewController, completeRegistration reportId: Int?) {
84+
if let reportId {
8585
let reportCompleteViewController = ReportCompleteViewController()
86+
// TODO: - reportCompleteViewController에 제보id 전달 (또는 생성한 제보 객체 자체를 넘기기. 논의 필요)
8687
self.navigationController?.pushViewController(reportCompleteViewController, animated: true)
8788
} else {
8889
navigationController?.popViewController(animated: true)

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import SnapKit
1212
import UIKit
1313

1414
protocol ReportRegistrationViewControllerDelegate: AnyObject {
15-
func reportRegistrationViewController(_ sender: ReportRegistrationViewController, completeRegistration: Bool)
15+
func reportRegistrationViewController(_ sender: ReportRegistrationViewController, completeRegistration reportId: Int?)
1616
}
1717

1818
final class ReportRegistrationViewController: BaseViewController<ReportRegistrationViewModel> {
@@ -417,13 +417,10 @@ final class ReportRegistrationViewController: BaseViewController<ReportRegistrat
417417

418418
viewModel.output.reportRegistrationCompletePublisher
419419
.receive(on: DispatchQueue.main)
420-
.sink { [weak self] isCompleted in
421-
guard
422-
let self,
423-
isCompleted
424-
else { return }
420+
.sink { [weak self] reportId in
421+
guard let self else { return }
425422

426-
delegate?.reportRegistrationViewController(self, completeRegistration: isCompleted)
423+
delegate?.reportRegistrationViewController(self, completeRegistration: reportId)
427424
}
428425
.store(in: &cancellables)
429426
}

Projects/Presentation/Sources/Report/ViewModel/ReportRegistrationViewModel.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class ReportRegistrationViewModel: ViewModel {
2828
let selectedPhotoPublisher: AnyPublisher<[PhotoItem], Never>
2929
let isReportValid: AnyPublisher<Bool, Never>
3030
let exceptionPublisher: AnyPublisher<String, Never>
31-
let reportRegistrationCompletePublisher: AnyPublisher<Bool, Never>
31+
let reportRegistrationCompletePublisher: AnyPublisher<Int?, Never>
3232
let maxPhotoCount: Int
3333
}
3434

@@ -40,7 +40,7 @@ final class ReportRegistrationViewModel: ViewModel {
4040
private let locationSubject = CurrentValueSubject<String?, Never>(nil)
4141
private let selectedPhotoSubject = CurrentValueSubject<[PhotoItem], Never>([])
4242
private let reportVerificationSubject = PassthroughSubject<Bool, Never>()
43-
private let reportRegistrationCompleteSubject = PassthroughSubject<Bool, Never>()
43+
private let reportRegistrationCompleteSubject = PassthroughSubject<Int?, Never>()
4444
private let exceptionSubject = PassthroughSubject<String, Never>()
4545
private let maxPhotoCount = 3
4646
private var location: LocationEntity? = nil
@@ -146,19 +146,17 @@ final class ReportRegistrationViewModel: ViewModel {
146146
Task {
147147
let minimumDuration: TimeInterval = 0.7
148148
let startTime = Date()
149-
let result: Bool
149+
let reportId: Int?
150150

151151
do {
152-
try await reportUseCase.report(
152+
reportId = try await reportUseCase.report(
153153
title: name,
154154
content: content,
155155
category: category,
156156
location: location,
157157
photos: selectedPhotos)
158-
result = true
159158
} catch {
160-
161-
result = false
159+
reportId = nil
162160
}
163161

164162
let elapsed = Date().timeIntervalSince(startTime)
@@ -169,7 +167,7 @@ final class ReportRegistrationViewModel: ViewModel {
169167
)
170168
}
171169

172-
reportRegistrationCompleteSubject.send(result)
170+
reportRegistrationCompleteSubject.send(reportId)
173171
}
174172
}
175173

0 commit comments

Comments
 (0)