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

[AN] 놀이터 전체 조회 -> 범위 조회로 변경 #778

Merged
merged 4 commits into from
Jan 6, 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,5 @@
package com.happy.friendogly.data.repository

import com.happy.friendogly.data.error.ApiExceptionDto
import com.happy.friendogly.data.mapper.toDomain
import com.happy.friendogly.data.source.PlaygroundDataSource
import com.happy.friendogly.domain.DomainResult
Expand All @@ -14,6 +13,8 @@ import com.happy.friendogly.presentation.ui.playground.model.PlaygroundInfo
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundJoin
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundMessage
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundSummary
import com.happy.friendogly.remote.error.ApiExceptionResponse
import com.happy.friendogly.remote.mapper.toData
import com.happy.friendogly.remote.model.request.PatchPlaygroundArrivalRequest
import com.happy.friendogly.remote.model.request.PatchPlaygroundMessageRequest
import com.happy.friendogly.remote.model.request.PostPlaygroundRequest
Expand Down Expand Up @@ -41,7 +42,11 @@ class PlaygroundRepositoryImpl
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionDto -> DomainResult.Error(throwable.error.data.errorCode.toDomain())
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
Expand All @@ -65,7 +70,11 @@ class PlaygroundRepositoryImpl
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionDto -> DomainResult.Error(throwable.error.data.errorCode.toDomain())
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
Expand All @@ -74,27 +83,110 @@ class PlaygroundRepositoryImpl
)
}

override suspend fun getPetExistence(): Result<PetExistence> =
source.getPetExistence().mapCatching { dto ->
dto.toDomain()
}
override suspend fun getPetExistence(): DomainResult<PetExistence, DataError.Network> =
source.getPetExistence()
.fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun getPlaygrounds(
startLatitude: Double,
endLatitude: Double,
startLongitude: Double,
endLongitude: Double,
): DomainResult<List<Playground>, DataError.Network> =
source.getPlaygrounds(startLatitude, endLatitude, startLongitude, endLongitude)
.fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun getMyPlayground(): DomainResult<MyPlayground, DataError.Network> =
source.getMyPlayground()
.fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

override suspend fun getPlaygrounds(): Result<List<Playground>> =
source
.getNearPlaygrounds()
.mapCatching { dto ->
dto.toDomain()
}
is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun getPlaygroundInfo(id: Long): Result<PlaygroundInfo> =
source
.getPlaygroundInfo(id)
.mapCatching { dto -> dto.toDomain() }
override suspend fun getPlaygroundInfo(id: Long): DomainResult<PlaygroundInfo, DataError.Network> =
source.getPlaygroundInfo(id)
.fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

override suspend fun getPlaygroundSummary(playgroundId: Long): Result<PlaygroundSummary> =
source
.getPlaygroundSummary(playgroundId)
.mapCatching { dto -> dto.toDomain() }
is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun getPlaygroundSummary(playgroundId: Long): DomainResult<PlaygroundSummary, DataError.Network> =
source.getPlaygroundSummary(playgroundId)
.fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun postPlaygroundJoin(playgroundId: Long): DomainResult<PlaygroundJoin, DataError.Network> {
return source.postPlaygroundJoin(playgroundId).fold(
Expand All @@ -103,7 +195,11 @@ class PlaygroundRepositoryImpl
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionDto -> DomainResult.Error(throwable.error.data.errorCode.toDomain())
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
Expand All @@ -112,12 +208,44 @@ class PlaygroundRepositoryImpl
)
}

override suspend fun deletePlaygroundLeave(): Result<Unit> = source.deletePlaygroundLeave()
override suspend fun deletePlaygroundLeave(): DomainResult<Unit, DataError.Network> =
source.deletePlaygroundLeave()
.fold(
onSuccess = { dto ->
DomainResult.Success(dto)
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

override suspend fun patchPlaygroundMessage(message: String): Result<PlaygroundMessage> =
is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)

override suspend fun patchPlaygroundMessage(message: String): DomainResult<PlaygroundMessage, DataError.Network> =
source.patchPlaygroundMessage(
PatchPlaygroundMessageRequest(message),
).mapCatching { dto ->
dto.toDomain()
}
).fold(
onSuccess = { dto ->
DomainResult.Success(dto.toDomain())
},
onFailure = { throwable ->
when (throwable) {
is ApiExceptionResponse ->
DomainResult.Error(
throwable.error.data.errorCode.toData().toDomain(),
)

is ConnectException -> DomainResult.Error(DataError.Network.NO_INTERNET)
is UnknownHostException -> DomainResult.Error(DataError.Network.NO_INTERNET)
else -> DomainResult.Error(DataError.Network.SERVER_ERROR)
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ interface PlaygroundDataSource {

suspend fun getPetExistence(): Result<PetExistenceDto>

suspend fun getNearPlaygrounds(): Result<List<PlaygroundDto>>
suspend fun getPlaygrounds(
startLatitude: Double,
endLatitude: Double,
startLongitude: Double,
endLongitude: Double,
): Result<List<PlaygroundDto>>

suspend fun getMyPlayground(): Result<MyPlaygroundDto>

suspend fun getPlaygroundInfo(id: Long): Result<PlaygroundInfoDto>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ interface PlaygroundRepository {
longitude: Double,
): DomainResult<PlaygroundArrival, DataError.Network>

suspend fun getPetExistence(): Result<PetExistence>
suspend fun getPetExistence(): DomainResult<PetExistence, DataError.Network>

suspend fun getPlaygrounds(): Result<List<Playground>>
suspend fun getPlaygrounds(
startLatitude: Double,
endLatitude: Double,
startLongitude: Double,
endLongitude: Double,
): DomainResult<List<Playground>, DataError.Network>

suspend fun getPlaygroundInfo(id: Long): Result<PlaygroundInfo>
suspend fun getMyPlayground(): DomainResult<MyPlayground, DataError.Network>

suspend fun getPlaygroundSummary(playgroundId: Long): Result<PlaygroundSummary>
suspend fun getPlaygroundInfo(id: Long): DomainResult<PlaygroundInfo, DataError.Network>

suspend fun getPlaygroundSummary(playgroundId: Long): DomainResult<PlaygroundSummary, DataError.Network>

suspend fun postPlaygroundJoin(playgroundId: Long): DomainResult<PlaygroundJoin, DataError.Network>

suspend fun deletePlaygroundLeave(): Result<Unit>
suspend fun deletePlaygroundLeave(): DomainResult<Unit, DataError.Network>

suspend fun patchPlaygroundMessage(message: String): Result<PlaygroundMessage>
suspend fun patchPlaygroundMessage(message: String): DomainResult<PlaygroundMessage, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import javax.inject.Inject

class DeletePlaygroundLeaveUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(): Result<Unit> = repository.deletePlaygroundLeave()
suspend operator fun invoke(): DomainResult<Unit, DataError.Network> = repository.deletePlaygroundLeave()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.MyPlayground
import javax.inject.Inject

class GetMyPlaygroundUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(): DomainResult<MyPlayground, DataError.Network> = repository.getMyPlayground()
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.PetExistence
import javax.inject.Inject

class GetPetExistenceUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(): Result<PetExistence> = repository.getPetExistence()
suspend operator fun invoke(): DomainResult<PetExistence, DataError.Network> = repository.getPetExistence()
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundInfo
import javax.inject.Inject

class GetPlaygroundInfoUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(id: Long): Result<PlaygroundInfo> = repository.getPlaygroundInfo(id)
suspend operator fun invoke(id: Long): DomainResult<PlaygroundInfo, DataError.Network> = repository.getPlaygroundInfo(id)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundSummary
import javax.inject.Inject

class GetPlaygroundSummaryUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(playgroundId: Long): Result<PlaygroundSummary> = repository.getPlaygroundSummary(playgroundId)
suspend operator fun invoke(playgroundId: Long): DomainResult<PlaygroundSummary, DataError.Network> =
repository.getPlaygroundSummary(playgroundId)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.Playground
import javax.inject.Inject

class GetPlaygroundsUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(): Result<List<Playground>> = repository.getPlaygrounds()
suspend operator fun invoke(
startLatitude: Double,
endLatitude: Double,
startLongitude: Double,
endLongitude: Double,
): DomainResult<List<Playground>, DataError.Network> =
repository.getPlaygrounds(startLatitude, endLatitude, startLongitude, endLongitude)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.DomainResult
import com.happy.friendogly.domain.error.DataError
import com.happy.friendogly.domain.repository.PlaygroundRepository
import com.happy.friendogly.presentation.ui.playground.model.PlaygroundMessage
import javax.inject.Inject

class PathPlaygroundMessageUseCase
class PatchPlaygroundMessageUseCase
@Inject
constructor(private val repository: PlaygroundRepository) {
suspend operator fun invoke(message: String): Result<PlaygroundMessage> = repository.patchPlaygroundMessage(message)
suspend operator fun invoke(message: String): DomainResult<PlaygroundMessage, DataError.Network> =
repository.patchPlaygroundMessage(message)
}
Loading
Loading