-
Notifications
You must be signed in to change notification settings - Fork 1
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 #65 from Team-Walkie/feat/like_post
좋아요 기능 구현, Reponse(retrofit)에서 결과를 가져오는 확장함수 구현
- Loading branch information
Showing
19 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
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
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,12 @@ | ||
package com.whyranoid.data | ||
|
||
import retrofit2.Response | ||
|
||
fun <T, R> Response<T>.getResult(transform: (T) -> R): R { | ||
if (this.isSuccessful.not()) | ||
throw Exception(this.errorBody().toString()) | ||
else if (this.body() == null) | ||
throw Exception(this.message()) | ||
|
||
return requireNotNull(this.body()?.let(transform) ?: throw Exception("empty response")) | ||
} |
6 changes: 6 additions & 0 deletions
6
data/src/main/java/com/whyranoid/data/datasource/community/CommunityDataSource.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,6 @@ | ||
package com.whyranoid.data.datasource.community | ||
|
||
interface CommunityDataSource { | ||
|
||
suspend fun likePost(postId: Long, likerId: Long): Result<Long> | ||
} |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/whyranoid/data/datasource/community/CommunityDataSourceImpl.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.whyranoid.data.datasource.community | ||
|
||
import com.whyranoid.data.getResult | ||
import com.whyranoid.data.model.community.request.PostLikeRequest | ||
|
||
class CommunityDataSourceImpl( | ||
private val service: CommunityService | ||
) : CommunityDataSource { | ||
override suspend fun likePost(postId: Long, likerId: Long): Result<Long> { | ||
|
||
return kotlin.runCatching { | ||
val request = PostLikeRequest(likerId, postId) | ||
val response = service.likePost(request) | ||
|
||
response.getResult { | ||
it.likerCount | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/whyranoid/data/datasource/community/CommunityService.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,15 @@ | ||
package com.whyranoid.data.datasource.community | ||
|
||
import com.whyranoid.data.API | ||
import com.whyranoid.data.model.community.request.PostLikeRequest | ||
import com.whyranoid.data.model.community.response.PostLikeResponse | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface CommunityService { | ||
|
||
@POST(API.SEND_LIKE) | ||
suspend fun likePost(@Body postLikeRequest: PostLikeRequest): Response<PostLikeResponse> | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
data/src/main/java/com/whyranoid/data/model/community/request/PostLikeRequest.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,8 @@ | ||
package com.whyranoid.data.model.community.request | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PostLikeRequest( | ||
@SerializedName("likerId") val likerId: Long, | ||
@SerializedName("postId") val postId: Long, | ||
) |
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/whyranoid/data/model/community/response/LikerProfile.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,10 @@ | ||
package com.whyranoid.data.model.community.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class LikerProfile( | ||
@SerializedName("nickname") val nickname: String, | ||
@SerializedName("profileImg") val profileImg: String, | ||
@SerializedName("status") val status: String, | ||
@SerializedName("walkieId") val walkieId: Long | ||
) |
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/whyranoid/data/model/community/response/PostLikeResponse.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,10 @@ | ||
package com.whyranoid.data.model.community.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PostLikeResponse( | ||
@SerializedName("likerCount") val likerCount: Long, | ||
@SerializedName("likerId") val likerId: Long, | ||
@SerializedName("likerProfiles") val likerProfiles: List<LikerProfile>, | ||
@SerializedName("postId") val postId: Long | ||
) |
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
12 changes: 12 additions & 0 deletions
12
data/src/main/java/com/whyranoid/data/repository/CommunityRepositoryImpl.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,12 @@ | ||
package com.whyranoid.data.repository | ||
|
||
import com.whyranoid.data.datasource.community.CommunityDataSource | ||
import com.whyranoid.domain.repository.CommunityRepository | ||
|
||
class CommunityRepositoryImpl( | ||
private val communityDataSource: CommunityDataSource | ||
): CommunityRepository { | ||
override suspend fun likePost(postId: Long, likerId: Long): Result<Long> { | ||
return communityDataSource.likePost(postId, likerId) | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
domain/src/main/java/com/whyranoid/domain/repository/CommunityRepository.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,6 @@ | ||
package com.whyranoid.domain.repository | ||
|
||
interface CommunityRepository { | ||
|
||
suspend fun likePost(postId: Long, likerId: Long): Result<Long> | ||
} |
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/com/whyranoid/domain/usecase/LikePostUseCase.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,16 @@ | ||
package com.whyranoid.domain.usecase | ||
|
||
import com.whyranoid.domain.repository.AccountRepository | ||
import com.whyranoid.domain.repository.CommunityRepository | ||
import kotlinx.coroutines.flow.first | ||
|
||
class LikePostUseCase( | ||
private val communityRepository: CommunityRepository, | ||
private val accountRepository: AccountRepository | ||
) { | ||
|
||
suspend operator fun invoke(postId: Long): Result<Long> { | ||
val uid = requireNotNull(accountRepository.uId.first()) | ||
return communityRepository.likePost(postId, uid) | ||
} | ||
} |
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
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