Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
๐Ÿ”€ :: (#117) ์ปค๋ฎค๋‹ˆํ‹ฐ ์‹ ๊ณ  ๊ธฐ๋Šฅ ๊ตฌํ˜„
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: (#117) ์ปค๋ฎค๋‹ˆํ‹ฐ ์‹ ๊ณ  ๊ธฐ๋Šฅ ๊ตฌํ˜„
  • Loading branch information
chlgkdms authored Dec 5, 2023
2 parents 1b1e025 + decf585 commit 061e6f8
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 19 deletions.
5 changes: 5 additions & 0 deletions data/src/main/kotlin/com/signal/data/api/FeedApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ interface FeedApi {
@Path("feed_id") feedId: UUID,
@Body createPostRequest: CreatePostRequest,
)

@PATCH(SignalUrl.Feed.ReportFeed)
suspend fun reportFeed(
@Path("feed_id") feedId: UUID,
)
}
1 change: 1 addition & 0 deletions data/src/main/kotlin/com/signal/data/api/SignalUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object SignalUrl {
const val CreateComment = "/comment/user/{feed_id}"
const val FetchComment = "/comment/{feed_id}"
const val FeedId = "$feed/{feed_id}"
const val ReportFeed = "$feed/report/{feed_id}"
}

object Attachment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface FeedDataSource {
feedId: UUID,
createPostRequest: CreatePostRequest,
)

suspend fun reportFeed(feedId: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ class FeedDataSourceImpl(
createPostRequest = createPostRequest,
)
}.sendRequest()

override suspend fun reportFeed(feedId: UUID) = ExceptionHandler<Unit>().httpRequest {
feedApi.reportFeed(feedId = feedId)
}.sendRequest()
}

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ class FeedRepositoryImpl(
title = title,
content = content,
image = image,
)
),
)
}

override suspend fun reportFeed(feedId: UUID) = kotlin.runCatching {
feedDataSource.reportFeed(feedId = feedId)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.signal.domain.repository

import com.signal.domain.entity.PostsEntity
import com.signal.domain.entity.PostCommentsEntity
import com.signal.domain.entity.PostDetailsEntity
import com.signal.domain.entity.PostsEntity
import com.signal.domain.enums.Tag
import java.util.UUID

Expand Down Expand Up @@ -36,4 +36,6 @@ interface FeedRepository {
content: String,
image: String?,
): Result<Unit>

suspend fun reportFeed(feedId: UUID): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ internal fun SignalApp() {
moveToCreatePost = {
navController.navigate("${NavigationRoute.Main.CreatePost}/${it ?: " "}")
},
moveToReport = {
navController.navigate(NavigationRoute.Main.Report)
},
moveToDiagnosisLanding = {
navController.navigate(NavigationRoute.User.DiagnosisLanding)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.signal.signal_android.designsystem.component.SignalBottomBar
import com.signal.signal_android.feature.main.diary.Diary
import com.signal.signal_android.feature.main.feed.Feed
import com.signal.signal_android.feature.main.home.Home
import com.signal.signal_android.feature.main.recommend.Recommend
import com.signal.signal_android.feature.main.mypage.MyPage
import com.signal.signal_android.feature.main.recommend.Recommend
import com.signal.signal_android.navigation.NavigationRoute
import java.util.UUID

Expand All @@ -27,7 +27,6 @@ internal fun Main(
moveToLanding: () -> Unit,
moveToFeedDetails: (feedId: UUID) -> Unit,
moveToCreatePost: (feedId: UUID?) -> Unit,
moveToReport: () -> Unit,
moveToDiagnosisLanding: () -> Unit,
moveToCreateDiary: () -> Unit,
moveToDiaryDetails: (diaryId: UUID) -> Unit,
Expand Down Expand Up @@ -82,7 +81,6 @@ internal fun Main(
Feed(
moveToFeedDetails = moveToFeedDetails,
moveToCreatePost = moveToCreatePost,
moveToReport = moveToReport,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ import java.util.UUID
internal fun Feed(
moveToFeedDetails: (feedId: UUID) -> Unit,
moveToCreatePost: (feedId: UUID?) -> Unit,
moveToReport: () -> Unit,
feedViewModel: FeedViewModel = koinViewModel(),
) {
val state by feedViewModel.state.collectAsState()

var expanded by remember { mutableStateOf(UUID.randomUUID()) }

var showDialog by remember { mutableStateOf(false) }
var showDeleteDialog by remember { mutableStateOf(false) }
var showReportDialog by remember { mutableStateOf(false) }

val alpha by animateFloatAsState(
targetValue = if (state.posts.isEmpty()) 1f else 0f,
Expand All @@ -80,19 +80,32 @@ internal fun Feed(
feedViewModel.fetchPosts()
}

if (showDialog) {
Dialog(onDismissRequest = { showDialog = false }) {
if (showDeleteDialog) {
Dialog(onDismissRequest = { showDeleteDialog = false }) {
SignalDialog(
title = stringResource(id = R.string.feed_delete_dialog_title),
onCancelBtnClick = { showDialog = false },
onCancelBtnClick = { showDeleteDialog = false },
onCheckBtnClick = {
showDialog = false
showDeleteDialog = false
feedViewModel.deletePost()
},
)
}
}

if (showReportDialog) {
Dialog(onDismissRequest = { showReportDialog = false }) {
SignalDialog(
title = stringResource(id = R.string.feed_report_dialog_title),
onCancelBtnClick = { showReportDialog = false },
onCheckBtnClick = {
showReportDialog = false
feedViewModel.reportFeed()
},
)
}
}

var filterExpanded by remember { mutableStateOf(false) }

Box(
Expand Down Expand Up @@ -123,15 +136,15 @@ internal fun Feed(
Box {
Posts(
moveToFeedDetails = moveToFeedDetails,
moveToReport = moveToReport,
moveToReport = { showReportDialog = true },
posts = { state.posts },
showDropDown = {
feedViewModel.setFeedId(it)
expanded = it
},
expanded = expanded,
onDismissRequest = { expanded = UUID.randomUUID() },
onDelete = { showDialog = true },
onDelete = { showDeleteDialog = true },
onEdit = { moveToCreatePost(state.feedId) },
nextPage = {
if (state.hasNextPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sealed interface FeedSideEffect {
object DeleteSuccess: FeedSideEffect
object ClearFocus: FeedSideEffect
object CommentSuccess: FeedSideEffect
object ReportSuccess: FeedSideEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ internal class FeedViewModel(
}
}

internal fun reportFeed() {
with(state.value) {
if (feedId != null) {
viewModelScope.launch(Dispatchers.IO) {
feedRepository.reportFeed(feedId = feedId).onSuccess {
postSideEffect(FeedSideEffect.ReportSuccess)
}.onFailure {
if (it is KotlinNullPointerException) {
postSideEffect(FeedSideEffect.ReportSuccess)
}
}
}
}
}
}

internal fun nextPage() {
with(state.value) {
setState(copy(page = page + 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal fun Home(
rippleEnabled = true,
onClick = {},
),
model = state.profile ?: R.drawable.ic_profile_image,
model = myPageState.profile ?: R.drawable.ic_profile_image,
contentDescription = stringResource(id = R.string.my_page_profile_image),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal fun NavGraphBuilder.mainNavigation(
moveToFeedDetails: (feedId: UUID) -> Unit,
moveToBack: () -> Unit,
moveToCreatePost: (feedId: UUID?) -> Unit,
moveToReport: () -> Unit,
moveToDiagnosisLanding: () -> Unit,
moveToCreateDiary: () -> Unit,
moveToDiaryDetails: (diaryId: UUID) -> Unit,
Expand All @@ -53,7 +52,6 @@ internal fun NavGraphBuilder.mainNavigation(
moveToLanding = moveToLanding,
moveToFeedDetails = moveToFeedDetails,
moveToCreatePost = moveToCreatePost,
moveToReport = moveToReport,
moveToDiagnosisLanding = moveToDiagnosisLanding,
moveToCreateDiary = moveToCreateDiary,
moveToDiaryDetails = moveToDiaryDetails,
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<string name="feed_posts_is_empty">์•„์ง ๊ฒŒ์‹œ๊ธ€์ด ์—†์–ด์š”!</string>
<string name="feed_posts_add">๊ฒŒ์‹œ๊ธ€ ์ž‘์„ฑํ•˜๊ธฐ</string>
<string name="feed_filter">ํ”ผ๋“œ ํ•„ํ„ฐ</string>
<string name="feed_report_dialog_title">์ •๋ง ์‹ ๊ณ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?</string>

<!--recommend-->
<string name="recommend_search">์ถ”์ฒœ ๊ฒ€์ƒ‰</string>
Expand Down

0 comments on commit 061e6f8

Please sign in to comment.