-
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.
Browse files
Browse the repository at this point in the history
…ike-api [Feature/#28] : 좋아요, 리뷰, 제보, 착한 업소 api 연결
- Loading branch information
Showing
24 changed files
with
456 additions
and
61 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> | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/ProfileDataSource.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,15 @@ | ||
package com.hackathon.alddeul_babsang.data.datasource | ||
|
||
import com.hackathon.alddeul_babsang.data.dto.BaseResponse | ||
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto | ||
|
||
interface ProfileDataSource { | ||
suspend fun getLikes( | ||
userId: Long | ||
): BaseResponse<ResponseLikesDto> | ||
|
||
suspend fun postLike( | ||
requestLikesDto: RequestLikesDto | ||
): BaseResponse<String> | ||
} |
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) | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/hackathon/alddeul_babsang/data/datasourceimpl/ProfileDataSourceImpl.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.ProfileDataSource | ||
import com.hackathon.alddeul_babsang.data.dto.BaseResponse | ||
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto | ||
import com.hackathon.alddeul_babsang.data.service.ProfileApiService | ||
import javax.inject.Inject | ||
|
||
class ProfileDataSourceImpl @Inject constructor( | ||
private val profileApiService: ProfileApiService | ||
) : ProfileDataSource { | ||
override suspend fun getLikes( | ||
userId: Long | ||
): BaseResponse<ResponseLikesDto> { | ||
return profileApiService.getLikes(userId) | ||
} | ||
|
||
override suspend fun postLike(requestLikesDto: RequestLikesDto): BaseResponse<String> { | ||
return profileApiService.postLike(requestLikesDto) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/hackathon/alddeul_babsang/data/dto/request/RequestLikesDto.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,10 @@ | ||
package com.hackathon.alddeul_babsang.data.dto.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestLikesDto ( | ||
@SerialName("userId") val userId: Long, | ||
@SerialName("storeId") val storeId: Long | ||
) |
Empty file.
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/hackathon/alddeul_babsang/data/dto/response/ResponseLikesDto.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,20 @@ | ||
package com.hackathon.alddeul_babsang.data.dto.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseLikesDto( | ||
@SerialName("favoriteStoreDetailDtos") val favoriteRestaurants: List<FavoriteRestaurantDto> | ||
) | ||
|
||
@Serializable | ||
data class FavoriteRestaurantDto( | ||
@SerialName("restaurantId") val restaurantId: Long, | ||
@SerialName("name") val name: String, | ||
@SerialName("category") val category: String, | ||
@SerialName("address") val address: String, | ||
@SerialName("contact") val contact: String, | ||
@SerialName("restaurantImageUrl") val restaurantImageUrl: String? = null, | ||
@SerialName("favorite") val favorite: Boolean | ||
) |
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 | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/hackathon/alddeul_babsang/data/repositoryimpl/ProfileRepositoryImpl.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,32 @@ | ||
package com.hackathon.alddeul_babsang.data.repositoryimpl | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource | ||
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto | ||
import com.hackathon.alddeul_babsang.data.dto.response.FavoriteRestaurantDto | ||
import com.hackathon.alddeul_babsang.domain.repository.ProfileRepository | ||
import javax.inject.Inject | ||
|
||
class ProfileRepositoryImpl @Inject constructor( | ||
private val profileDataSource: ProfileDataSource | ||
) : ProfileRepository { | ||
override suspend fun getLikes( | ||
userId: Long, | ||
): Result<List<FavoriteRestaurantDto>> { | ||
return runCatching { | ||
profileDataSource.getLikes( | ||
userId = userId | ||
).result?.favoriteRestaurants ?: emptyList() | ||
} | ||
} | ||
|
||
override suspend fun postLike(userId: Long, storeId: Long): Result<String> { | ||
return runCatching { | ||
profileDataSource.postLike( | ||
requestLikesDto = RequestLikesDto( | ||
userId = userId, | ||
storeId = storeId | ||
) | ||
).result.toString() | ||
} | ||
} | ||
} |
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> | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/hackathon/alddeul_babsang/data/service/ProfileApiService.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.request.RequestLikesDto | ||
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto | ||
import com.sopt.data.service.ApiKeyStorage.FAVORITES | ||
import com.sopt.data.service.ApiKeyStorage.USER_ID | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
|
||
interface ProfileApiService { | ||
@GET("/$FAVORITES/{$USER_ID}}") | ||
suspend fun getLikes( | ||
@Path("userId") userId: Long, | ||
): BaseResponse<ResponseLikesDto> | ||
|
||
@POST("/$FAVORITES") | ||
suspend fun postLike( | ||
@Body requestLikesDto: RequestLikesDto | ||
): BaseResponse<String> | ||
} |
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> | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/hackathon/alddeul_babsang/domain/repository/ProfileRepository.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.domain.repository | ||
|
||
import com.hackathon.alddeul_babsang.data.dto.response.FavoriteRestaurantDto | ||
|
||
interface ProfileRepository { | ||
suspend fun getLikes( | ||
userId: Long, | ||
): Result<List<FavoriteRestaurantDto>> | ||
|
||
suspend fun postLike( | ||
userId: Long, | ||
storeId: Long, | ||
): Result<String> | ||
} |
Oops, something went wrong.