Skip to content

Commit

Permalink
#40 feat/리뷰 작성 : data 모듈에 리뷰 작성 DataSource, API 호출로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HayleyKim0716 committed Oct 18, 2022
1 parent d6bb628 commit 9f0525c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ftw.data.datasource.review

interface ReviewDataSource {
suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
)
}
14 changes: 14 additions & 0 deletions data/src/main/java/com/ftw/data/remote/api/review/ReviewAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ftw.data.remote.api.review

import com.ftw.data.remote.request.CreateReviewRequest
import com.ftw.data.remote.response.RemoteResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface ReviewAPI {
@POST("/api/v1/review")
fun create(
@Body review: CreateReviewRequest
): Response<RemoteResponse<Nothing>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ftw.data.remote.datasource.review

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.data.remote.api.review.ReviewAPI
import com.ftw.data.remote.exception.ResponseException
import com.ftw.data.remote.request.CreateReviewRequest

class ReviewRemoteDataSource(
private val api: ReviewAPI
) : ReviewDataSource {
override suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
) {
try {
val response = api.create(
CreateReviewRequest(
buildingId,
companyId,
period,
rating,
advantage,
disadvantage,
floor
)
)

if (!response.isSuccessful) {
throw ResponseException()
}
} catch (e: Exception) {
throw e
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.ftw.data.remote.exception

class ResponseException(message: String) : RuntimeException(message)
class ResponseException(message: String = "Network Exception") : RuntimeException(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ftw.data.remote.request

data class CreateReviewRequest(
val buildingId: String,
val companyId: String,
val period: String,
val rating: Int,
val advantage: String,
val disadvantage: String,
val floor: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ftw.data.repository.review

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.domain.repository.review.ReviewRepository

class ReviewRepositoryImpl(
private val dataSource: ReviewDataSource
) : ReviewRepository {
override suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
) {
dataSource.create(buildingId, companyId, period, rating, advantage, disadvantage, floor)
}
}

0 comments on commit 9f0525c

Please sign in to comment.