|
1 | 1 | package com.everymeal.data.model.review
|
2 | 2 |
|
3 | 3 |
|
4 |
| -import com.everymeal.domain.model.review.Review |
5 |
| -import kotlinx.serialization.SerialName |
| 4 | +import com.everymeal.domain.model.review.GetStoreReviewEntity |
| 5 | +import com.everymeal.domain.model.review.StoreReviewEntity |
6 | 6 | import kotlinx.serialization.Serializable
|
7 | 7 |
|
8 | 8 | @Serializable
|
9 | 9 | data class ReviewListResponse(
|
10 |
| - @SerialName("reviewPagingList") |
11 |
| - val reviewPagingList: List<ReviewPaging>? = null, |
12 |
| - @SerialName("reviewTotalCnt") |
13 |
| - val reviewTotalCnt: Int? = null |
14 |
| -) { |
15 |
| - @Serializable |
16 |
| - data class ReviewPaging( |
17 |
| - @SerialName("content") |
18 |
| - val content: String? = null, |
19 |
| - @SerialName("grade") |
20 |
| - val grade: Int? = null, |
21 |
| - @SerialName("imageList") |
22 |
| - val imageList: List<String>? = null, |
23 |
| - @SerialName("mealCategory") |
24 |
| - val mealCategory: String? = null, |
25 |
| - @SerialName("mealType") |
26 |
| - val mealType: String? = null, |
27 |
| - @SerialName("restaurantName") |
28 |
| - val restaurantName: String? = null, |
29 |
| - @SerialName("reviewIdx") |
30 |
| - val reviewIdx: Int? = null, |
31 |
| - @SerialName("reviewMarksCnt") |
32 |
| - val reviewMarksCnt: Int? = null |
33 |
| - ) { |
34 |
| - fun toReviewDetail(): Review.ReviewDetail { |
35 |
| - return Review.ReviewDetail( |
36 |
| - content = content ?: "", |
37 |
| - grade = grade ?: 0, |
38 |
| - imageList = imageList ?: listOf(), |
39 |
| - mealCategory = mealCategory ?: "", |
40 |
| - mealType = mealType ?: "", |
41 |
| - restaurantName = restaurantName ?: "", |
42 |
| - reviewIdx = reviewIdx ?: 0, |
43 |
| - reviewMarksCnt = reviewMarksCnt ?: 0 |
44 |
| - ) |
45 |
| - } |
46 |
| - } |
47 |
| - |
48 |
| - fun toReview(): Review { |
49 |
| - return Review( |
50 |
| - reviewPagingList = reviewPagingList?.map { it.toReviewDetail() } ?: listOf(), |
51 |
| - reviewTotalCnt = reviewTotalCnt ?: 0 |
52 |
| - ) |
53 |
| - } |
| 10 | + val content: List<ReviewResponse>, |
| 11 | + val pageable: Pageable, |
| 12 | + val totalPages: Int, |
| 13 | + val totalElements: Int, |
| 14 | + val last: Boolean, |
| 15 | + val size: Int, |
| 16 | + val number: Int, |
| 17 | + val sort: Sort, |
| 18 | + val numberOfElements: Int, |
| 19 | + val first: Boolean, |
| 20 | + val empty: Boolean, |
| 21 | +) |
| 22 | + |
| 23 | +@Serializable |
| 24 | +data class ReviewResponse( |
| 25 | + val reviewIdx: Int, |
| 26 | + val content: String, |
| 27 | + val grade: Int, |
| 28 | + val createdAt: String, |
| 29 | + val formattedCreatedAt: String, |
| 30 | + val nickName: String, |
| 31 | + val profileImageUrl: String, |
| 32 | + val reviewMarksCnt: Int, |
| 33 | + val images: List<String>?, |
| 34 | + val storeIdx: Int, |
| 35 | + val storeName: String, |
| 36 | +) |
| 37 | + |
| 38 | +@Serializable |
| 39 | +data class Pageable( |
| 40 | + val sort: Sort, |
| 41 | + val offset: Int, |
| 42 | + val pageNumber: Int, |
| 43 | + val pageSize: Int, |
| 44 | + val paged: Boolean, |
| 45 | + val unpaged: Boolean, |
| 46 | +) |
| 47 | + |
| 48 | +@Serializable |
| 49 | +data class Sort( |
| 50 | + val empty: Boolean, |
| 51 | + val sorted: Boolean, |
| 52 | + val unsorted: Boolean, |
| 53 | +) |
| 54 | + |
| 55 | +fun ReviewResponse.toStoreReviewEntity(): StoreReviewEntity { |
| 56 | + return StoreReviewEntity( |
| 57 | + reviewIdx = this.reviewIdx, |
| 58 | + content = this.content, |
| 59 | + grade = this.grade, |
| 60 | + createdAt = this.createdAt, |
| 61 | + formattedCreatedAt = this.formattedCreatedAt, |
| 62 | + nickName = this.nickName, |
| 63 | + profileImageUrl = this.profileImageUrl, |
| 64 | + reviewMarksCnt = this.reviewMarksCnt, |
| 65 | + images = this.images, |
| 66 | + storeIdx = this.storeIdx, |
| 67 | + storeName = this.storeName, |
| 68 | + ) |
| 69 | +} |
| 70 | + |
| 71 | +fun ReviewListResponse.toStoreReviewEntityList(): GetStoreReviewEntity { |
| 72 | + return GetStoreReviewEntity( |
| 73 | + data = this.content.map { it.toStoreReviewEntity() } |
| 74 | + ) |
54 | 75 | }
|
0 commit comments