Skip to content

Commit 71aac61

Browse files
committed
Feat: 제보 목록 조회 UseCase 및 Repository 메서드 구현
1 parent c472f16 commit 71aac61

10 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.threegap.bitnagil.data.report.datasource
22

33
import com.threegap.bitnagil.data.report.model.request.ReportRequestDto
4+
import com.threegap.bitnagil.data.report.model.response.ReportHistoriesPerDateDto
45

56
interface ReportDataSource {
67
suspend fun submitReport(reportRequestDto: ReportRequestDto): Result<Long>
8+
suspend fun getReports(): Result<ReportHistoriesPerDateDto>
79
}

data/src/main/java/com/threegap/bitnagil/data/report/datasourceImpl/ReportDataSourceImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.threegap.bitnagil.data.report.datasourceImpl
33
import com.threegap.bitnagil.data.common.safeApiCall
44
import com.threegap.bitnagil.data.report.datasource.ReportDataSource
55
import com.threegap.bitnagil.data.report.model.request.ReportRequestDto
6+
import com.threegap.bitnagil.data.report.model.response.ReportHistoriesPerDateDto
67
import com.threegap.bitnagil.data.report.service.ReportService
78
import javax.inject.Inject
89

@@ -12,4 +13,8 @@ class ReportDataSourceImpl @Inject constructor(
1213
override suspend fun submitReport(reportRequestDto: ReportRequestDto): Result<Long> {
1314
return safeApiCall { reportService.submitReport(reportRequestDto) }
1415
}
16+
17+
override suspend fun getReports(): Result<ReportHistoriesPerDateDto> {
18+
return safeApiCall { reportService.getReports() }
19+
}
1520
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.threegap.bitnagil.data.report.model.response
2+
3+
import com.threegap.bitnagil.domain.report.model.ReportItem
4+
import kotlinx.serialization.SerialName
5+
import kotlinx.serialization.Serializable
6+
import java.time.LocalDate
7+
8+
@Serializable
9+
data class ReportHistoriesPerDateDto(
10+
@SerialName("reportInfos")
11+
val reportInfos: Map<String, List<ReportItemDto>>,
12+
)
13+
14+
fun ReportHistoriesPerDateDto.toDomainMap(): Map<LocalDate, List<ReportItem>> =
15+
this.reportInfos
16+
.mapKeys { LocalDate.parse(it.key) }
17+
.mapValues { entry ->
18+
entry.value.map { it.toDomain() }
19+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.threegap.bitnagil.data.report.model.response
2+
3+
import com.threegap.bitnagil.domain.report.model.ReportCategory
4+
import com.threegap.bitnagil.domain.report.model.ReportItem
5+
import com.threegap.bitnagil.domain.report.model.ReportStatus
6+
import kotlinx.serialization.SerialName
7+
import kotlinx.serialization.Serializable
8+
9+
@Serializable
10+
data class ReportItemDto(
11+
@SerialName("reportId")
12+
val reportId: Int,
13+
@SerialName("reportStatus")
14+
val reportStatus: String,
15+
@SerialName("reportTitle")
16+
val reportTitle: String,
17+
@SerialName("reportCategory")
18+
val reportCategory: String,
19+
@SerialName("reportLocation")
20+
val reportLocation: String,
21+
@SerialName("reportImageUrl")
22+
val reportImageUrl: String,
23+
)
24+
25+
fun ReportItemDto.toDomain(): ReportItem =
26+
ReportItem(
27+
id = this.reportId,
28+
status = ReportStatus.fromString(this.reportStatus),
29+
title = this.reportTitle,
30+
category = ReportCategory.fromString(this.reportCategory),
31+
address = this.reportLocation,
32+
imageUrl = this.reportImageUrl,
33+
)

data/src/main/java/com/threegap/bitnagil/data/report/repositoryImpl/ReportRepositoryImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package com.threegap.bitnagil.data.report.repositoryImpl
22

33
import com.threegap.bitnagil.data.report.datasource.ReportDataSource
44
import com.threegap.bitnagil.data.report.model.request.toDto
5+
import com.threegap.bitnagil.data.report.model.response.toDomainMap
56
import com.threegap.bitnagil.domain.report.model.Report
7+
import com.threegap.bitnagil.domain.report.model.ReportItem
68
import com.threegap.bitnagil.domain.report.repository.ReportRepository
9+
import java.time.LocalDate
710
import javax.inject.Inject
811

912
class ReportRepositoryImpl @Inject constructor(
@@ -12,4 +15,8 @@ class ReportRepositoryImpl @Inject constructor(
1215
override suspend fun submitReport(report: Report): Result<Long> {
1316
return reportDataSource.submitReport(report.toDto())
1417
}
18+
19+
override suspend fun getReportHistories(): Result<Map<LocalDate, List<ReportItem>>> {
20+
return reportDataSource.getReports().map { it.toDomainMap() }
21+
}
1522
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.threegap.bitnagil.data.report.service
22

33
import com.threegap.bitnagil.data.report.model.request.ReportRequestDto
4+
import com.threegap.bitnagil.data.report.model.response.ReportHistoriesPerDateDto
45
import com.threegap.bitnagil.network.model.BaseResponse
56
import retrofit2.http.Body
7+
import retrofit2.http.GET
68
import retrofit2.http.POST
79

810
interface ReportService {
911
@POST("/api/v2/reports")
1012
suspend fun submitReport(
1113
@Body reportRequestDto: ReportRequestDto,
1214
): BaseResponse<Long>
15+
16+
@GET("/api/v2/reports")
17+
suspend fun getReports(): BaseResponse<ReportHistoriesPerDateDto>
1318
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.threegap.bitnagil.domain.report.model
2+
3+
data class ReportItem(
4+
val id: Int,
5+
val title: String,
6+
val category: ReportCategory,
7+
val status: ReportStatus,
8+
val imageUrl: String,
9+
val address: String,
10+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.threegap.bitnagil.domain.report.model
2+
3+
enum class ReportStatus {
4+
Pending,
5+
InProgress,
6+
Completed,
7+
;
8+
9+
companion object {
10+
fun fromString(value: String): ReportStatus {
11+
return when (value) {
12+
"PENDING" -> Pending
13+
"IN_PROGRESS" -> InProgress
14+
"COMPLETED" -> Completed
15+
else -> throw IllegalArgumentException("Invalid ReportStatus value: $value")
16+
}
17+
}
18+
19+
fun toString(value: ReportStatus): String {
20+
return when (value) {
21+
Pending -> "PENDING"
22+
InProgress -> "IN_PROGRESS"
23+
Completed -> "COMPLETED"
24+
}
25+
}
26+
}
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.threegap.bitnagil.domain.report.repository
22

33
import com.threegap.bitnagil.domain.report.model.Report
4+
import com.threegap.bitnagil.domain.report.model.ReportItem
5+
import java.time.LocalDate
46

57
interface ReportRepository {
68
suspend fun submitReport(report: Report): Result<Long>
9+
suspend fun getReportHistories(): Result<Map<LocalDate, List<ReportItem>>>
710
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.threegap.bitnagil.domain.report.usecase
2+
3+
import com.threegap.bitnagil.domain.report.model.ReportItem
4+
import com.threegap.bitnagil.domain.report.repository.ReportRepository
5+
import java.time.LocalDate
6+
import javax.inject.Inject
7+
8+
class GetReportHistoriesUseCase @Inject constructor(
9+
private val reportRepository: ReportRepository,
10+
) {
11+
suspend operator fun invoke(): Result<Map<LocalDate, List<ReportItem>>> {
12+
return reportRepository.getReportHistories()
13+
}
14+
}

0 commit comments

Comments
 (0)