From 32a9d43a4f3d35464be44d2ab39327ce7263fa66 Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 17:30:50 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EB=B0=A5?= =?UTF-8?q?=EC=83=81=20=EC=A1=B0=ED=9A=8C=20api=20=EC=97=B0=EA=B2=B0=20?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/ReportDataSource.kt | 8 ++++++++ .../data/datasourceimpl/ReportDataSourceImpl.kt | 15 +++++++++++++++ .../data/dto/response/ResponseReportDto.kt | 16 ++++++++++++++++ .../data/mapper/toReportEntity.kt | 12 ++++++++++++ .../data/repositoryimpl/ReportRepositoryImpl.kt | 16 ++++++++++++++++ .../data/service/ReportApiService.kt | 11 +++++++++++ .../domain/entity/BabsangEntity.kt | 11 +++++++++++ .../domain/repository/ReportRepository.kt | 7 +++++++ .../presentation/babsang/screen/BabsangItem.kt | 6 +++--- .../babsang/screen/BabsangViewModel.kt | 12 ++++++------ .../presentation/profile/screen/LikeItem.kt | 6 +++--- .../presentation/profile/screen/LikeViewModel.kt | 12 ++++++------ .../presentation/report/screen/ReportItem.kt | 6 +++--- .../report/screen/ReportViewModel.kt | 12 ++++++------ 14 files changed, 123 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/BabsangEntity.kt create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt new file mode 100644 index 0000000..0ecd1da --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt @@ -0,0 +1,8 @@ +package com.hackathon.alddeul_babsang.data.datasource + +import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto + +interface ReportDataSource { + suspend fun getReports(): BaseResponse> +} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt new file mode 100644 index 0000000..d396af9 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt @@ -0,0 +1,15 @@ +package com.hackathon.alddeul_babsang.data.datasourceimpl + +import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto +import com.hackathon.alddeul_babsang.data.service.ReportApiService +import javax.inject.Inject + +class ReportDataSourceImpl @Inject constructor( + private val reportApiService: ReportApiService +) : ReportDataSource { + override suspend fun getReports(): BaseResponse> { + return reportApiService.getREPORTS() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt new file mode 100644 index 0000000..44b3b9c --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt @@ -0,0 +1,16 @@ +package com.hackathon.alddeul_babsang.data.dto.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ResponseReportDto( + @SerialName("id") val id: Long, + @SerialName("name") val name: String, + @SerialName("category") val category: String, + @SerialName("address") val address: String, + @SerialName("contact") val contact: String, + @SerialName("imageUrl") val imageUrl: String? = null, + @SerialName("favorite") val isFavorite: Boolean +) + diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt new file mode 100644 index 0000000..2b0bb97 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt @@ -0,0 +1,12 @@ +package com.hackathon.alddeul_babsang.data.mapper + +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity + +class toLikesEntity { +} + +fun ResponseReportDto.toLikesEntity() = ReportEntity( + id, imageUrl, name, category, address, contact, isFavorite +) + diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt new file mode 100644 index 0000000..0f7540a --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt @@ -0,0 +1,16 @@ +package com.hackathon.alddeul_babsang.data.repositoryimpl + +import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto +import com.hackathon.alddeul_babsang.domain.repository.ReportRepository +import javax.inject.Inject + +class ReportRepositoryImpl @Inject constructor( + private val reportDataSource: ReportDataSource +) : ReportRepository { + override suspend fun getReports(): Result> { + return runCatching { + reportDataSource.getReports().result ?: emptyList() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt new file mode 100644 index 0000000..4459343 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt @@ -0,0 +1,11 @@ +package com.hackathon.alddeul_babsang.data.service + +import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto +import com.sopt.data.service.ApiKeyStorage.REPORTS +import retrofit2.http.GET + +interface ReportApiService { + @GET("/$REPORTS") + suspend fun getREPORTS(): BaseResponse> +} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/BabsangEntity.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/BabsangEntity.kt new file mode 100644 index 0000000..da0c4b1 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/BabsangEntity.kt @@ -0,0 +1,11 @@ +package com.hackathon.alddeul_babsang.domain.entity + +data class BabsangEntity( + val id: Long, + val avatar: String? = null, + val name: String, + val codeName: String, + val address: String, + val phone: String, + val favorite: Boolean = false, +) \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt new file mode 100644 index 0000000..49bfca4 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt @@ -0,0 +1,7 @@ +package com.hackathon.alddeul_babsang.domain.repository + +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto + +interface ReportRepository { + suspend fun getReports(): Result> +} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt index 77fa839..b8dc1e6 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt @@ -37,13 +37,13 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity import com.hackathon.alddeul_babsang.presentation.profile.screen.LikeItem @Composable fun BabsangItem( onClick: () -> Unit = {}, - data: LikesEntity + data: ReportEntity ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -165,7 +165,7 @@ fun ReplaceImage2(codeName: String, imageUrl: String?) { fun BabsangListItemPreview() { AlddeulBabsangTheme { LikeItem( - data = LikesEntity( + data = ReportEntity( id = 1, avatar = null, name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt index 190ec35..26277f0 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt @@ -2,7 +2,7 @@ package com.hackathon.alddeul_babsang.presentation.babsang.screen import androidx.lifecycle.ViewModel import com.hackathon.alddeul_babsang.domain.entity.BabsangRecommendEntity -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @@ -46,7 +46,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() { ) ) val mockBabsang = listOf( - LikesEntity( + ReportEntity( id = 1, avatar = null, name = "송이네 밥상", @@ -55,7 +55,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() { phone = "02-210-0120", favorite = true ), - LikesEntity( + ReportEntity( id = 2, avatar = null, name = "송이네 일식", @@ -64,7 +64,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() { phone = "02-210-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 3, avatar = null, name = "송이네 한식", @@ -73,7 +73,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = null, name = "송이네 중식", @@ -82,7 +82,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4", name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt index 012fcb1..6e50062 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt @@ -37,12 +37,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity @Composable fun LikeItem( onClick: () -> Unit = {}, - data: LikesEntity + data: ReportEntity ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -164,7 +164,7 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) { fun LikeItemPreview() { AlddeulBabsangTheme { LikeItem( - data = LikesEntity( + data = ReportEntity( id = 1, avatar = null, name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt index 00be6eb..07fb5f5 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt @@ -2,14 +2,14 @@ package com.hackathon.alddeul_babsang.presentation.profile.screen import androidx.lifecycle.ViewModel -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @HiltViewModel class LikeViewModel @Inject constructor() : ViewModel() { val mockLikes = listOf( - LikesEntity( + ReportEntity( id = 1, avatar = null, name = "송이네 밥상", @@ -18,7 +18,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-210-0120", favorite = true ), - LikesEntity( + ReportEntity( id = 2, avatar = null, name = "송이네 일식", @@ -27,7 +27,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-210-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 3, avatar = null, name = "송이네 한식", @@ -36,7 +36,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = null, name = "송이네 중식", @@ -45,7 +45,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4", name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt index 63dcce3..a80071c 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt @@ -37,12 +37,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity @Composable fun ReportItem( onClick: () -> Unit = {}, - data: LikesEntity + data: ReportEntity ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -167,7 +167,7 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) { fun BabsangItemPreview() { AlddeulBabsangTheme { ReportItem( - data = LikesEntity( + data = ReportEntity( id = 1, avatar = null, name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt index 0f62a1b..0352186 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt @@ -1,14 +1,14 @@ package com.hackathon.alddeul_babsang.presentation.report.screen import androidx.lifecycle.ViewModel -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity +import com.hackathon.alddeul_babsang.domain.entity.ReportEntity import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @HiltViewModel class ReportViewModel @Inject constructor() : ViewModel() { val mockReportBabsang = listOf( - LikesEntity( + ReportEntity( id = 1, avatar = null, name = "송이네 밥상", @@ -17,7 +17,7 @@ class ReportViewModel @Inject constructor() : ViewModel() { phone = "02-210-0120", favorite = true ), - LikesEntity( + ReportEntity( id = 2, avatar = null, name = "송이네 일식", @@ -26,7 +26,7 @@ class ReportViewModel @Inject constructor() : ViewModel() { phone = "02-210-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 3, avatar = null, name = "송이네 한식", @@ -35,7 +35,7 @@ class ReportViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = null, name = "송이네 중식", @@ -44,7 +44,7 @@ class ReportViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - LikesEntity( + ReportEntity( id = 4, avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4", name = "송이네 밥상", From 90f6641a020276743ac13bb08f9ab39f1ef3a94a Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 17:31:07 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EB=B0=A5?= =?UTF-8?q?=EC=83=81=20=EC=A1=B0=ED=9A=8C=20api=20=EC=97=B0=EA=B2=B0=20?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alddeul_babsang/domain/entity/ReportEntity.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/ReportEntity.kt diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/ReportEntity.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/ReportEntity.kt new file mode 100644 index 0000000..40d8097 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/entity/ReportEntity.kt @@ -0,0 +1,11 @@ +package com.hackathon.alddeul_babsang.domain.entity + +data class ReportEntity( + val id: Long, + val avatar: String? = null, + val name: String, + val codeName: String, + val address: String, + val phone: String, + val favorite: Boolean = false, +) \ No newline at end of file From e4d259cd42094f63f9a2841f1cff443f7a5737eb Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 20:00:34 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EC=B0=A9?= =?UTF-8?q?=ED=95=9C=20=EB=B0=A5=EC=83=81=20=EC=A0=9C=EB=B3=B4=20api=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/di/DataSourceModule.kt | 12 +++ .../app/di/RepositoryModule.kt | 14 ++++ .../alddeul_babsang/app/di/ServiceModule.kt | 14 ++++ .../data/datasource/ReportDataSource.kt | 5 ++ .../datasourceimpl/ReportDataSourceImpl.kt | 8 +- .../data/dto/request/RequestReportWriteDto.kt | 16 ++++ .../data/dto/response/ResponseReportDto.kt | 2 +- .../{toReportEntity.kt => toLikesEntity.kt} | 0 .../repositoryimpl/ReportRepositoryImpl.kt | 28 +++++++ .../data/service/ReportApiService.kt | 11 ++- .../domain/repository/ReportRepository.kt | 16 +++- .../babsang/screen/BabsangItem.kt | 12 ++- .../babsang/screen/BabsangViewModel.kt | 48 ------------ .../presentation/profile/screen/LikeItem.kt | 5 +- .../profile/screen/LikeViewModel.kt | 11 +-- .../presentation/report/screen/ReportItem.kt | 18 ++--- .../report/screen/ReportScreen.kt | 75 ++++++++++++++++--- .../report/screen/ReportViewModel.kt | 59 ++++++++++++++- .../report/screen/ReportWriteScreen.kt | 49 ++++++++---- 19 files changed, 302 insertions(+), 101 deletions(-) create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportWriteDto.kt rename app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/{toReportEntity.kt => toLikesEntity.kt} (100%) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt index 1bc750e..f4898e5 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt @@ -2,9 +2,13 @@ package com.hackathon.alddeul_babsang.app.di import com.hackathon.alddeul_babsang.data.datasource.BabsangDataSource import com.hackathon.alddeul_babsang.data.datasource.ExampleDataSource +import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.datasource.ReportWriteDataSource import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource import com.hackathon.alddeul_babsang.data.datasourceimpl.BabsangDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.ExampleDataSourceImpl +import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportDataSourceImpl +import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportWriteDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.UserPreferencesDataSourceImpl import dagger.Binds import dagger.Module @@ -27,4 +31,12 @@ abstract class DataSourceModule { @Binds @Singleton abstract fun bindBabsangDataSource(babsangDataSourceImpl: BabsangDataSourceImpl): BabsangDataSource + + @Binds + @Singleton + abstract fun bindReportDataSource(reportDataSourceImpl: ReportDataSourceImpl): ReportDataSource + + @Binds + @Singleton + abstract fun bindReportWriteDataSource(reportWriteDataSourceImpl: ReportWriteDataSourceImpl): ReportWriteDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt index 0db5c38..c46bfad 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt @@ -1,10 +1,16 @@ package com.hackathon.alddeul_babsang.app.di +import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportDataSourceImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.BabsangRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.ExampleRepositoryImpl +import com.hackathon.alddeul_babsang.data.repositoryimpl.ReportRepositoryImpl +import com.hackathon.alddeul_babsang.data.repositoryimpl.ReportWriteRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.UserPreferencesRepositoryImpl import com.hackathon.alddeul_babsang.domain.repository.BabsangRepository import com.hackathon.alddeul_babsang.domain.repository.ExampleRepository +import com.hackathon.alddeul_babsang.domain.repository.ReportRepository +import com.hackathon.alddeul_babsang.domain.repository.ReportWriteRepository import com.hackathon.alddeul_babsang.domain.repository.UserPreferencesRepository import dagger.Binds import dagger.Module @@ -27,4 +33,12 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindBabsangRepository(babsangRepositoryImpl: BabsangRepositoryImpl): BabsangRepository + + @Binds + @Singleton + abstract fun bindReportRepository(reportDataSourceImpl: ReportRepositoryImpl): ReportRepository + + @Binds + @Singleton + abstract fun bindReportWriteRepository(reportWriteDataSourceImpl: ReportWriteRepositoryImpl): ReportWriteRepository } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt index 27583ee..a0d6f96 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt @@ -1,6 +1,8 @@ package com.hackathon.alddeul_babsang.app.di import com.hackathon.alddeul_babsang.data.service.BabsangApiService +import com.hackathon.alddeul_babsang.data.service.ReportApiService +import com.hackathon.alddeul_babsang.data.service.ReportWriteApiService import com.sopt.data.service.ExampleApiService import dagger.Module import dagger.Provides @@ -24,4 +26,16 @@ object ServiceModule { fun provideBabsangService( @AlddeulRetrofit retrofit: Retrofit ): BabsangApiService = retrofit.create(BabsangApiService::class.java) + + @Provides + @Singleton + fun provideReportService( + @AlddeulRetrofit retrofit: Retrofit + ): ReportApiService = retrofit.create(ReportApiService::class.java) + + @Provides + @Singleton + fun provideReportWriteService( + @AlddeulRetrofit retrofit: Retrofit + ): ReportWriteApiService = retrofit.create(ReportWriteApiService::class.java) } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt index 0ecd1da..f121ad6 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt @@ -1,8 +1,13 @@ package com.hackathon.alddeul_babsang.data.datasource import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportDataSource { suspend fun getReports(): BaseResponse> + + suspend fun postReportWrite( + requestReportWriteDto: RequestReportWriteDto + ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt index d396af9..c7db835 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt @@ -2,6 +2,7 @@ package com.hackathon.alddeul_babsang.data.datasourceimpl import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.data.service.ReportApiService import javax.inject.Inject @@ -10,6 +11,9 @@ class ReportDataSourceImpl @Inject constructor( private val reportApiService: ReportApiService ) : ReportDataSource { override suspend fun getReports(): BaseResponse> { - return reportApiService.getREPORTS() + return reportApiService.getReports() } -} \ No newline at end of file + + override suspend fun postReportWrite(requestReportWriteDto: RequestReportWriteDto): BaseResponse { + return reportApiService.postReportWrite(requestReportWriteDto) +}} \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportWriteDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportWriteDto.kt new file mode 100644 index 0000000..ebd076c --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportWriteDto.kt @@ -0,0 +1,16 @@ +package com.hackathon.alddeul_babsang.data.dto.request + +import kotlinx.serialization.Serializable + +@Serializable +data class RequestReportWriteDto ( + val name : String, + val category: String, + val address: String, + val contact: String, + val menuName1: String, + val menuPrice1: Int, + val menuName2: String, + val menuPrice2: Int, + val imageUrl: String? = null +) \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt index 44b3b9c..9ff2e93 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt @@ -11,6 +11,6 @@ data class ResponseReportDto( @SerialName("address") val address: String, @SerialName("contact") val contact: String, @SerialName("imageUrl") val imageUrl: String? = null, - @SerialName("favorite") val isFavorite: Boolean + @SerialName("favorite") val favorite: Boolean ) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt similarity index 100% rename from app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toReportEntity.kt rename to app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt index 0f7540a..73c6030 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.hackathon.alddeul_babsang.data.repositoryimpl import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.domain.repository.ReportRepository import javax.inject.Inject @@ -13,4 +14,31 @@ class ReportRepositoryImpl @Inject constructor( reportDataSource.getReports().result ?: emptyList() } } + + override suspend fun postReportWrite( + name: String, + category: String, + address: String, + contact: String, + menuName1: String, + menuPrice1: Int, + menuName2: String, + menuPrice2: Int, + imageUrl: String + ): Result { + return runCatching { + reportDataSource.postReportWrite( + requestReportWriteDto = RequestReportWriteDto( + name = name, + category = category, + address = address, + contact = contact, + menuName1 = menuName1, + menuPrice1 = menuPrice1, + menuName2 = menuName2, + menuPrice2 = menuPrice2 + ) + ).result ?: "" + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt index 4459343..9097c67 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt @@ -1,11 +1,20 @@ package com.hackathon.alddeul_babsang.data.service import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto +import com.sopt.data.service.ApiKeyStorage.POST import com.sopt.data.service.ApiKeyStorage.REPORTS +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST interface ReportApiService { @GET("/$REPORTS") - suspend fun getREPORTS(): BaseResponse> + suspend fun getReports(): BaseResponse> + + @POST("/$REPORTS/$POST") + suspend fun postReportWrite( + @Body requestReportWriteDto: RequestReportWriteDto + ): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt index 49bfca4..aa5ad18 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt @@ -4,4 +4,18 @@ import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportRepository { suspend fun getReports(): Result> -} \ No newline at end of file + + suspend fun postReportWrite( + name: String, + category: String, + address: String, + contact: String, + menuName1: String, + menuPrice1: Int, + menuName2: String, + menuPrice2: Int, + imageUrl: String, + ): Result + +} + diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt index fe9e5ff..cf9277c 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt @@ -38,8 +38,6 @@ import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold import com.hackathon.alddeul_babsang.data.dto.response.ResponseBabsangDto -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity -import com.hackathon.alddeul_babsang.presentation.profile.screen.LikeItem @Composable fun BabsangItem( @@ -165,14 +163,14 @@ fun ReplaceImage2(codeName: String, imageUrl: String?) { @Composable fun BabsangListItemPreview() { AlddeulBabsangTheme { - LikeItem( - data = LikesEntity( + BabsangItem( + data = ResponseBabsangDto( id = 1, - avatar = null, name = "송이네 밥상", - codeName = "경양식/일식", + category = "경양식/일식", address = "서울특별시 용산구 청파동 11", - phone = "02-210-0220", + contact = "02-210-0220", + imageUrl = null, favorite = true ) ) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt index 89b4f40..b5f053e 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.hackathon.alddeul_babsang.data.dto.response.ResponseBabsangDto import com.hackathon.alddeul_babsang.domain.entity.BabsangRecommendEntity -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity import com.hackathon.alddeul_babsang.domain.repository.BabsangRepository import com.hackathon.alddeul_babsang.util.UiState import dagger.hilt.android.lifecycle.HiltViewModel @@ -70,51 +69,4 @@ class BabsangViewModel @Inject constructor( address = "용산구", ) ) - val mockBabsang = listOf( - LikesEntity( - id = 1, - avatar = null, - name = "송이네 밥상", - codeName = "기타외식업", - address = "서울특별시 용산구 청파동 81", - phone = "02-210-0120", - favorite = true - ), - LikesEntity( - id = 2, - avatar = null, - name = "송이네 일식", - codeName = "경양식/일식", - address = "서울특별시 용산구 청파동 11", - phone = "02-210-0220", - favorite = true - ), - LikesEntity( - id = 3, - avatar = null, - name = "송이네 한식", - codeName = "한식", - address = "서울특별시 용산구 청파동 31", - phone = "02-223-0220", - favorite = true - ), - LikesEntity( - id = 4, - avatar = null, - name = "송이네 중식", - codeName = "중식", - address = "서울특별시 용산구 청파동 31", - phone = "02-223-0220", - favorite = true - ), - LikesEntity( - id = 4, - avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4", - name = "송이네 밥상", - codeName = "중식", - address = "서울특별시 용산구 청파동 31", - phone = "02-223-0220", - favorite = true - ) - ) } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt index 6e50062..1299a6d 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt @@ -37,12 +37,13 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold +import com.hackathon.alddeul_babsang.domain.entity.LikesEntity import com.hackathon.alddeul_babsang.domain.entity.ReportEntity @Composable fun LikeItem( onClick: () -> Unit = {}, - data: ReportEntity + data: LikesEntity ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -164,7 +165,7 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) { fun LikeItemPreview() { AlddeulBabsangTheme { LikeItem( - data = ReportEntity( + data = LikesEntity( id = 1, avatar = null, name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt index 07fb5f5..e13079c 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt @@ -2,6 +2,7 @@ package com.hackathon.alddeul_babsang.presentation.profile.screen import androidx.lifecycle.ViewModel +import com.hackathon.alddeul_babsang.domain.entity.LikesEntity import com.hackathon.alddeul_babsang.domain.entity.ReportEntity import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @@ -9,7 +10,7 @@ import javax.inject.Inject @HiltViewModel class LikeViewModel @Inject constructor() : ViewModel() { val mockLikes = listOf( - ReportEntity( + LikesEntity( id = 1, avatar = null, name = "송이네 밥상", @@ -18,7 +19,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-210-0120", favorite = true ), - ReportEntity( + LikesEntity( id = 2, avatar = null, name = "송이네 일식", @@ -27,7 +28,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-210-0220", favorite = true ), - ReportEntity( + LikesEntity( id = 3, avatar = null, name = "송이네 한식", @@ -36,7 +37,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - ReportEntity( + LikesEntity( id = 4, avatar = null, name = "송이네 중식", @@ -45,7 +46,7 @@ class LikeViewModel @Inject constructor() : ViewModel() { phone = "02-223-0220", favorite = true ), - ReportEntity( + LikesEntity( id = 4, avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4", name = "송이네 밥상", diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt index a80071c..b44d243 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportItem.kt @@ -37,12 +37,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold -import com.hackathon.alddeul_babsang.domain.entity.ReportEntity +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto @Composable fun ReportItem( onClick: () -> Unit = {}, - data: ReportEntity + data: ResponseReportDto ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -71,7 +71,7 @@ fun ReportItem( .clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)) ) { // AsyncImage 로드 - LoadImageWithPlaceholder(data.codeName, data.avatar) + LoadImageWithPlaceholder(data.category, data.imageUrl) Image( painter = painterResource(heartIconId), @@ -95,7 +95,7 @@ fun ReportItem( ) Spacer(modifier = Modifier.width(15.dp)) Text( - text = data.codeName, + text = data.category, style = body2Regular, color = Orange800, modifier = Modifier @@ -112,7 +112,7 @@ fun ReportItem( ) Spacer(modifier = Modifier.height(7.dp)) Text( - text = data.phone, + text = data.contact, style = body4Regular, color = Gray300, modifier = Modifier.padding(start = 20.dp) @@ -167,13 +167,13 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) { fun BabsangItemPreview() { AlddeulBabsangTheme { ReportItem( - data = ReportEntity( + data = ResponseReportDto( id = 1, - avatar = null, + imageUrl = null, name = "송이네 밥상", - codeName = "경양식/일식", + category = "경양식/일식", address = "서울특별시 용산구 청파동 11", - phone = "02-210-0220", + contact = "02-210-0220", favorite = true ) ) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt index aeda380..2a6e383 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt @@ -3,42 +3,54 @@ package com.hackathon.alddeul_babsang.presentation.report.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.hackathon.alddeul_babsang.R +import com.hackathon.alddeul_babsang.core_ui.component.LoadingCircleIndicator import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme import com.hackathon.alddeul_babsang.core_ui.theme.Blue import com.hackathon.alddeul_babsang.core_ui.theme.Gray900 import com.hackathon.alddeul_babsang.core_ui.theme.Orange900 import com.hackathon.alddeul_babsang.core_ui.theme.White import com.hackathon.alddeul_babsang.core_ui.theme.head6Bold +import com.hackathon.alddeul_babsang.core_ui.theme.head6Semi import com.hackathon.alddeul_babsang.core_ui.theme.head7Bold import com.hackathon.alddeul_babsang.core_ui.theme.title4Bold import com.hackathon.alddeul_babsang.presentation.report.navigation.ReportNavigator +import com.hackathon.alddeul_babsang.util.UiState @Composable fun ReportRoute( navigator: ReportNavigator ) { - val babsangListViewModel: ReportViewModel = hiltViewModel() + val reportViewModel: ReportViewModel = hiltViewModel() val systemUiController = rememberSystemUiController() + LaunchedEffect(Unit) { + reportViewModel.getReport() + } + SideEffect { systemUiController.setStatusBarColor( color = White @@ -51,7 +63,7 @@ fun ReportRoute( navigator.navigateReportWrite() }, - babsangListViewModel = babsangListViewModel + reportViewModel = reportViewModel ) } @@ -60,8 +72,11 @@ fun ReportRoute( fun ReportScreen( onItemClick: (Long) -> Unit = {}, onReportWriteClick: () -> Unit = {}, - babsangListViewModel: ReportViewModel + reportViewModel: ReportViewModel ) { + + val getReportState by reportViewModel.getReportState.collectAsStateWithLifecycle(UiState.Empty) + Scaffold( floatingActionButton = { Button( @@ -108,12 +123,51 @@ fun ReportScreen( style = head7Bold, color = Gray900 ) } - items(babsangListViewModel.mockReportBabsang) { item -> - ReportItem( - onClick = { onItemClick(item.id) }, - data = item - ) + + when (getReportState) { + is UiState.Loading -> { + item { + LoadingCircleIndicator() + } } + + is UiState.Success -> { + val data = (getReportState as UiState.Success).data + if (data.isEmpty()) { + item { + Text( + text = "밥상 데이터가 없어요", + style = head6Semi, + color = Orange900, + modifier = Modifier.padding(vertical = 20.dp) + ) + } + } else { + itemsIndexed(data) { index, item -> + ReportItem( + onClick = { onItemClick(item.id) }, + data = item + ) + if (index != data.size - 1) { + Spacer(modifier = Modifier.height(16.dp)) + } + } + } + } + + is UiState.Failure -> { + item { + Text( + text = (getReportState as UiState.Failure).msg, + style = head6Semi, + color = Orange900, + modifier = Modifier.padding(vertical = 20.dp) + ) + } + } + + else -> {} + } } } } @@ -122,12 +176,11 @@ fun ReportScreen( @Preview @Composable fun ReportScreenPreview() { - val babsangListViewModel: ReportViewModel = hiltViewModel() AlddeulBabsangTheme { ReportScreen( onReportWriteClick = { }, - babsangListViewModel = babsangListViewModel + reportViewModel = hiltViewModel() ) } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt index 0352186..b2048da 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt @@ -1,12 +1,69 @@ package com.hackathon.alddeul_babsang.presentation.report.screen import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.domain.entity.ReportEntity +import com.hackathon.alddeul_babsang.domain.repository.ReportRepository +import com.hackathon.alddeul_babsang.util.UiState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch import javax.inject.Inject + @HiltViewModel -class ReportViewModel @Inject constructor() : ViewModel() { +class ReportViewModel @Inject constructor( + private val reportRepository: ReportRepository +) : ViewModel() { + private val _getReportState = + MutableStateFlow>>(UiState.Empty) + val getReportState: StateFlow>> = _getReportState + + private val _postReportWriteState = + MutableStateFlow>(UiState.Empty) + val postReportWriteState: StateFlow> = _postReportWriteState + + + fun getReport() = viewModelScope.launch { + _getReportState.emit(UiState.Loading) + reportRepository.getReports().fold( + onSuccess = { + _getReportState.emit(UiState.Success(it)) + }, + onFailure = { + _getReportState.emit(UiState.Failure(it.message.toString())) + } + ) + } + + fun postReportWrite( + name: String, + category: String, + address: String, + contact: String, + menuName1: String, + menuPrice1: Int, + menuName2: String, + menuPrice2: Int, + imageUrl: String + ) = viewModelScope.launch { + _postReportWriteState.emit(UiState.Loading) + reportRepository.postReportWrite( + name, category, address, contact, menuName1, menuPrice1, menuName2, menuPrice2, imageUrl + ).fold( + onSuccess = { + _postReportWriteState.emit(UiState.Success(it)) + }, + onFailure = { + _postReportWriteState.emit(UiState.Failure(it.message.toString())) + } + ) + } + + + val mockReportBabsang = listOf( ReportEntity( id = 1, diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportWriteScreen.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportWriteScreen.kt index c78e54a..bb016c8 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportWriteScreen.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportWriteScreen.kt @@ -43,14 +43,14 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import coil.compose.rememberAsyncImagePainter import com.hackathon.alddeul_babsang.R import com.hackathon.alddeul_babsang.core_ui.component.AlddeulButton import com.hackathon.alddeul_babsang.core_ui.component.AlddeulHeader import com.hackathon.alddeul_babsang.core_ui.component.ReportWriteArea -import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme import com.hackathon.alddeul_babsang.core_ui.theme.Gray100 import com.hackathon.alddeul_babsang.core_ui.theme.Gray600 import com.hackathon.alddeul_babsang.core_ui.theme.Gray900 @@ -59,15 +59,31 @@ import com.hackathon.alddeul_babsang.core_ui.theme.White import com.hackathon.alddeul_babsang.core_ui.theme.body2Semi import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold import com.hackathon.alddeul_babsang.presentation.report.navigation.ReportNavigator +import com.hackathon.alddeul_babsang.util.UiState import com.hackathon.alddeul_babsang.util.toast +import timber.log.Timber @Composable fun ReportWriteRoute( navigator: ReportNavigator ) { + val reportViewModel: ReportViewModel = hiltViewModel() + val postReportWriteState by reportViewModel.postReportWriteState.collectAsStateWithLifecycle( + UiState.Empty + ) + + when(postReportWriteState) { + is UiState.Success -> { + navigator.navigateBack() + } + is UiState.Failure -> { + Timber.e((postReportWriteState as UiState.Failure).msg) + } + else -> {} + } ReportWriteScreen( onBackClick = { navigator.navigateBack() }, - onButtonClick = { navigator.navigateBack() } + reportViewModel = reportViewModel ) } @@ -75,7 +91,7 @@ fun ReportWriteRoute( @Composable fun ReportWriteScreen( onBackClick: () -> Unit = {}, - onButtonClick: () -> Unit = {} + reportViewModel: ReportViewModel ) { var imageUri by remember { mutableStateOf(null) } val galleryLauncher = rememberLauncherForActivityResult( @@ -226,19 +242,26 @@ fun ReportWriteScreen( Spacer(modifier = Modifier.height(110.dp)) AlddeulButton(text = R.string.btn_report_complete) { if (name.isNotEmpty() && address.isNotEmpty() && phone.isNotEmpty() && menu1.isNotEmpty() && menu1price.isNotEmpty()) { - onButtonClick() + reportViewModel.postReportWrite( + name = name, + category = when(selectedCategory){ + 0 -> "KOREAN" + 1 -> "CHINESE" + 2 -> "WESTERN_JAPANESE" + else -> "OTHER" + }, + address = address, + contact = phone, + menuName1 = menu1, + menuPrice1 = menu1price.toInt(), + menuName2 = menu2, + menuPrice2 = menu2price.toInt(), + imageUrl = "" + ) } else { context.toast(context.getString(R.string.toast_report_failure)) } } } } -} - -@Preview(showBackground = true) -@Composable -fun ReportWriteScreenPreview() { - AlddeulBabsangTheme { - ReportWriteScreen() - } } \ No newline at end of file From 838d59130b2576958ab2d8d2f955c25a0902944c Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 20:34:15 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EC=B0=A9?= =?UTF-8?q?=ED=95=9C=20=EB=B0=A5=EC=83=81=20=EC=A1=B0=ED=9A=8C=20userid=20?= =?UTF-8?q?api=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alddeul_babsang/app/di/DataSourceModule.kt | 8 +++----- .../alddeul_babsang/app/di/RepositoryModule.kt | 10 +++------- .../hackathon/alddeul_babsang/app/di/ServiceModule.kt | 3 +-- .../data/datasource/ReportDataSource.kt | 5 ++++- .../data/datasourceimpl/ReportDataSourceImpl.kt | 5 +++-- .../data/dto/request/RequestReportDto.kt | 7 +++++++ .../data/repositoryimpl/ReportRepositoryImpl.kt | 11 +++++++++-- .../alddeul_babsang/data/service/ReportApiService.kt | 6 +++++- .../domain/repository/ReportRepository.kt | 4 +++- .../presentation/report/screen/ReportViewModel.kt | 6 ++++-- 10 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportDto.kt diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt index b54be2e..fc1691a 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt @@ -3,16 +3,14 @@ package com.hackathon.alddeul_babsang.app.di import com.hackathon.alddeul_babsang.data.datasource.BabsangDataSource import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource import com.hackathon.alddeul_babsang.data.datasource.ExampleDataSource -import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource -import com.hackathon.alddeul_babsang.data.datasource.ReportWriteDataSource import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource +import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource import com.hackathon.alddeul_babsang.data.datasourceimpl.BabsangDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.DetailDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.ExampleDataSourceImpl -import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportDataSourceImpl -import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportWriteDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.ProfileDataSourceImpl +import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportDataSourceImpl import com.hackathon.alddeul_babsang.data.datasourceimpl.UserPreferencesDataSourceImpl import dagger.Binds import dagger.Module @@ -50,5 +48,5 @@ abstract class DataSourceModule { @Binds @Singleton - abstract fun bindReportWriteDataSource(reportWriteDataSourceImpl: ReportWriteDataSourceImpl): ReportWriteDataSource + abstract fun bindReportWriteDataSource(reportWriteDataSourceImpl: ReportDataSourceImpl): ReportDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt index 96b2279..ee5f3ec 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt @@ -1,20 +1,16 @@ package com.hackathon.alddeul_babsang.app.di -import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource -import com.hackathon.alddeul_babsang.data.datasourceimpl.ReportDataSourceImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.BabsangRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.DetailRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.ExampleRepositoryImpl -import com.hackathon.alddeul_babsang.data.repositoryimpl.ReportRepositoryImpl -import com.hackathon.alddeul_babsang.data.repositoryimpl.ReportWriteRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.ProfileRepositoryImpl +import com.hackathon.alddeul_babsang.data.repositoryimpl.ReportRepositoryImpl import com.hackathon.alddeul_babsang.data.repositoryimpl.UserPreferencesRepositoryImpl import com.hackathon.alddeul_babsang.domain.repository.BabsangRepository import com.hackathon.alddeul_babsang.domain.repository.DetailRepository import com.hackathon.alddeul_babsang.domain.repository.ExampleRepository -import com.hackathon.alddeul_babsang.domain.repository.ReportRepository -import com.hackathon.alddeul_babsang.domain.repository.ReportWriteRepository import com.hackathon.alddeul_babsang.domain.repository.ProfileRepository +import com.hackathon.alddeul_babsang.domain.repository.ReportRepository import com.hackathon.alddeul_babsang.domain.repository.UserPreferencesRepository import dagger.Binds import dagger.Module @@ -52,5 +48,5 @@ abstract class RepositoryModule { @Binds @Singleton - abstract fun bindReportWriteRepository(reportWriteDataSourceImpl: ReportWriteRepositoryImpl): ReportWriteRepository + abstract fun bindReportWriteRepository(reportWriteDataSourceImpl: ReportRepositoryImpl): ReportRepository } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt index 14feba9..65ce540 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt @@ -2,7 +2,6 @@ package com.hackathon.alddeul_babsang.app.di import com.hackathon.alddeul_babsang.data.service.BabsangApiService import com.hackathon.alddeul_babsang.data.service.ReportApiService -import com.hackathon.alddeul_babsang.data.service.ReportWriteApiService import com.hackathon.alddeul_babsang.data.service.DetailApiService import com.hackathon.alddeul_babsang.data.service.ProfileApiService import com.sopt.data.service.ExampleApiService @@ -51,5 +50,5 @@ object ServiceModule { @Singleton fun provideReportWriteService( @AlddeulRetrofit retrofit: Retrofit - ): ReportWriteApiService = retrofit.create(ReportWriteApiService::class.java) + ): ReportApiService = retrofit.create(ReportApiService::class.java) } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt index f121ad6..b6f99fc 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt @@ -1,11 +1,14 @@ package com.hackathon.alddeul_babsang.data.datasource import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportDataSource { - suspend fun getReports(): BaseResponse> + suspend fun getReports( + requestReportDto: RequestReportDto + ): BaseResponse> suspend fun postReportWrite( requestReportWriteDto: RequestReportWriteDto diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt index c7db835..d31f452 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt @@ -2,6 +2,7 @@ package com.hackathon.alddeul_babsang.data.datasourceimpl import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.data.service.ReportApiService @@ -10,8 +11,8 @@ import javax.inject.Inject class ReportDataSourceImpl @Inject constructor( private val reportApiService: ReportApiService ) : ReportDataSource { - override suspend fun getReports(): BaseResponse> { - return reportApiService.getReports() + override suspend fun getReports(requestReportDto: RequestReportDto): BaseResponse> { + return reportApiService.getReports(requestReportDto) } override suspend fun postReportWrite(requestReportWriteDto: RequestReportWriteDto): BaseResponse { diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportDto.kt new file mode 100644 index 0000000..02aabb0 --- /dev/null +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestReportDto.kt @@ -0,0 +1,7 @@ +package com.hackathon.alddeul_babsang.data.dto.request + +import kotlinx.serialization.SerialName + +class RequestReportDto ( + @SerialName("userId") val userId: Long +) \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt index 73c6030..1782a81 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.hackathon.alddeul_babsang.data.repositoryimpl import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.domain.repository.ReportRepository @@ -9,9 +10,15 @@ import javax.inject.Inject class ReportRepositoryImpl @Inject constructor( private val reportDataSource: ReportDataSource ) : ReportRepository { - override suspend fun getReports(): Result> { + override suspend fun getReports( + userId: Long + ): Result> { return runCatching { - reportDataSource.getReports().result ?: emptyList() + reportDataSource.getReports( + requestReportDto = RequestReportDto( + userId = userId + ) + ).result ?: emptyList() } } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt index 9097c67..fcd9de1 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt @@ -1,6 +1,7 @@ package com.hackathon.alddeul_babsang.data.service import com.hackathon.alddeul_babsang.data.dto.BaseResponse +import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.sopt.data.service.ApiKeyStorage.POST @@ -11,10 +12,13 @@ import retrofit2.http.POST interface ReportApiService { @GET("/$REPORTS") - suspend fun getReports(): BaseResponse> + suspend fun getReports( + @Body requestReportDto: RequestReportDto + ): BaseResponse> @POST("/$REPORTS/$POST") suspend fun postReportWrite( @Body requestReportWriteDto: RequestReportWriteDto ): BaseResponse + } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt index aa5ad18..7da9690 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt @@ -3,7 +3,9 @@ package com.hackathon.alddeul_babsang.domain.repository import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportRepository { - suspend fun getReports(): Result> + suspend fun getReports( + userId: Long + ): Result> suspend fun postReportWrite( name: String, diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt index b2048da..7142d91 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt @@ -26,9 +26,11 @@ class ReportViewModel @Inject constructor( val postReportWriteState: StateFlow> = _postReportWriteState - fun getReport() = viewModelScope.launch { + fun getReport( + userId : Long = 1 + ) = viewModelScope.launch { _getReportState.emit(UiState.Loading) - reportRepository.getReports().fold( + reportRepository.getReports(userId).fold( onSuccess = { _getReportState.emit(UiState.Success(it)) }, From f8add2c7a49caf25de27d65ae22acd12323cc5b1 Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 21:32:22 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EC=B0=A9?= =?UTF-8?q?=ED=95=9C=20=EB=B0=A5=EC=83=81=20=EC=A1=B0=ED=9A=8C=20&=20?= =?UTF-8?q?=EC=A0=9C=EB=B3=B4=20&=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alddeul_babsang/app/di/ServiceModule.kt | 6 +---- .../data/datasource/ReportDataSource.kt | 2 +- .../datasourceimpl/ReportDataSourceImpl.kt | 4 ++-- .../data/dto/response/ResponseReportDto.kt | 2 +- .../repositoryimpl/ReportRepositoryImpl.kt | 4 ++-- .../data/service/ReportApiService.kt | 5 ++-- .../domain/repository/ReportRepository.kt | 2 +- .../babsang/screen/BabsangItem.kt | 4 ---- .../presentation/profile/screen/LikeItem.kt | 8 +++---- .../presentation/profile/screen/LikeScreen.kt | 16 ++++++++++++- .../profile/screen/LikeViewModel.kt | 23 +++++++++++++++++++ .../report/screen/ReportScreen.kt | 2 +- .../report/screen/ReportViewModel.kt | 4 ++-- 13 files changed, 54 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt index 5898581..8b43625 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/ServiceModule.kt @@ -53,9 +53,5 @@ object ServiceModule { @AlddeulRetrofit retrofit: Retrofit ): ReportApiService = retrofit.create(ReportApiService::class.java) - @Provides - @Singleton - fun provideReportWriteService( - @AlddeulRetrofit retrofit: Retrofit - ): ReportApiService = retrofit.create(ReportApiService::class.java) + } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt index b6f99fc..849c62f 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt @@ -6,7 +6,7 @@ import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportDataSource { - suspend fun getReports( + suspend fun postReports( requestReportDto: RequestReportDto ): BaseResponse> diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt index d31f452..a99e8f8 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt @@ -11,8 +11,8 @@ import javax.inject.Inject class ReportDataSourceImpl @Inject constructor( private val reportApiService: ReportApiService ) : ReportDataSource { - override suspend fun getReports(requestReportDto: RequestReportDto): BaseResponse> { - return reportApiService.getReports(requestReportDto) + override suspend fun postReports(requestReportDto: RequestReportDto): BaseResponse> { + return reportApiService.postReports(requestReportDto) } override suspend fun postReportWrite(requestReportWriteDto: RequestReportWriteDto): BaseResponse { diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt index 9ff2e93..c455b69 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReportDto.kt @@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class ResponseReportDto( - @SerialName("id") val id: Long, + @SerialName("storeId") val id: Long, @SerialName("name") val name: String, @SerialName("category") val category: String, @SerialName("address") val address: String, diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt index 1782a81..ea3c9bb 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt @@ -10,11 +10,11 @@ import javax.inject.Inject class ReportRepositoryImpl @Inject constructor( private val reportDataSource: ReportDataSource ) : ReportRepository { - override suspend fun getReports( + override suspend fun postReports( userId: Long ): Result> { return runCatching { - reportDataSource.getReports( + reportDataSource.postReports( requestReportDto = RequestReportDto( userId = userId ) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt index fcd9de1..b4d5468 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt @@ -7,12 +7,11 @@ import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.sopt.data.service.ApiKeyStorage.POST import com.sopt.data.service.ApiKeyStorage.REPORTS import retrofit2.http.Body -import retrofit2.http.GET import retrofit2.http.POST interface ReportApiService { - @GET("/$REPORTS") - suspend fun getReports( + @POST("/$REPORTS") + suspend fun postReports( @Body requestReportDto: RequestReportDto ): BaseResponse> diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt index 7da9690..d811323 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt @@ -3,7 +3,7 @@ package com.hackathon.alddeul_babsang.domain.repository import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportRepository { - suspend fun getReports( + suspend fun postReports( userId: Long ): Result> diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt index bac5a52..2cea722 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/babsang/screen/BabsangItem.kt @@ -25,11 +25,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import com.hackathon.alddeul_babsang.R -import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme import com.hackathon.alddeul_babsang.core_ui.theme.Gray300 import com.hackathon.alddeul_babsang.core_ui.theme.Orange700 import com.hackathon.alddeul_babsang.core_ui.theme.Orange800 @@ -38,8 +36,6 @@ import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold import com.hackathon.alddeul_babsang.data.dto.response.ResponseBabsangDto -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity -import com.hackathon.alddeul_babsang.presentation.profile.screen.LikeItem @Composable fun BabsangItem( diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt index ee6f21a..9e2e712 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeItem.kt @@ -25,11 +25,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import com.hackathon.alddeul_babsang.R -import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme import com.hackathon.alddeul_babsang.core_ui.theme.Gray300 import com.hackathon.alddeul_babsang.core_ui.theme.Orange700 import com.hackathon.alddeul_babsang.core_ui.theme.Orange800 @@ -38,13 +36,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold import com.hackathon.alddeul_babsang.data.dto.response.FavoriteRestaurantDto -import com.hackathon.alddeul_babsang.domain.entity.LikesEntity -import com.hackathon.alddeul_babsang.domain.entity.ReportEntity @Composable fun LikeItem( onClick: () -> Unit = {}, - data: FavoriteRestaurantDto + data: FavoriteRestaurantDto, + likeViewModel: LikeViewModel ) { var isFavorite by remember { mutableStateOf(data.favorite) } @@ -82,6 +79,7 @@ fun LikeItem( .clickable { // 클릭 시 좋아요 상태를 토글 isFavorite = !isFavorite + likeViewModel.postLike(storeId = data.restaurantId) } ) } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeScreen.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeScreen.kt index fc1f23c..a27908b 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeScreen.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeScreen.kt @@ -39,6 +39,7 @@ import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold import com.hackathon.alddeul_babsang.core_ui.theme.head6Semi import com.hackathon.alddeul_babsang.presentation.profile.navigation.ProfileNavigator import com.hackathon.alddeul_babsang.util.UiState +import timber.log.Timber @Composable fun LikeRoute( @@ -48,12 +49,24 @@ fun LikeRoute( val systemUiController = rememberSystemUiController() val likeViewModel: LikeViewModel = hiltViewModel() + val postLikeState by likeViewModel.postLikeState.collectAsStateWithLifecycle(UiState.Empty) + SideEffect { systemUiController.setStatusBarColor( color = White ) } + when(postLikeState) { + is UiState.Success -> { + navigator.navigateBack() + } + is UiState.Failure -> { + Timber.e((postLikeState as UiState.Failure).msg) + } + else -> {} + } + LaunchedEffect(Unit) { likeViewModel.getLikes() } @@ -127,7 +140,8 @@ fun LikeScreen( items((getLikesState as UiState.Success).data) { item -> LikeItem( onClick = { onItemClick(item.restaurantId) }, - data = item + data = item, + likeViewModel = likeViewModel ) } } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt index 528cd0c..8697094 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/profile/screen/LikeViewModel.kt @@ -21,6 +21,10 @@ class LikeViewModel @Inject constructor( MutableStateFlow>>(UiState.Empty) val getLikesState: StateFlow>> = _getLikesState + private val _postLikeState = + MutableStateFlow>(UiState.Empty) + val postLikeState: StateFlow> = _postLikeState + fun getLikes() = viewModelScope.launch { _getLikesState.emit(UiState.Loading) profileRepository.getLikes(userId = 1).fold( @@ -33,6 +37,25 @@ class LikeViewModel @Inject constructor( ) } + fun postLike( + userId: Long = 1, + storeId: Long + ) = viewModelScope.launch { + _postLikeState.emit(UiState.Loading) + profileRepository.postLike( + userId, storeId + ).fold( + onSuccess = { + _postLikeState.emit(UiState.Success(it)) + }, + onFailure = { + _postLikeState.emit(UiState.Failure(it.message.toString())) + } + ) + } + + + val mockLikes = listOf( LikesEntity( id = 1, diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt index 2a6e383..144aa86 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportScreen.kt @@ -48,7 +48,7 @@ fun ReportRoute( val systemUiController = rememberSystemUiController() LaunchedEffect(Unit) { - reportViewModel.getReport() + reportViewModel.postReports() } SideEffect { diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt index 7142d91..d3d2a9c 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/report/screen/ReportViewModel.kt @@ -26,11 +26,11 @@ class ReportViewModel @Inject constructor( val postReportWriteState: StateFlow> = _postReportWriteState - fun getReport( + fun postReports( userId : Long = 1 ) = viewModelScope.launch { _getReportState.emit(UiState.Loading) - reportRepository.getReports(userId).fold( + reportRepository.postReports(userId).fold( onSuccess = { _getReportState.emit(UiState.Success(it)) }, From 401078f2cc84c2ca454c960c58df5311b0eea4b8 Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 21:49:00 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EC=B0=A9?= =?UTF-8?q?=ED=95=9C=20=EB=B0=A5=EC=83=81=20=EC=A1=B0=ED=9A=8C=20&=20?= =?UTF-8?q?=EC=A0=9C=EB=B3=B4=20&=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alddeul_babsang/app/di/DataSourceModule.kt | 3 --- .../alddeul_babsang/app/di/RepositoryModule.kt | 4 ---- .../alddeul_babsang/data/mapper/toLikesEntity.kt | 12 ------------ 3 files changed, 19 deletions(-) delete mode 100644 app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt index 7b8e988..fcdda97 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/DataSourceModule.kt @@ -52,7 +52,4 @@ abstract class DataSourceModule { @Singleton abstract fun bindReportDataSource(reportDataSourceImpl: ReportDataSourceImpl): ReportDataSource - @Binds - @Singleton - abstract fun bindReportWriteDataSource(reportWriteDataSourceImpl: ReportDataSourceImpl): ReportDataSource } \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt index a4922ff..c9fe71f 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/app/di/RepositoryModule.kt @@ -48,10 +48,6 @@ abstract class RepositoryModule { @Singleton abstract fun bindReportRepository(reportDataSourceImpl: ReportRepositoryImpl): ReportRepository - @Binds - @Singleton - abstract fun bindReportWriteRepository(reportWriteDataSourceImpl: ReportRepositoryImpl): ReportRepository - @Binds @Singleton abstract fun bindMapRepository(mapRepositoryImpl: MapRepositoryImpl): MapRepository diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt deleted file mode 100644 index 2b0bb97..0000000 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/mapper/toLikesEntity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.hackathon.alddeul_babsang.data.mapper - -import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto -import com.hackathon.alddeul_babsang.domain.entity.ReportEntity - -class toLikesEntity { -} - -fun ResponseReportDto.toLikesEntity() = ReportEntity( - id, imageUrl, name, category, address, contact, isFavorite -) - From 25968e99e3b2e550d36894145faf0984caeb776f Mon Sep 17 00:00:00 2001 From: seoyeonsw Date: Fri, 8 Nov 2024 22:47:00 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#26=20=EC=98=88=EB=B9=84=20=EC=B0=A9?= =?UTF-8?q?=ED=95=9C=20=EB=B0=A5=EC=83=81=20=EC=A1=B0=ED=9A=8C=20&=20?= =?UTF-8?q?=EC=A0=9C=EB=B3=B4=20&=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alddeul_babsang/data/datasource/ReportDataSource.kt | 2 +- .../data/datasourceimpl/ReportDataSourceImpl.kt | 4 ++-- .../data/dto/response/ResponseGetReviewDto.kt | 2 ++ .../data/repositoryimpl/ReportRepositoryImpl.kt | 7 ++----- .../alddeul_babsang/data/service/ReportApiService.kt | 5 +++-- .../alddeul_babsang/domain/repository/ReportRepository.kt | 2 +- .../presentation/detail/screen/ReviewItem.kt | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt index 849c62f..fd7d62c 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ReportDataSource.kt @@ -7,7 +7,7 @@ import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportDataSource { suspend fun postReports( - requestReportDto: RequestReportDto + userId: Int ): BaseResponse> suspend fun postReportWrite( diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt index a99e8f8..c865a31 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ReportDataSourceImpl.kt @@ -11,8 +11,8 @@ import javax.inject.Inject class ReportDataSourceImpl @Inject constructor( private val reportApiService: ReportApiService ) : ReportDataSource { - override suspend fun postReports(requestReportDto: RequestReportDto): BaseResponse> { - return reportApiService.postReports(requestReportDto) + override suspend fun postReports(userId : Int): BaseResponse> { + return reportApiService.postReports(userId) } override suspend fun postReportWrite(requestReportWriteDto: RequestReportWriteDto): BaseResponse { diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseGetReviewDto.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseGetReviewDto.kt index 6343a11..8cdfb44 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseGetReviewDto.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseGetReviewDto.kt @@ -14,4 +14,6 @@ data class Review ( @SerialName("nickname") val nickname: String, @SerialName("rate") val rate: Double, @SerialName("content") val content: String, + @SerialName("image") val imageUrl: String, + @SerialName("date") val date: String ) \ No newline at end of file diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt index ea3c9bb..c3f84b9 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ReportRepositoryImpl.kt @@ -1,7 +1,6 @@ package com.hackathon.alddeul_babsang.data.repositoryimpl import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource -import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto import com.hackathon.alddeul_babsang.domain.repository.ReportRepository @@ -11,13 +10,11 @@ class ReportRepositoryImpl @Inject constructor( private val reportDataSource: ReportDataSource ) : ReportRepository { override suspend fun postReports( - userId: Long + userId: Int ): Result> { return runCatching { reportDataSource.postReports( - requestReportDto = RequestReportDto( - userId = userId - ) + userId = userId ).result ?: emptyList() } } diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt index b4d5468..f5c7550 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/data/service/ReportApiService.kt @@ -8,11 +8,12 @@ import com.sopt.data.service.ApiKeyStorage.POST import com.sopt.data.service.ApiKeyStorage.REPORTS import retrofit2.http.Body import retrofit2.http.POST +import retrofit2.http.Query interface ReportApiService { - @POST("/$REPORTS") + @POST("/$REPORTS/") suspend fun postReports( - @Body requestReportDto: RequestReportDto + @Query("userId") userId: Int ): BaseResponse> @POST("/$REPORTS/$POST") diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt index d811323..54f3578 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ReportRepository.kt @@ -4,7 +4,7 @@ import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto interface ReportRepository { suspend fun postReports( - userId: Long + userId: Int ): Result> suspend fun postReportWrite( diff --git a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/detail/screen/ReviewItem.kt b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/detail/screen/ReviewItem.kt index e78b105..044b0b0 100644 --- a/app/src/main/java/com/hackathon/alddeul_babsang/presentation/detail/screen/ReviewItem.kt +++ b/app/src/main/java/com/hackathon/alddeul_babsang/presentation/detail/screen/ReviewItem.kt @@ -50,7 +50,7 @@ fun ReviewItem( verticalAlignment = Alignment.CenterVertically ) { AsyncImage( - model = "", + model = data.imageUrl, contentDescription = null, placeholder = painterResource(id = R.drawable.ic_launcher_background), modifier = Modifier