Skip to content

Commit

Permalink
Merge pull request #137 from EAT-SSU/refactor/base-response
Browse files Browse the repository at this point in the history
[Refactor/base response]
  • Loading branch information
HI-JIN2 authored Mar 9, 2024
2 parents 0e5c530 + f4d294e commit e27f36f
Show file tree
Hide file tree
Showing 29 changed files with 815 additions and 433 deletions.
10 changes: 6 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
</intent>
</queries>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<!--갤러리 권한-->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32"
tools:ignore="ScopedStorage" />
android:maxSdkVersion="32" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.eatssu.android.data.model.request
package com.eatssu.android.data.dto.request

data class InquiriesRequest(
val content: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.eatssu.android.data.dto.request

import com.google.gson.annotations.SerializedName

data class ModifyReviewRequest(
val content: String,
val grade: Int,
val reviewTags: List<String>,
@SerializedName("mainRate") var mainRate: Int? = null,
@SerializedName("amountRate") var amountRate: Int? = null,
@SerializedName("tasteRate") var tasteRate: Int? = null,
@SerializedName("content") var content: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.eatssu.android.data.dto.request

import com.google.gson.annotations.SerializedName

data class WriteReviewRequest(

@SerializedName("mainRating") var mainRating: Int? = null,
@SerializedName("amountRating") var amountRating: Int? = null,
@SerializedName("tasteRating") var tasteRating: Int? = null,
@SerializedName("content") var content: String? = null,
@SerializedName("imageUrl") var imageUrl: String? = null,

)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName


data class FixMenuInfoList(
@SerializedName("menuId") var menuId: Int? = null,
@SerializedName("menuId") var menuId: Long? = null,
@SerializedName("name") var name: String? = null,
@SerializedName("price") var price: Int? = null,
@SerializedName("mainRating") var mainRating: String? = null,
Expand All @@ -14,10 +14,10 @@ data class FixMenuInfoList(
fun ArrayList<FixMenuInfoList>.mapFixedMenuResponseToMenu(): List<Menu> {
return this.map { fixMenuInfo ->
Menu(
id = fixMenuInfo.menuId,
name = fixMenuInfo.name,
price = fixMenuInfo.price,
rate = fixMenuInfo.mainRating
id = fixMenuInfo.menuId ?: 0,
name = fixMenuInfo.name ?: "",
price = fixMenuInfo.price ?: 0,
rate = fixMenuInfo.mainRating ?: ""
)
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
package com.eatssu.android.data.dto.response

import com.eatssu.android.data.model.Reviews

data class GetReviewListResponse(
val dataList: List<Data>?,
val hasNext: Boolean,
val numberOfElements: Int
){
val numberOfElements: Int,
) {
data class Data(
val reviewId: Long,
val menu: String,
val writerId : Int,
val writerId: Int,
val isWriter: Boolean,
val writerNickname: String,
val mainGrade: Int,
val amountGrade: Int,
val tasteGrade: Int,
val writeDate: String,
val content: String,
val imgUrlList: List<String>
val imgUrlList: List<String>,
)
}

fun GetReviewListResponse.toReviewList(): List<Reviews> {
return dataList.orEmpty().map { data ->
Reviews(
menu = data.menu,
writerNickname = data.writerNickname,
mainGrade = data.mainGrade,
amountGrade = data.amountGrade,
tasteGrade = data.tasteGrade,
writeDate = data.writeDate,
content = data.content,
imgUrlList = data.imgUrlList
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ data class GetTodayMealResponseDto(

data class MealInformationResponseList(

@SerializedName("mealId") var mealId: Int? = null,
@SerializedName("mealId") var mealId: Long? = null,
@SerializedName("price") var price: Int? = null,
@SerializedName("mainRating") var mainRating: String? = null,
@SerializedName("menusInformation") var menusInformation: ArrayList<MenusInformation> = arrayListOf(),
)

data class MenusInformation(
@SerializedName("menuId") var menuId: Int? = null,
@SerializedName("menuId") var menuId: Long? = null,
@SerializedName("name") var name: String? = null,
)

Expand All @@ -31,7 +31,7 @@ fun GetTodayMealResponseDto.mapTodayMenuResponseToMenu(): List<Menu> {
id = mealInfo.mealId ?: -1, // Default value if mealId is null
name = name,
price = mealInfo.price ?: 0, // Default value if price is null
rate = mealInfo.mainRating
rate = mealInfo.mainRating ?: ""
)
menuList.add(menu)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.eatssu.android.data.dto.response

import com.google.gson.annotations.SerializedName

data class ImageResponse(
@SerializedName("url") var url: String? = null,
)
8 changes: 4 additions & 4 deletions app/src/main/java/com/eatssu/android/data/model/Menu.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.eatssu.android.data.model

data class Menu(
val id: Int?,
val name: String?,
val price: Int?,
val rate: String?,
val id: Long,
val name: String,
val price: Int,
val rate: String,
)
28 changes: 24 additions & 4 deletions app/src/main/java/com/eatssu/android/data/model/Review.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package com.eatssu.android.data.model

data class Review(
val multipartFileList: List<String>,
val reviewCreate: ReviewCreate,
var name: String? = null,
var reviewCnt: Int? = null,
var mainRating: Double? = null,
var amountRating: Double? = null,
var tasteRating: Double? = null,
var ratingDetails: RatingDetails,
var reviewList: List<Reviews>? = null,
)

data class ReviewCreate(
val content: String,
data class RatingDetails(
var one: Int,
var two: Int,
var three: Int,
var four: Int,
var five: Int,
)

data class Reviews(
val menu: String,
val writerNickname: String,

val mainGrade: Int,
val amountGrade: Int,
val tasteGrade: Int,

val writeDate: String,

val content: String,
val imgUrlList: List<String>,
)
13 changes: 13 additions & 0 deletions app/src/main/java/com/eatssu/android/data/model/WriteReview.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.eatssu.android.data.model

data class WriteReview(
val multipartFileList: List<String>,
val reviewCreate: ReviewCreate,
)

data class ReviewCreate(
val content: String,
val mainGrade: Int,
val amountGrade: Int,
val tasteGrade: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eatssu.android.data.repository


interface ImageRepository {

// suspend fun getImageString(
// image: MultipartBody.Part
// ): Flow<Unit>

// suspend fun login(idToken: String): Flow<LoginResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.eatssu.android.data.repository

import com.eatssu.android.data.service.ImageService
import javax.inject.Inject

class ImageRepositoryImpl @Inject constructor(private val imageService: ImageService) :
ImageRepository {


// override suspend fun getImageString(
// image: MultipartBody.Part
// ): Flow<Unit> = flow {
// emit(imageService.getImageUrl(image))
// }


}
18 changes: 18 additions & 0 deletions app/src/main/java/com/eatssu/android/data/service/ImageService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.eatssu.android.data.service

import com.eatssu.android.base.BaseResponse
import com.eatssu.android.data.dto.response.ImageResponse
import okhttp3.MultipartBody
import retrofit2.Call
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part

interface ImageService {

@Multipart
@POST("/reviews/upload/image") //리뷰 이미지 업로드
fun getImageUrl(
@Part image: MultipartBody.Part,
): Call<BaseResponse<ImageResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.eatssu.android.data.service

import com.eatssu.android.base.BaseResponse
import com.eatssu.android.data.model.request.InquiriesRequest
import com.eatssu.android.data.dto.request.InquiriesRequest
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST
Expand Down
63 changes: 36 additions & 27 deletions app/src/main/java/com/eatssu/android/data/service/ReviewService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,48 @@ package com.eatssu.android.data.service


import com.eatssu.android.base.BaseResponse
import com.eatssu.android.data.dto.request.ModifyReviewRequest
import com.eatssu.android.data.dto.request.WriteReviewRequest
import com.eatssu.android.data.dto.response.GetReviewInfoResponse
import com.eatssu.android.data.dto.response.GetReviewListResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.http.*


interface ReviewService {
@Multipart
@POST("review/{menuId}")
fun writeReview(
@Path("menuId") menuId: Long,
@Part files: List<MultipartBody.Part>, // Remove the part name from the annotation
@Part("reviewCreate") reviewData: RequestBody,
): Call<Void>
// @Multipart
// @POST("reviews/{menuId}")
// fun writeReview(
// @Path("menuId") menuId: Long,
// @Part files: List<MultipartBody.Part>, // Remove the part name from the annotation
// @Part("reviewCreate") reviewData: RequestBody,
// ): Call<BaseResponse<Void>>
//
// @Multipart
// @POST("reviews/{menuId}")
// fun writeReview(
// @Path("menuId") menuId: Long,
// @Part("reviewCreate") reviewData: RequestBody,
// ): Call<BaseResponse<Void>>

@Multipart
@POST("review/{menuId}")
@POST("/reviews/write/{menuId}") //리뷰 작성
fun writeReview(
@Path("menuId") menuId: Long,
@Part("reviewCreate") reviewData: RequestBody,
): Call<Void>

@Body request: WriteReviewRequest,
): Call<BaseResponse<Void>>

@DELETE("/reviews/{reviewId}") //리뷰 삭제
fun delReview(@Path("reviewId") reviewId: Long): Call<BaseResponse<Void>>
fun deleteReview(
@Path("reviewId") reviewId: Long,
): Call<BaseResponse<Void>>

@PATCH("/review/{reviewId}") //리뷰 수정(글 수정)
fun modifyReview(
@Path("reviewId") reviewId: Long,
@Body request: RequestBody,
@Body request: ModifyReviewRequest,
): Call<BaseResponse<Void>>


@GET("/review/info") // Retrieve menu review information (rating, etc.) for changeable menus
fun getRreviewInfo(
@Query("menuType") menuType: String,
@Query("mealId") mealId: Long?,
@Query("menuId") menuId: Long?,
): Call<GetReviewInfoResponse>


@GET("/review/list") //메뉴 리뷰 리스트 조회 - 고정메뉴
@GET("/reviews") //리뷰 리스트 조회
fun getReviewList(
@Query("menuType") menuType: String,
@Query("mealId") mealId: Long?,
Expand All @@ -54,6 +52,17 @@ interface ReviewService {
// @Query("page") page: Int?,
// @Query("size") size: Int?,
// @Query("black") black: List<String>?
): Call<GetReviewListResponse>
): Call<BaseResponse<GetReviewListResponse>>

@GET("/reviews/menus/{menuId}") //고정 메뉴 리뷰 정보 조회(메뉴명, 평점 등등)
fun getMenuReviewInfo(
@Query("menuType") menuType: String,
@Path("menuId") menuId: Long,
): Call<BaseResponse<GetReviewInfoResponse>>

@GET("/reviews/menus/{mealId}") //식단(변동 메뉴) 리뷰 정보 조회(메뉴명, 평점 등등)
fun getMealReviewInfo(
@Path("mealId") mealId: Long,
): Call<BaseResponse<GetReviewInfoResponse>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class MenuViewModel(private val menuService: MenuService) : ViewModel() {
call: Call<BaseResponse<ChangeMenuInfoListDto>>,
response: Response<BaseResponse<ChangeMenuInfoListDto>>,
) {
val data = response.body()?.result!!
if (response.isSuccessful) {
val data = response.body()?.result!!
Log.d("post", "onResponse 성공" + response.body())

menuBymealId.postValue(data)
Expand Down
Loading

0 comments on commit e27f36f

Please sign in to comment.