-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8960695
commit b36351b
Showing
15 changed files
with
239 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/DetailDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hackathon.alddeul_babsang.data.datasource | ||
|
||
import com.hackathon.alddeul_babsang.data.dto.BaseResponse | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
|
||
interface DetailDataSource { | ||
suspend fun postReview( | ||
storeId: Long, | ||
data: Map<String, RequestBody>, // JSON 데이터를 포함하는 Map | ||
reviewImage: MultipartBody.Part? = null // 이미지 파일 | ||
): BaseResponse<ResponseReviewDto> | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/DetailDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.hackathon.alddeul_babsang.data.datasourceimpl | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource | ||
import com.hackathon.alddeul_babsang.data.dto.BaseResponse | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto | ||
import com.hackathon.alddeul_babsang.data.service.DetailApiService | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import javax.inject.Inject | ||
|
||
class DetailDataSourceImpl @Inject constructor( | ||
private val detailApiService: DetailApiService | ||
) : DetailDataSource { | ||
override suspend fun postReview( | ||
storeId: Long, | ||
data: Map<String, RequestBody>, | ||
reviewImage: MultipartBody.Part? | ||
): BaseResponse<ResponseReviewDto> { | ||
return detailApiService.postReview(storeId, data, reviewImage) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseReviewDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hackathon.alddeul_babsang.data.dto.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseReviewDto ( | ||
@SerialName("storeId") val storeId: Long, | ||
@SerialName("userId") val userId: Long, | ||
@SerialName("message") val message: String, | ||
) |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/DetailRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.hackathon.alddeul_babsang.data.repositoryimpl | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource | ||
import com.hackathon.alddeul_babsang.domain.repository.DetailRepository | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import org.json.JSONObject | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class DetailRepositoryImpl @Inject constructor( | ||
private val detailDataSource: DetailDataSource | ||
) : DetailRepository { | ||
override suspend fun postReview( | ||
storeId: Long, | ||
userId: Long, | ||
rating: Double, | ||
content: String, | ||
reviewImage: File | ||
): Result<String> { | ||
return runCatching { | ||
val dataMap = mapOf( | ||
"userId" to userId.toString().toRequestBody("text/plain".toMediaTypeOrNull()), | ||
"rating" to rating.toString().toRequestBody("text/plain".toMediaTypeOrNull()), | ||
"content" to content.toRequestBody("text/plain".toMediaTypeOrNull()) | ||
) | ||
|
||
// 이미지 파일 파트 생성 | ||
val filePart = reviewImage?.let { | ||
val requestBody = it.asRequestBody("image/jpeg".toMediaTypeOrNull()) | ||
MultipartBody.Part.createFormData("reviewImage", it.name, requestBody) | ||
} | ||
|
||
detailDataSource.postReview( | ||
storeId = storeId, | ||
data = dataMap, | ||
reviewImage = filePart | ||
).message | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/hackathon/alddeul_babsang/data/service/DetailApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.hackathon.alddeul_babsang.data.service | ||
|
||
import com.hackathon.alddeul_babsang.data.dto.BaseResponse | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto | ||
import com.sopt.data.service.ApiKeyStorage.REVIEW | ||
import com.sopt.data.service.ApiKeyStorage.STORE_ID | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.POST | ||
import retrofit2.http.Part | ||
import retrofit2.http.PartMap | ||
import retrofit2.http.Path | ||
|
||
interface DetailApiService { | ||
@Multipart | ||
@POST("/$REVIEW/{$STORE_ID}") | ||
suspend fun postReview( | ||
@Path("storeId") storeId: Long, | ||
@PartMap data: Map<String, @JvmSuppressWildcards RequestBody>, | ||
@Part reviewImage: MultipartBody.Part? = null | ||
): BaseResponse<ResponseReviewDto> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/DetailRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hackathon.alddeul_babsang.domain.repository | ||
|
||
import java.io.File | ||
|
||
interface DetailRepository { | ||
suspend fun postReview( | ||
storeId: Long, | ||
userId: Long, | ||
rating: Double, | ||
content: String, | ||
reviewImage: File | ||
): Result<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.