Skip to content

Commit

Permalink
chore: 2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rhkrwngud445 committed Sep 29, 2024
1 parent 88d1487 commit 6bb469d
Show file tree
Hide file tree
Showing 33 changed files with 493 additions and 109 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
applicationId = "com.withpeace.withpeace"
targetSdk = 34
versionCode = 11
versionName = "2.1.1"
versionCode = 12
versionName = "2.2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private fun NavController.navigateToTabScreen(bottomTab: BottomTab) {
when (bottomTab) {
BottomTab.HOME -> navigateHome(tabNavOptions)
BottomTab.POLICY -> navigateToPolicyList(tabNavOptions)
BottomTab.POST -> navigateToPostList(tabNavOptions)
BottomTab.POST -> navigateToPostList(navOptions = tabNavOptions)
BottomTab.MY_PAGE -> navigate(MY_PAGE_NESTED_ROUTE, tabNavOptions)
}
}
Expand Down Expand Up @@ -115,5 +115,11 @@ enum class BottomTab(
MY_PAGE_NESTED_ROUTE,
),
;

companion object {
operator fun contains(route: String): Boolean {
return entries.map { it.route }.contains(route)
}
}
}
// https://stackoverflow.com/questions/76721423/compose-navigation-go-to-top-level-destination-when-clicking-on-navigation-bar
10 changes: 7 additions & 3 deletions app/src/main/java/com/withpeace/withpeace/WithpeaceApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ fun WithpeaceApp(

Scaffold(
bottomBar = {
MainBottomBar(
if (
BottomTab.contains(parentDestination?.route ?: currentDestination?.route ?: "")
) {
MainBottomBar(
currentDestination = if (parentDestination?.route == null) {
currentDestination ?: return@Scaffold
} else parentDestination,
navController = navController,
)
navController = navController,
)
}
},
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.withpeace.withpeace.feature.postdetail.navigation.navigateToPostDetai
import com.withpeace.withpeace.feature.postdetail.navigation.postDetailGraph
import com.withpeace.withpeace.feature.postlist.navigation.POST_LIST_DELETED_POST_ID_ARGUMENT
import com.withpeace.withpeace.feature.postlist.navigation.POST_LIST_ROUTE
import com.withpeace.withpeace.feature.postlist.navigation.navigateToPostList
import com.withpeace.withpeace.feature.postlist.navigation.postListGraph
import com.withpeace.withpeace.feature.privacypolicy.navigation.navigateToPrivacyPolicy
import com.withpeace.withpeace.feature.privacypolicy.navigation.privacyPolicyGraph
Expand Down Expand Up @@ -194,6 +195,9 @@ fun WithpeaceNavHost(
onPolicyClick = {
navController.navigateToPolicyDetail(policyId = it)
},
onPostClick = {
navController.navigateToPostList(it.name)
}
)
policyDetailNavGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.withpeace.withpeace.core.data.mapper

import com.withpeace.withpeace.core.domain.model.post.RecentPost
import com.withpeace.withpeace.core.network.di.response.post.RecentPostResponse

fun RecentPostResponse.toDomain(): RecentPost {
return RecentPost(
id = postId, title = title, type = type.toDomain(),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.withpeace.withpeace.core.data.mapper.youthpolicy

import com.withpeace.withpeace.core.domain.model.policy.PolicyClassification
import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters
import com.withpeace.withpeace.core.domain.model.policy.PolicyRegion
import com.withpeace.withpeace.core.network.di.response.policy.UserPolicyFilterResponse

fun UserPolicyFilterResponse.toDomain(): PolicyFilters {
return PolicyFilters(
regions = region.map { name ->
PolicyRegion.entries.find { it.name == name } ?: PolicyRegion.기타
},
classifications = classification.map { name ->
PolicyClassification.entries.find { it.name == name } ?: PolicyClassification.ETC
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.withpeace.withpeace.core.domain.model.error.ResponseError
import com.withpeace.withpeace.core.domain.model.post.Post
import com.withpeace.withpeace.core.domain.model.post.PostDetail
import com.withpeace.withpeace.core.domain.model.post.PostTopic
import com.withpeace.withpeace.core.domain.model.post.RecentPost
import com.withpeace.withpeace.core.domain.model.post.RegisterPost
import com.withpeace.withpeace.core.domain.model.post.ReportType
import com.withpeace.withpeace.core.domain.repository.PostRepository
Expand Down Expand Up @@ -147,6 +148,13 @@ class DefaultPostRepository @Inject constructor(
}
}

override fun getRecentPost(onError: suspend (CheonghaError) -> Unit): Flow<List<RecentPost>> =
flow {
postService.getRecentPost().suspendMapSuccess {
emit(this.data.map { it.toDomain() })
}.handleApiFailure(onError)
}

private fun getImageRequestBodies(
imageUris: List<String>,
): List<MultipartBody.Part> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.withpeace.withpeace.core.analytics.AnalyticsEvent
import com.withpeace.withpeace.core.analytics.AnalyticsHelper
import com.withpeace.withpeace.core.data.analytics.event
import com.withpeace.withpeace.core.data.mapper.toDomain
import com.withpeace.withpeace.core.data.mapper.youthpolicy.toCode
import com.withpeace.withpeace.core.data.mapper.youthpolicy.toDomain
import com.withpeace.withpeace.core.data.util.convertToFile
import com.withpeace.withpeace.core.data.util.handleApiFailure
import com.withpeace.withpeace.core.datastore.dataStore.token.TokenPreferenceDataSource
Expand All @@ -15,6 +17,7 @@ import com.withpeace.withpeace.core.domain.model.SignUpInfo
import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.model.error.ClientError
import com.withpeace.withpeace.core.domain.model.error.ResponseError
import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters
import com.withpeace.withpeace.core.domain.model.profile.ChangedProfile
import com.withpeace.withpeace.core.domain.model.profile.Nickname
import com.withpeace.withpeace.core.domain.model.profile.ProfileInfo
Expand Down Expand Up @@ -133,6 +136,25 @@ class DefaultUserRepository @Inject constructor(
}
}

override fun updatePolicyFilter(
policyFilters: PolicyFilters,
onError: suspend (CheonghaError) -> Unit,
): Flow<Unit> = flow {
userService.patchPolicyFilter(
region = policyFilters.regions.joinToString(",") { it.toCode() },
classification = policyFilters.classifications.joinToString(",") { it.toCode() },
).suspendMapSuccess {
emit(Unit)
}.handleApiFailure(onError)
}

override fun getPolicyFilter(onError: suspend (CheonghaError) -> Unit): Flow<PolicyFilters> =
flow {
userService.getPolicyFilter().suspendMapSuccess {
emit(this.data.toDomain())
}.handleApiFailure(onError)
}

override fun withdraw(onError: suspend (CheonghaError) -> Unit): Flow<Unit> =
flow {
userService.withdraw().suspendMapSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ class DefaultYouthPolicyRepository @Inject constructor(
}
}

override fun getRecommendPolicy(onError: suspend (CheonghaError) -> Unit): Flow<List<YouthPolicy>> =
flow {
youthPolicyService.getRecommendations().suspendMapSuccess {
emit(data.map { it.toDomain() })
}.handleApiFailure {
onErrorWithAuthExpired(it, onError)
}
}

override fun getHotPolicy(onError: suspend (CheonghaError) -> Unit): Flow<List<YouthPolicy>> =
flow {
youthPolicyService.getHots().suspendMapSuccess {
emit(data.map { it.toDomain() })
}.handleApiFailure {
onErrorWithAuthExpired(it, onError)
}
}

private suspend fun onErrorWithAuthExpired(
it: ResponseError,
onError: suspend (CheonghaError) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.withpeace.withpeace.core.domain.model.post

data class RecentPost(
val id: Long,
val title: String,
val type: PostTopic,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.model.post.Post
import com.withpeace.withpeace.core.domain.model.post.PostDetail
import com.withpeace.withpeace.core.domain.model.post.PostTopic
import com.withpeace.withpeace.core.domain.model.post.RecentPost
import com.withpeace.withpeace.core.domain.model.post.RegisterPost
import com.withpeace.withpeace.core.domain.model.post.ReportType
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -48,4 +49,8 @@ interface PostRepository {
reportType: ReportType,
onError: suspend (CheonghaError) -> Unit,
): Flow<Boolean>

fun getRecentPost(
onError: suspend (CheonghaError) -> Unit,
): Flow<List<RecentPost>>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.withpeace.withpeace.core.domain.repository

import com.withpeace.withpeace.core.domain.model.error.ResponseError
import com.withpeace.withpeace.core.domain.model.SignUpInfo
import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.model.policy.PolicyFilters
import com.withpeace.withpeace.core.domain.model.profile.ChangedProfile
import com.withpeace.withpeace.core.domain.model.profile.Nickname
import com.withpeace.withpeace.core.domain.model.profile.ProfileInfo
Expand Down Expand Up @@ -42,4 +42,11 @@ interface UserRepository {
fun withdraw(
onError: suspend (CheonghaError) -> Unit,
): Flow<Unit>

fun updatePolicyFilter(
policyFilters: PolicyFilters,
onError: suspend (CheonghaError) -> Unit,
): Flow<Unit>

fun getPolicyFilter(onError: suspend (CheonghaError) -> Unit): Flow<PolicyFilters>
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ interface YouthPolicyRepository {
policyId: String,
onError: suspend (CheonghaError) -> Unit,
): Flow<Unit>

fun getRecommendPolicy(
onError: suspend (CheonghaError) -> Unit,
): Flow<List<YouthPolicy>>

fun getHotPolicy(
onError: suspend (CheonghaError) -> Unit,
): Flow<List<YouthPolicy>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.withpeace.withpeace.core.domain.usecase

import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.repository.YouthPolicyRepository
import javax.inject.Inject

class GetHotPoliciesUseCase @Inject constructor(
private val policyRepository: YouthPolicyRepository,
) {
operator fun invoke(onError: suspend (CheonghaError) -> Unit) =
policyRepository.getHotPolicy(onError)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.withpeace.withpeace.core.domain.usecase

import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.repository.PostRepository
import javax.inject.Inject

class GetRecentPostUseCase @Inject constructor(
private val postRepository: PostRepository,
) {
operator fun invoke(onError: suspend (CheonghaError) -> Unit) =
postRepository.getRecentPost(onError)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.withpeace.withpeace.core.domain.usecase

import com.withpeace.withpeace.core.domain.model.error.CheonghaError
import com.withpeace.withpeace.core.domain.repository.YouthPolicyRepository
import javax.inject.Inject

class GetRecommendPoliciesUseCase @Inject constructor(
private val policyRepository: YouthPolicyRepository,
) {
operator fun invoke(onError: suspend (CheonghaError) -> Unit) =
policyRepository.getRecommendPolicy(onError)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.withpeace.withpeace.core.network.di.response.policy

import kotlinx.serialization.Serializable

@Serializable
data class UserPolicyFilterResponse(
val classification: List<String>,
val region: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.withpeace.withpeace.core.network.di.response.post

import kotlinx.serialization.Serializable

@Serializable
data class RecentPostResponse(
val type: PostTopicResponse,
val postId: Long,
val title: String,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.withpeace.withpeace.core.network.di.response.BaseResponse
import com.withpeace.withpeace.core.network.di.response.post.PostDetailResponse
import com.withpeace.withpeace.core.network.di.response.post.PostIdResponse
import com.withpeace.withpeace.core.network.di.response.post.PostResponse
import com.withpeace.withpeace.core.network.di.response.post.RecentPostResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
Expand Down Expand Up @@ -71,4 +72,7 @@ interface PostService {
@Path("commentId") commentId: Long,
@Body reportTypeRequest: ReportTypeRequest,
): ApiResponse<BaseResponse<Boolean>>

@GET("/api/v1/posts/recents")
suspend fun getRecentPost(): ApiResponse<BaseResponse<List<RecentPostResponse>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.withpeace.withpeace.core.network.di.response.BaseResponse
import com.withpeace.withpeace.core.network.di.response.ChangedProfileResponse
import com.withpeace.withpeace.core.network.di.response.ProfileResponse
import com.withpeace.withpeace.core.network.di.response.TokenResponse
import com.withpeace.withpeace.core.network.di.response.policy.UserPolicyFilterResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
Expand Down Expand Up @@ -57,4 +58,13 @@ interface UserService {

@DELETE("/api/v1/users")
suspend fun withdraw(): ApiResponse<BaseResponse<Boolean>>

@PATCH("/api/v1/users/profile/policy-filter")
suspend fun patchPolicyFilter(
@Query("region") region: String,
@Query("classification") classification: String,
): ApiResponse<BaseResponse<Boolean>>

@GET("/api/v1/users/profile/policy-filter")
suspend fun getPolicyFilter(): ApiResponse<BaseResponse<UserPolicyFilterResponse>>
}
Loading

0 comments on commit 6bb469d

Please sign in to comment.