-
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.
#40 feat/리뷰 작성 : data 모듈에 리뷰 작성 DataSource, API 호출로직 추가
- Loading branch information
1 parent
d6bb628
commit 9f0525c
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/ftw/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
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
14
data/src/main/java/com/ftw/data/remote/api/review/ReviewAPI.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.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>> | ||
} |
40 changes: 40 additions & 0 deletions
40
data/src/main/java/com/ftw/data/remote/datasource/review/ReviewRemoteDataSource.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,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 | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
data/src/main/java/com/ftw/data/remote/exception/ResponseException.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,3 +1,3 @@ | ||
package com.ftw.data.remote.exception | ||
|
||
class ResponseException(message: String) : RuntimeException(message) | ||
class ResponseException(message: String = "Network Exception") : RuntimeException(message) |
11 changes: 11 additions & 0 deletions
11
data/src/main/java/com/ftw/data/remote/request/CreateReviewRequest.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.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 | ||
) |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/ftw/data/repository/review/ReviewRepositoryImpl.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.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) | ||
} | ||
} |