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] 대댓글 추가 연동 및 BottomSheet 수정 #86

Merged
merged 1 commit into from
Jan 19, 2024
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
7 changes: 7 additions & 0 deletions data/src/main/java/com/kusitms/data/remote/api/KusitmsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ interface KusitmsApi {
@Path("commentId") commentId: Int,
): BaseResponse<List<CommentPayload>>

@POST("v1/comment/{noticeId}/{commentId}")
suspend fun addNoticeChildComment(
@Path("noticeId") noticeId: Int,
@Path("commentId") commentId: Int,
@Body commentContentRequestBody: CommentContentRequestBody,
): BaseResponse<CommentPayload>

Comment on lines +89 to +95
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에 남겨놓으신것처럼 스크린단이나 기능단 아니면 v1/v2로 분리할 필요성이 있어보여서
메모용으로 코멘트 남겨놓을게요 고생하셨습니다 ✔️🙇🏻‍♀️

// SignInNonMember
@FormUrlEncoded
@POST("v1/member/check/register")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,25 @@ class NoticeRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun addNoticeChildComment(
noticeId: Int,
commentId: Int,
commentContentModel: CommentContentModel
): Result<CommentModel> {
return try {
val response = kusitmsApi.addNoticeChildComment(
noticeId = noticeId,
commentId = commentId,
commentContentRequestBody = commentContentModel.toBody()
)
if (response.result.code == 200 && response.payload != null) {
Result.success(response.payload.toModel())
} else {
Result.failure(RuntimeException("대댓글 등록 실패: ${response.result.message}"))
}
} catch (e: Exception){
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ interface NoticeRepository {
commentId: Int
) : Result<List<CommentModel>>

suspend fun addNoticeChildComment(
noticeId: Int,
commentId : Int,
commentContentModel: CommentContentModel
) : Result<CommentModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.kusitms.domain.usecase.notice

import com.kusitms.domain.model.notice.CommentContentModel
import com.kusitms.domain.repository.NoticeRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class AddNoticeChildCommentUseCase @Inject constructor(
private val noticeRepository: NoticeRepository
) {
operator fun invoke(
noticeId : Int,
commentId : Int,
content : CommentContentModel
): Flow<Unit> = flow {
noticeRepository.addNoticeChildComment(
noticeId = noticeId,
commentId = commentId,
commentContentModel = content
).onSuccess {
//TODO 타입 변경
emit(Unit)
}.onFailure {
throw it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -42,13 +46,10 @@ import com.kusitms.domain.model.notice.CommentModel
import com.kusitms.presentation.common.ui.KusitmsMarginVerticalSpacer
import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette
import com.kusitms.presentation.common.ui.theme.KusitmsTypo
import com.kusitms.presentation.model.notice.CommentUiModel
import com.kusitms.presentation.ui.ImageVector.icons.KusitmsIcons
import com.kusitms.presentation.ui.ImageVector.icons.kusitmsicons.Close
import com.kusitms.presentation.ui.notice.detail.comment.CommentInput
import com.kusitms.presentation.ui.notice.detail.comment.NoticeComment
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@Composable
fun BottomSheetDrawerBar(
Expand All @@ -61,10 +62,13 @@ fun BottomSheetDrawerBar(
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NoticeCommentBottom(
noticeDetailViewModel: NoticeDetailViewModel = hiltViewModel(),
targetComment : CommentModel
targetComment : CommentModel,
onClickChildReport : (NoticeDetailModalState.Report) -> Unit,
onClickChildDelete : (NoticeDetailDialogState.CommentDelete) -> Unit
){
val childCommentList by noticeDetailViewModel.childCommentList.collectAsStateWithLifecycle()

Expand All @@ -74,8 +78,6 @@ fun NoticeCommentBottom(
targetComment.commentId
)
}


Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -117,11 +119,15 @@ fun NoticeCommentBottom(
NoticeComment(
comment = comment,
onClickReport = {
// openBottomSheet =
// NoticeDetailModalState.Report(comment, comment.writerId)
onClickChildReport(
NoticeDetailModalState.Report(comment, comment.writerId)
)
},
onClickDelete = {
//openDialogState = NoticeDetailDialogState.CommentDelete(comment)
onClickChildDelete(
NoticeDetailDialogState.CommentDelete(comment)
)

},
isLast = index == childCommentList.lastIndex
)
Expand All @@ -133,7 +139,7 @@ fun NoticeCommentBottom(
CommentInput(
modifier = Modifier.padding(bottom = 42.dp),
onClickSend = {

noticeDetailViewModel.addNoticeChildComment(targetComment.commentId,it)
}
)
}
Expand Down Expand Up @@ -269,6 +275,7 @@ fun NoticeCommentReportBottom(
boxPadding = PaddingValues(horizontal = 12.5.dp),
onClick = {
onClick(it)
onDismiss()
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ sealed class NoticeDetailDialogState() {

object AlreadyReport : NoticeDetailDialogState()

data class CommentDelete(val comment: CommentModel) : NoticeDetailDialogState()
data class CommentDelete(val comment: CommentModel,val isChild : Boolean = false) : NoticeDetailDialogState()
}

sealed class NoticeDetailModalState() {
Expand Down Expand Up @@ -143,6 +143,11 @@ fun NoticeDetailScreen(

var openDialogState by remember { mutableStateOf<NoticeDetailDialogState?>(null) }

var openBottomSheetInCommentModal by remember { mutableStateOf<NoticeDetailModalState?>(null) }
val bottomSheetStateInCommentModal = rememberModalBottomSheetState(
skipPartiallyExpanded = true
)

LaunchedEffect(key1 = Unit){
viewModel.snackbarEvent.collect {
onShowSnackbar(
Expand Down Expand Up @@ -276,7 +281,13 @@ fun NoticeDetailScreen(
is NoticeDetailModalState.Comment -> {
NoticeCommentBottom(
viewModel,
(openBottomSheet as NoticeDetailModalState.Comment).comment
(openBottomSheet as NoticeDetailModalState.Comment).comment,
onClickChildReport = {
openBottomSheetInCommentModal = it
},
onClickChildDelete = {
openDialogState = it
}
)
}

Expand All @@ -294,13 +305,50 @@ fun NoticeDetailScreen(
memberId = reportState.memberId
)
}

},
onDismiss = {
openBottomSheet = null
}
)
}
}


}
}
if (openBottomSheetInCommentModal is NoticeDetailModalState.Report) {
ModalBottomSheet(
containerColor = KusitmsColorPalette.current.Grey600,
dragHandle = { Box(Modifier.height(0.dp)) },
onDismissRequest = { openBottomSheetInCommentModal = null },
sheetState = bottomSheetStateInCommentModal,
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
) {
when (openBottomSheetInCommentModal ?: return@ModalBottomSheet) {
is NoticeDetailModalState.Report -> {
NoticeCommentReportBottom(
onClick = {
(openBottomSheetInCommentModal as NoticeDetailModalState.Report).let { reportState ->
openDialogState =
NoticeDetailDialogState.Report(
comment = reportState.comment,
report = it,
memberId = reportState.memberId
)

}

openBottomSheetInCommentModal = null
}
) {
openBottomSheet = null
openBottomSheetInCommentModal = null
}
}
else -> {

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.kusitms.domain.model.notice.CommentModel
import com.kusitms.domain.model.notice.NoticeModel
import com.kusitms.domain.model.notice.ReportCommentContentModel
import com.kusitms.domain.model.report.ReportResult
import com.kusitms.domain.usecase.notice.AddNoticeChildCommentUseCase
import com.kusitms.domain.usecase.notice.AddNoticeCommentUseCase
import com.kusitms.domain.usecase.notice.DeleteCommentUseCase
import com.kusitms.domain.usecase.notice.GetChildCommentListUseCase
Expand Down Expand Up @@ -36,7 +37,8 @@ class NoticeDetailViewModel @Inject constructor(
private val addNoticeCommentUseCase: AddNoticeCommentUseCase,
private val deleteCommentUseCase: DeleteCommentUseCase,
private val reportUseCase: ReportUseCase,
private val getChildCommentListUseCase : GetChildCommentListUseCase
private val getChildCommentListUseCase : GetChildCommentListUseCase,
private val addNoticeChildCommentUseCase : AddNoticeChildCommentUseCase
) : ViewModel() {

val noticeId: Int = savedStateHandle.get<Int>(NOTICE_ID_SAVED_STATE_KEY)!!
Expand Down Expand Up @@ -114,6 +116,24 @@ class NoticeDetailViewModel @Inject constructor(
}
}

fun addNoticeChildComment(
commentId: Int,
content : String
){
viewModelScope.launch {
addNoticeChildCommentUseCase(
noticeId = noticeId,
commentId = commentId,
content = CommentContentModel(content)
).catch {
_snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR)
}.collectLatest {
fetchCommentList()
_snackbarEvent.emit(NoticeDetailSnackbarEvent.ADDED_COMMENT)
}
}
}

fun deleteNoticeComment(
commentId : Int
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fun NoticeComment(
}

}
if(!isLast)
if(!isLast && !isParentCommentAsReply)
Divider(
modifier = Modifier
.fillMaxWidth()
Expand Down