Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#162] 지도 관련 API 구현 #172

Merged
merged 16 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.spoony.spoony.data.datasource

import com.spoony.spoony.data.dto.base.BaseResponse
import com.spoony.spoony.data.dto.response.AddedMapListResponseDto
import com.spoony.spoony.data.dto.response.AddedMapPostListDto
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import com.spoony.spoony.data.dto.response.ZzimLocationResponseDto

Expand All @@ -9,5 +11,7 @@ interface PostRemoteDataSource {
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>
suspend fun getAddedMapPost(postId: Int, userId: Int): BaseResponse<AddedMapPostListDto>
suspend fun getAddedMap(userId: Int): BaseResponse<AddedMapListResponseDto>
suspend fun getZzimByLocation(userId: Int, locationId: Int): BaseResponse<ZzimLocationResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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.AddedMapListResponseDto
import com.spoony.spoony.data.dto.response.AddedMapPostListDto
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import com.spoony.spoony.data.dto.response.ZzimLocationResponseDto
import com.spoony.spoony.data.service.PostService
Expand All @@ -26,6 +28,15 @@ class PostRemoteDataSourceImpl @Inject constructor(
userId = userId
)

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

override suspend fun getAddedMap(userId: Int): BaseResponse<AddedMapListResponseDto> =
postService.getAddedMap(userId)

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

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

@Serializable
data class AddedMapResponseDto(
@SerialName("placeId")
val placeId: Int,
@SerialName("placeName")
val placeName: String,
@SerialName("placeAddress")
val placeAddress: String,
@SerialName("postTitle")
val postTitle: String,
@SerialName("photoUrl")
val photoUrlList: String,
@SerialName("latitude")
val latitude: Double,
@SerialName("longitude")
val longitude: Double,
@SerialName("categoryColorResponse")
val categoryColorResponse: CategoryColorResponse
)

@Serializable
data class AddedMapListResponseDto(
@SerialName("count")
val count: Int,
@SerialName("zzimCardResponses")
val zzimCardResponses: List<AddedMapResponseDto>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.spoony.spoony.data.dto.response

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

@Serializable
data class AddedMapPostDto(
@SerialName("placeId")
val placeId: Int,
@SerialName("placeName")
val placeName: String,
@SerialName("categoryColorResponse")
val categoryColorResponse: CategoryColorResponse,
@SerialName("authorName")
val authorName: String,
@SerialName("authorRegionName")
val authorRegionName: String,
@SerialName("postId")
val postId: Int,
@SerialName("postTitle")
val postTitle: String,
@SerialName("zzimCount")
val zzimCount: Int,
@SerialName("photoUrlList")
val photoUrlList: List<String>
)

@Serializable
data class AddedMapPostListDto(
@SerialName("zzimFocusResponseList")
val zzimFocusResponseList: List<AddedMapPostDto>
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ data class GetPostResponseDto(
val isScoop: Boolean,
@SerialName("categoryColorResponse")
val categoryColorResponse: CategoryColorResponse
) {
@Serializable
data class CategoryColorResponse(
@SerialName("categoryId")
val categoryId: Int,
@SerialName("categoryName")
val categoryName: String,
@SerialName("iconUrl")
val iconUrl: String,
@SerialName("iconTextColor")
val iconTextColor: String,
@SerialName("iconBackgroundColor")
val iconBackgroundColor: String
)
}
)

@Serializable
data class CategoryColorResponse(
@SerialName("categoryId")
val categoryId: Int,
@SerialName("categoryName")
val categoryName: String,
@SerialName("iconUrl")
val iconUrl: String,
@SerialName("iconTextColor")
val iconTextColor: String,
@SerialName("iconBackgroundColor")
val iconBackgroundColor: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.spoony.spoony.data.mapper

import com.spoony.spoony.data.dto.response.AddedMapListResponseDto
import com.spoony.spoony.data.dto.response.AddedMapResponseDto
import com.spoony.spoony.domain.entity.AddedPlaceEntity
import com.spoony.spoony.domain.entity.AddedPlaceListEntity

fun AddedMapListResponseDto.toDomain(): AddedPlaceListEntity = AddedPlaceListEntity(
count = this.count,
placeList = this.zzimCardResponses.map { it.toDomain() }
)

fun AddedMapResponseDto.toDomain(): AddedPlaceEntity =
AddedPlaceEntity(
placeId = this.placeId,
placeName = this.placeName,
placeAddress = this.placeAddress,
postTitle = this.postTitle,
photoUrl = this.photoUrlList,
latitude = this.latitude,
longitude = this.longitude,
categoryInfo = this.categoryColorResponse.toDomain()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.spoony.spoony.data.mapper

import com.spoony.spoony.data.dto.response.AddedMapPostDto
import com.spoony.spoony.domain.entity.AddedMapPostEntity

fun AddedMapPostDto.toDomain() = AddedMapPostEntity(
placeId = this.placeId,
placeName = this.placeName,
categoryEntity = this.categoryColorResponse.toDomain(),
authorName = this.authorName,
authorRegionName = this.authorRegionName,
postId = this.postId,
postTitle = this.postTitle,
zzimCount = this.zzimCount,
photoUrlList = this.photoUrlList
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.spoony.spoony.data.mapper

import com.spoony.spoony.data.dto.response.CategoryColorResponse
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import com.spoony.spoony.domain.entity.CategoryEntity
import com.spoony.spoony.domain.entity.PostEntity
Expand All @@ -24,7 +25,7 @@ fun GetPostResponseDto.toDomain() =
category = this.categoryColorResponse.toDomain()
)

fun GetPostResponseDto.CategoryColorResponse.toDomain() =
fun CategoryColorResponse.toDomain() =
CategoryEntity(
categoryId = this.categoryId,
categoryName = this.categoryName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.spoony.spoony.data.repositoryimpl

import com.spoony.spoony.data.datasource.MapRemoteDataSource
import com.spoony.spoony.data.datasource.PostRemoteDataSource
import com.spoony.spoony.data.mapper.toDomain
import com.spoony.spoony.data.service.PostService
import com.spoony.spoony.domain.entity.AddedPlaceEntity
import com.spoony.spoony.domain.entity.CategoryEntity
import com.spoony.spoony.domain.entity.AddedPlaceListEntity
import com.spoony.spoony.domain.entity.LocationEntity
import com.spoony.spoony.domain.repository.MapRepository
import javax.inject.Inject

class MapRepositoryImpl @Inject constructor(
private val postService: PostService,
private val mapRemoteDataSource: MapRemoteDataSource
private val mapRemoteDataSource: MapRemoteDataSource,
private val postRemoteDataSource: PostRemoteDataSource
) : MapRepository {
override suspend fun searchLocation(query: String): Result<List<LocationEntity>> =
runCatching {
Expand All @@ -20,30 +20,14 @@ class MapRepositoryImpl @Inject constructor(
}
}

override suspend fun getAddedPlaceList(userId: Int): Result<List<AddedPlaceEntity>> = Result.success(
listOf(
AddedPlaceEntity(
placeId = 1,
placeName = "BBQ",
placeAddress = "서울특별시 마포구",
postTitle = "안드들 낭만 챙겼다~~",
photoUrl = "https://avatars.githubusercontent.com/u/160750136?v=4&size=40",
latitude = 37.0,
longitude = 127.0,
categoryInfo = CategoryEntity(
categoryId = 3,
categoryName = "카페",
iconUrl = "https://avatars.githubusercontent.com/u/160750136?v=4&size=40",
textColor = "123456",
backgroundColor = "123456"
)
)
)
)
override suspend fun getAddedPlaceList(userId: Int): Result<AddedPlaceListEntity> =
runCatching {
postRemoteDataSource.getAddedMap(userId).data!!.toDomain()
}

override suspend fun getAddedPlaceListByLocation(userId: Int, locationId: Int): Result<List<AddedPlaceEntity>> =
runCatching {
postService.getZzimByLocation(userId, locationId)
postRemoteDataSource.getZzimByLocation(userId, locationId)
.data!!.zzimCardResponses.map { it.toDomain() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.spoony.spoony.data.repositoryimpl

import com.spoony.spoony.data.datasource.PostRemoteDataSource
import com.spoony.spoony.data.mapper.toDomain
import com.spoony.spoony.domain.entity.AddedMapPostEntity
import com.spoony.spoony.domain.entity.PostEntity
import com.spoony.spoony.domain.repository.PostRepository
import javax.inject.Inject
Expand All @@ -28,4 +29,12 @@ class PostRepositoryImpl @Inject constructor(
runCatching {
postRemoteDataSource.deletePinMap(postId = postId, userId = userId).success
}

override suspend fun getAddedMapPost(userId: Int, placeId: Int): Result<List<AddedMapPostEntity>> =
runCatching {
postRemoteDataSource.getAddedMapPost(
userId = userId,
postId = placeId
).data?.zzimFocusResponseList!!.map { it.toDomain() }
}
}
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
Expand Up @@ -3,6 +3,8 @@ 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.AddedMapListResponseDto
import com.spoony.spoony.data.dto.response.AddedMapPostListDto
import com.spoony.spoony.data.dto.response.GetPostResponseDto
import com.spoony.spoony.data.dto.response.ZzimLocationResponseDto
import okhttp3.MultipartBody
Expand Down Expand Up @@ -44,6 +46,17 @@ interface PostService {
@Path("postId") postId: Int
): BaseResponse<Boolean>

@GET("/api/v1/post/zzim/{userId}")
suspend fun getAddedMap(
@Path("userId") userId: Int
): BaseResponse<AddedMapListResponseDto>

@GET("/api/v1/post/zzim/{userId}/{postId}")
suspend fun getAddedMapPost(
@Path("userId") userId: Int,
@Path("postId") postId: Int
): BaseResponse<AddedMapPostListDto>

@Multipart
@POST("/api/v1/post")
suspend fun registerPost(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.spoony.spoony.domain.entity

data class AddedMapPostEntity(
val placeId: Int,
val placeName: String,
val categoryEntity: CategoryEntity,
val authorName: String,
val authorRegionName: String,
val postId: Int,
val postTitle: String,
val zzimCount: Int,
val photoUrlList: List<String>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.spoony.spoony.domain.entity

data class AddedPlaceListEntity(
val count: Int,
val placeList: List<AddedPlaceEntity>
)

data class AddedPlaceEntity(
val placeId: Int,
val placeName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.spoony.spoony.domain.repository

import com.spoony.spoony.domain.entity.AddedPlaceEntity
import com.spoony.spoony.domain.entity.AddedPlaceListEntity
import com.spoony.spoony.domain.entity.LocationEntity

interface MapRepository {
suspend fun searchLocation(query: String): Result<List<LocationEntity>>

suspend fun getAddedPlaceList(userId: Int): Result<List<AddedPlaceEntity>>

suspend fun getAddedPlaceListByLocation(userId: Int, locationId: Int): Result<List<AddedPlaceEntity>>
suspend fun getAddedPlaceList(userId: Int): Result<AddedPlaceListEntity>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.spoony.spoony.domain.repository

import com.spoony.spoony.domain.entity.AddedMapPostEntity
import com.spoony.spoony.domain.entity.PostEntity

interface PostRepository {
Expand All @@ -10,4 +11,6 @@ interface PostRepository {
suspend fun postAddMap(postId: Int, userId: Int): Result<Boolean>

suspend fun deletePinMap(postId: Int, userId: Int): Result<Boolean>

suspend fun getAddedMapPost(userId: Int, placeId: Int): Result<List<AddedMapPostEntity>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ fun MainScreen(
)

mapSearchNavGraph(
paddingValues = paddingValues
paddingValues = paddingValues,
navigateUp = navigator::navigateUp
)
}
}
Expand Down
Loading
Loading