Skip to content

Commit d8d72c6

Browse files
committed
Feat: 제보 기록 조회 네트워트 구성 요소 구현 (#T3-203)
1 parent ef1fed3 commit d8d72c6

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

Projects/DataSource/Sources/DTO/ReportDTO.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ struct ReportDTO: Decodable {
3535
address: reportLocation),
3636
photoUrls: reportImageUrls ?? [])
3737
}
38+
39+
func toReportEntity(date: String) throws -> ReportEntity {
40+
guard let reportId else { throw NetworkError.decodingError }
41+
return ReportEntity(
42+
id: reportId,
43+
title: reportTitle,
44+
date: date,
45+
type: ReportType(rawValue: reportCategory) ?? .transportation,
46+
progress: ReportProgress(rawValue: reportStatus) ?? .received,
47+
content: reportContent,
48+
location: LocationEntity(
49+
longitude: longitude,
50+
latitude: latitude,
51+
address: reportLocation),
52+
photoUrls: reportImageUrls ?? [])
53+
}
3854
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// ReportDictonaryDTO.swift
3+
// DataSource
4+
//
5+
// Created by 최정인 on 11/21/25.
6+
//
7+
8+
struct ReportDictonaryDTO: Decodable {
9+
let reportInfos: [String: [ReportDTO]]
10+
}

Projects/DataSource/Sources/Endpoint/ReportEndpoint.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,30 @@
66
//
77

88
enum ReportEndpoint {
9+
case fetchReports
910
case fetchReportDetail(reportId: Int)
1011
}
1112

1213
extension ReportEndpoint: Endpoint {
1314
var baseURL: String {
1415
switch self {
15-
case .fetchReportDetail:
16+
case .fetchReports, .fetchReportDetail:
1617
return AppProperties.baseURL + "/api/v2/reports"
1718
}
1819
}
1920

2021
var path: String {
2122
switch self {
23+
case .fetchReports:
24+
return baseURL
2225
case .fetchReportDetail(let reportId):
23-
"\(baseURL)/\(reportId)"
26+
return "\(baseURL)/\(reportId)"
2427
}
2528
}
2629

2730
var method: HTTPMethod {
2831
switch self {
29-
case .fetchReportDetail:
32+
case .fetchReports, .fetchReportDetail:
3033
.get
3134
}
3235
}

Projects/DataSource/Sources/Repository/ReportRepository.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,25 @@ final class ReportRepository: ReportRepositoryProtocol {
1414

1515
}
1616

17+
func fetchReports() async throws -> [ReportEntity] {
18+
let endpoint = ReportEndpoint.fetchReports
19+
guard let response = try await networkService.request(endpoint: endpoint, type: ReportDictonaryDTO.self)
20+
else { return [] }
21+
22+
var reportEntities: [ReportEntity] = []
23+
for (date, reports) in response.reportInfos {
24+
let reportHistories = reports.compactMap({ try? $0.toReportEntity(date: date) })
25+
reportEntities += reportHistories
26+
}
27+
28+
return reportEntities
29+
}
30+
1731
func fetchReportDetail(reportId: Int) async throws -> ReportEntity? {
1832
let endpoint = ReportEndpoint.fetchReportDetail(reportId: reportId)
19-
guard let response = try await networkService.request(endpoint: endpoint, type: ReportDTO.self) else { return nil }
33+
guard let response = try await networkService.request(endpoint: endpoint, type: ReportDTO.self)
34+
else { return nil }
35+
2036
return try response.toReportEntity()
2137
}
2238
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
public protocol ReportRepositoryProtocol {
99
func report(reportEntity: ReportEntity) async
1010

11+
/// 제보 목록을 조회합니다.
12+
/// - Returns: 조회된 제보 목록
13+
func fetchReports() async throws -> [ReportEntity]
14+
1115
/// 제보 상세 기록을 조회합니다.
1216
/// - Parameter reportId: 조회할 제보의 ID
1317
/// - Returns: 조회된 제보

0 commit comments

Comments
 (0)