-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from everymeals/feature/withdraw
[feature/withdraw] 신고하기 플로우 구현 및 리뷰조회 api 연결
- Loading branch information
Showing
27 changed files
with
665 additions
and
207 deletions.
There are no files selected for viewing
23 changes: 19 additions & 4 deletions
23
data/src/main/java/com/everymeal/data/datasource/review/ReviewDataSource.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
51 changes: 39 additions & 12 deletions
51
data/src/main/java/com/everymeal/data/datasource/review/ReviewDataSourceImpl.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
53 changes: 53 additions & 0 deletions
53
data/src/main/java/com/everymeal/data/datasource/review/ReviewPagingSource.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,53 @@ | ||
package com.everymeal.data.datasource.review | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.everymeal.data.datasource.restaurant.PAGING_SIZE | ||
import com.everymeal.data.datasource.restaurant.STARTING_PAGE_INDEX | ||
import com.everymeal.data.model.restaruant.RestaurantResponse | ||
import com.everymeal.data.model.review.ReviewResponse | ||
import com.everymeal.data.service.restaurant.RestaurantApi | ||
import com.everymeal.data.service.review.StoreReviewApi | ||
import retrofit2.HttpException | ||
import java.io.IOException | ||
|
||
class ReviewPagingSource ( | ||
private val storeReviewApi: StoreReviewApi, | ||
private val order: String?, | ||
private val group: String?, | ||
private val grade: Int?, | ||
private val campusIdx: Int | ||
) : PagingSource<Int, ReviewResponse>() { | ||
override fun getRefreshKey(state: PagingState<Int, ReviewResponse>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) | ||
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ReviewResponse> { | ||
val position = params.key ?: STARTING_PAGE_INDEX | ||
|
||
return try { | ||
val response = storeReviewApi.getStoresReviews( | ||
campusIdx = campusIdx, | ||
order = order, | ||
group = group, | ||
grade = grade, | ||
offset = position, | ||
limit = PAGING_SIZE | ||
) | ||
val restaurants = response.data.content | ||
LoadResult.Page( | ||
data = restaurants, | ||
prevKey = if (position == STARTING_PAGE_INDEX) null else position - 1, | ||
nextKey = if (restaurants.isEmpty()) null else position + 1 | ||
) | ||
} catch (exception: IOException) { | ||
LoadResult.Error(exception) | ||
} catch (exception: HttpException) { | ||
LoadResult.Error(exception) | ||
} | ||
} | ||
|
||
} |
113 changes: 67 additions & 46 deletions
113
data/src/main/java/com/everymeal/data/model/review/ReviewListResponse.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 |
---|---|---|
@@ -1,54 +1,75 @@ | ||
package com.everymeal.data.model.review | ||
|
||
|
||
import com.everymeal.domain.model.review.Review | ||
import kotlinx.serialization.SerialName | ||
import com.everymeal.domain.model.review.GetStoreReviewEntity | ||
import com.everymeal.domain.model.review.StoreReviewEntity | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ReviewListResponse( | ||
@SerialName("reviewPagingList") | ||
val reviewPagingList: List<ReviewPaging>? = null, | ||
@SerialName("reviewTotalCnt") | ||
val reviewTotalCnt: Int? = null | ||
) { | ||
@Serializable | ||
data class ReviewPaging( | ||
@SerialName("content") | ||
val content: String? = null, | ||
@SerialName("grade") | ||
val grade: Int? = null, | ||
@SerialName("imageList") | ||
val imageList: List<String>? = null, | ||
@SerialName("mealCategory") | ||
val mealCategory: String? = null, | ||
@SerialName("mealType") | ||
val mealType: String? = null, | ||
@SerialName("restaurantName") | ||
val restaurantName: String? = null, | ||
@SerialName("reviewIdx") | ||
val reviewIdx: Int? = null, | ||
@SerialName("reviewMarksCnt") | ||
val reviewMarksCnt: Int? = null | ||
) { | ||
fun toReviewDetail(): Review.ReviewDetail { | ||
return Review.ReviewDetail( | ||
content = content ?: "", | ||
grade = grade ?: 0, | ||
imageList = imageList ?: listOf(), | ||
mealCategory = mealCategory ?: "", | ||
mealType = mealType ?: "", | ||
restaurantName = restaurantName ?: "", | ||
reviewIdx = reviewIdx ?: 0, | ||
reviewMarksCnt = reviewMarksCnt ?: 0 | ||
) | ||
} | ||
} | ||
|
||
fun toReview(): Review { | ||
return Review( | ||
reviewPagingList = reviewPagingList?.map { it.toReviewDetail() } ?: listOf(), | ||
reviewTotalCnt = reviewTotalCnt ?: 0 | ||
) | ||
} | ||
val content: List<ReviewResponse>, | ||
val pageable: Pageable, | ||
val totalPages: Int, | ||
val totalElements: Int, | ||
val last: Boolean, | ||
val size: Int, | ||
val number: Int, | ||
val sort: Sort, | ||
val numberOfElements: Int, | ||
val first: Boolean, | ||
val empty: Boolean, | ||
) | ||
|
||
@Serializable | ||
data class ReviewResponse( | ||
val reviewIdx: Int, | ||
val content: String, | ||
val grade: Int, | ||
val createdAt: String, | ||
val formattedCreatedAt: String, | ||
val nickName: String, | ||
val profileImageUrl: String, | ||
val reviewMarksCnt: Int, | ||
val images: List<String>?, | ||
val storeIdx: Int, | ||
val storeName: String, | ||
) | ||
|
||
@Serializable | ||
data class Pageable( | ||
val sort: Sort, | ||
val offset: Int, | ||
val pageNumber: Int, | ||
val pageSize: Int, | ||
val paged: Boolean, | ||
val unpaged: Boolean, | ||
) | ||
|
||
@Serializable | ||
data class Sort( | ||
val empty: Boolean, | ||
val sorted: Boolean, | ||
val unsorted: Boolean, | ||
) | ||
|
||
fun ReviewResponse.toStoreReviewEntity(): StoreReviewEntity { | ||
return StoreReviewEntity( | ||
reviewIdx = this.reviewIdx, | ||
content = this.content, | ||
grade = this.grade, | ||
createdAt = this.createdAt, | ||
formattedCreatedAt = this.formattedCreatedAt, | ||
nickName = this.nickName, | ||
profileImageUrl = this.profileImageUrl, | ||
reviewMarksCnt = this.reviewMarksCnt, | ||
images = this.images, | ||
storeIdx = this.storeIdx, | ||
storeName = this.storeName, | ||
) | ||
} | ||
|
||
fun ReviewListResponse.toStoreReviewEntityList(): GetStoreReviewEntity { | ||
return GetStoreReviewEntity( | ||
data = this.content.map { it.toStoreReviewEntity() } | ||
) | ||
} |
48 changes: 41 additions & 7 deletions
48
data/src/main/java/com/everymeal/data/repository/review/DefaultReviewRepository.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
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
19 changes: 19 additions & 0 deletions
19
domain/src/main/java/com/everymeal/domain/model/review/GetStoreReviewEntity.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,19 @@ | ||
package com.everymeal.domain.model.review | ||
|
||
data class GetStoreReviewEntity( | ||
val data: List<StoreReviewEntity> | ||
) | ||
|
||
data class StoreReviewEntity( | ||
val reviewIdx: Int, | ||
val content: String, | ||
val grade: Int, | ||
val createdAt: String, | ||
val formattedCreatedAt: String, | ||
val nickName: String, | ||
val profileImageUrl: String, | ||
val reviewMarksCnt: Int, | ||
val images: List<String>?, | ||
val storeIdx: Int, | ||
val storeName: String, | ||
) |
Oops, something went wrong.