File tree Expand file tree Collapse file tree 5 files changed +53
-4
lines changed
Domain/Sources/Protocol/Repository Expand file tree Collapse file tree 5 files changed +53
-4
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 66//
77
88enum ReportEndpoint {
9+ case fetchReports
910 case fetchReportDetail( reportId: Int )
1011}
1112
1213extension 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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 88public 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: 조회된 제보
You can’t perform that action at this time.
0 commit comments