Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/#137-report-p…
Browse files Browse the repository at this point in the history
…ost-api
  • Loading branch information
Roel4990 committed Jan 23, 2025
2 parents f0f6bf9 + a2398e6 commit 9109c26
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import com.spoony.spoony.data.dto.response.GetPostResponseDto
interface PostRemoteDataSource {
suspend fun postScoopPost(postId: Int, userId: Int): BaseResponse<Boolean>
suspend fun getPostData(postId: Int, userId: Int): BaseResponse<GetPostResponseDto>
suspend fun postAddMapData(postId: Int, userId: Int): BaseResponse<Boolean>
suspend fun deletePinMap(postId: Int, userId: Int): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.spoony.spoony.data.datasourceimpl

import com.spoony.spoony.data.datasource.PostRemoteDataSource
import com.spoony.spoony.data.dto.base.BaseResponse
import com.spoony.spoony.data.dto.request.AddMapRequestDto
import com.spoony.spoony.data.dto.request.PostScoopRequestDto
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import com.spoony.spoony.data.service.PostService
Expand All @@ -17,4 +18,15 @@ class PostRemoteDataSourceImpl @Inject constructor(
postService.postScoopPost(
PostScoopRequestDto(postId = postId, userId = userId)
)

override suspend fun deletePinMap(postId: Int, userId: Int): BaseResponse<Boolean> =
postService.deletePinMap(
postId = postId,
userId = userId
)

override suspend fun postAddMapData(postId: Int, userId: Int): BaseResponse<Boolean> =
postService.postAddMapPost(
AddMapRequestDto(postId = postId, userId = userId)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.spoony.spoony.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AddMapRequestDto(
@SerialName("postId")
val postId: Int,
@SerialName("userId")
val userId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class PostRepositoryImpl @Inject constructor(
}

override suspend fun postAddMap(postId: Int, userId: Int): Result<Boolean> =
Result.success(
true
)
runCatching {
postRemoteDataSource.postAddMapData(postId, userId).success
}

override suspend fun deletePinMap(postId: Int, userId: Int): Result<Boolean> =
Result.success(
true
)
runCatching {
postRemoteDataSource.deletePinMap(postId = postId, userId = userId).success
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/spoony/spoony/data/service/PostService.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.spoony.spoony.data.service

import com.spoony.spoony.data.dto.base.BaseResponse
import com.spoony.spoony.data.dto.request.AddMapRequestDto
import com.spoony.spoony.data.dto.request.PostScoopRequestDto
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
Expand All @@ -15,8 +17,19 @@ interface PostService {
@Path("postId") postId: Int
): BaseResponse<GetPostResponseDto>

@POST("/api/v1/post/zzim")
suspend fun postAddMapPost(
@Body addMapRequestDto: AddMapRequestDto
): BaseResponse<Boolean>

@POST("/api/v1/post/scoop")
suspend fun postScoopPost(
@Body postScoopRequestDto: PostScoopRequestDto
): BaseResponse<Boolean>

@DELETE("/api/v1/post/zzim/{userId}/{postId}")
suspend fun deletePinMap(
@Path("userId") userId: Int,
@Path("postId") postId: Int
): BaseResponse<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class PlaceDetailViewModel @Inject constructor(
}
}

fun addMyMap(userId: Int, postId: Int) {
fun addMyMap(postId: Int, userId: Int) {
viewModelScope.launch {
postRepository.postAddMap(userId = userId, postId = postId)
.onSuccess { response ->
postRepository.postAddMap(postId = postId, userId = userId)
.onSuccess {
_sideEffect.emit(PlaceDetailSideEffect.ShowSnackbar("내 지도에 추가되었어요."))
_state.update {
it.copy(
Expand All @@ -95,10 +95,10 @@ class PlaceDetailViewModel @Inject constructor(
}
}

fun deletePinMap(userId: Int, postId: Int) {
fun deletePinMap(postId: Int, userId: Int) {
viewModelScope.launch {
postRepository.deletePinMap(userId = userId, postId = postId)
.onSuccess { response ->
postRepository.deletePinMap(postId = postId, userId = userId)
.onSuccess {
_sideEffect.emit(PlaceDetailSideEffect.ShowSnackbar("내 지도에서 삭제되었어요."))
_state.update {
it.copy(
Expand Down

0 comments on commit 9109c26

Please sign in to comment.