Skip to content

Commit

Permalink
feat(report): gửi report lên server
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Dec 4, 2024
1 parent 709a356 commit 29afe46
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.pwhs.quickmem.data.remote.repository.ClassRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.FlashCardRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.FolderRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.NotificationRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.ReportRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.StreakRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.StudySetRepositoryImpl
import com.pwhs.quickmem.data.remote.repository.StudyTimeRepositoryImpl
Expand All @@ -15,6 +16,7 @@ import com.pwhs.quickmem.domain.repository.ClassRepository
import com.pwhs.quickmem.domain.repository.FlashCardRepository
import com.pwhs.quickmem.domain.repository.FolderRepository
import com.pwhs.quickmem.domain.repository.NotificationRepository
import com.pwhs.quickmem.domain.repository.ReportRepository
import com.pwhs.quickmem.domain.repository.SearchQueryRepository
import com.pwhs.quickmem.domain.repository.StreakRepository
import com.pwhs.quickmem.domain.repository.StudySetRepository
Expand Down Expand Up @@ -77,4 +79,9 @@ abstract class RepositoryModule {
abstract fun bindStudyTimeRepository(
studyTimeRepositoryImpl: StudyTimeRepositoryImpl
): StudyTimeRepository

@Binds
abstract fun bindReportRepository(
reportRepositoryImpl: ReportRepositoryImpl
): ReportRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pwhs.quickmem.data.dto.report

import com.google.gson.annotations.SerializedName

data class CreateReportRequestDto(
@SerializedName("reason")
val reason: String,
@SerializedName("reportedEntityId")
val reportedEntityId: String,
@SerializedName("ownerOfReportedEntityId")
val ownerOfReportedEntityId: String,
@SerializedName("reportedType")
val reportedType: String,
@SerializedName("reporterId")
val reporterId: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pwhs.quickmem.data.mapper.report

import com.pwhs.quickmem.data.dto.report.CreateReportRequestDto
import com.pwhs.quickmem.domain.model.report.CreateReportRequestModel

fun CreateReportRequestModel.toDto(): CreateReportRequestDto {
return CreateReportRequestDto(
reason = reason,
reportedEntityId = reportedEntityId,
ownerOfReportedEntityId = ownerOfReportedEntityId,
reportedType = reportedType,
reporterId = reporterId
)
}

fun CreateReportRequestDto.toModel(): CreateReportRequestModel {
return CreateReportRequestModel(
reason = reason,
reportedEntityId = reportedEntityId,
ownerOfReportedEntityId = ownerOfReportedEntityId,
reportedType = reportedType,
reporterId = reporterId
)
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/pwhs/quickmem/data/remote/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.pwhs.quickmem.data.dto.notification.GetNotificationResponseDto
import com.pwhs.quickmem.data.dto.notification.MarkNotificationReadRequestDto
import com.pwhs.quickmem.data.dto.notification.DeviceTokenRequestDto
import com.pwhs.quickmem.data.dto.flashcard.WriteStatusFlashCardDto
import com.pwhs.quickmem.data.dto.report.CreateReportRequestDto
import com.pwhs.quickmem.data.dto.streak.GetStreakDto
import com.pwhs.quickmem.data.dto.streak.GetTopStreakResponseDto
import com.pwhs.quickmem.data.dto.streak.IncreaseStreakDto
Expand Down Expand Up @@ -637,4 +638,11 @@ interface ApiService {
@Body createStudyTimeDto: CreateStudyTimeDto
)

// Report
@POST("report")
suspend fun createReport(
@Header("Authorization") token: String,
@Body createReportRequestDto: CreateReportRequestDto
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.pwhs.quickmem.data.remote.repository

import com.pwhs.quickmem.core.utils.Resources
import com.pwhs.quickmem.data.mapper.report.toDto
import com.pwhs.quickmem.data.remote.ApiService
import com.pwhs.quickmem.domain.model.report.CreateReportRequestModel
import com.pwhs.quickmem.domain.repository.ReportRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class ReportRepositoryImpl @Inject constructor(
private val apiService: ApiService
) : ReportRepository {
override suspend fun createReport(
token: String,
createReportRequestModel: CreateReportRequestModel
): Flow<Resources<Unit>> {
return flow {
emit(Resources.Loading())
try {
val response = apiService.createReport(
token = token,
createReportRequestDto = createReportRequestModel.toDto()
)
emit(Resources.Success(response))
} catch (e: Exception) {
emit(Resources.Error(e.message ?: "An error occurred"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pwhs.quickmem.domain.model.report

data class CreateReportRequestModel(
val reason: String,
val reportedEntityId: String,
val ownerOfReportedEntityId: String,
val reportedType: String,
val reporterId: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pwhs.quickmem.domain.repository

import com.pwhs.quickmem.core.utils.Resources
import com.pwhs.quickmem.domain.model.report.CreateReportRequestModel
import kotlinx.coroutines.flow.Flow

interface ReportRepository {
suspend fun createReport(
token: String,
createReportRequestModel: CreateReportRequestModel,
): Flow<Resources<Unit>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ fun ClassDetailScreen(
navigator.navigate(
ReportScreenDestination(
reportType = ReportTypeEnum.CLASS,
classId = uiState.id,
username = uiState.userResponseModel.username
reportedEntityId = uiState.id,
ownerOfReportedEntity = uiState.userResponseModel.id
)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderDetailStudySetList
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderDetailTopAppBar
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderMenuBottomSheet
import com.pwhs.quickmem.presentation.app.report.ReportTypeEnum
import com.pwhs.quickmem.presentation.app.study_set.detail.material.LearnModeCard
import com.pwhs.quickmem.presentation.component.LoadingOverlay
import com.pwhs.quickmem.presentation.component.QuickMemAlertDialog
Expand All @@ -49,6 +50,7 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.generated.destinations.AddStudySetToFolderScreenDestination
import com.ramcosta.composedestinations.generated.destinations.EditFolderScreenDestination
import com.ramcosta.composedestinations.generated.destinations.FlipFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.ReportScreenDestination
import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScreenDestination
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
Expand Down Expand Up @@ -183,7 +185,16 @@ fun FolderDetailScreen(
userId = uiState.user.id
)
)
}
},
onReportClick = {
navigator.navigate(
ReportScreenDestination(
reportType = ReportTypeEnum.FOLDER,
reportedEntityId = uiState.id,
ownerOfReportedEntity = uiState.user.id
)
)
},
)
}

Expand All @@ -206,7 +217,8 @@ fun FolderDetail(
onLearnFlipFlashcardClick: () -> Unit = {},
onNavigateBack: () -> Unit = {},
onAddStudySet: () -> Unit = {},
onNavigateToUserDetail: () -> Unit = {}
onNavigateToUserDetail: () -> Unit = {},
onReportClick: () -> Unit = {}
) {
val context = LocalContext.current
val formattedCreatedAt = formatDate(createdAt)
Expand Down Expand Up @@ -314,7 +326,8 @@ fun FolderDetail(
showMoreBottomSheet = showMoreBottomSheet,
sheetShowMoreState = sheetShowMoreState,
onDismissRequest = { showMoreBottomSheet = false },
isOwner = isOwner
isOwner = isOwner,
onReportClick = onReportClick
)
if (showStudyFolderBottomSheet) {
ModalBottomSheet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material.icons.Icons.Outlined
import androidx.compose.material.icons.filled.DeleteOutline
import androidx.compose.material.icons.filled.IosShare
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material.icons.outlined.Report
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
Expand All @@ -31,6 +32,7 @@ fun FolderMenuBottomSheet(
showMoreBottomSheet: Boolean = false,
sheetShowMoreState: SheetState = rememberModalBottomSheetState(),
onDismissRequest: () -> Unit = {},
onReportClick: () -> Unit = {}
) {
if (showMoreBottomSheet) {
ModalBottomSheet(
Expand All @@ -42,7 +44,7 @@ fun FolderMenuBottomSheet(
modifier = Modifier
.fillMaxWidth()
) {
if (isOwner){
if (isOwner) {
ItemMenuBottomSheet(
onClick = onEditFolder,
icon = Outlined.Edit,
Expand All @@ -55,7 +57,16 @@ fun FolderMenuBottomSheet(
title = stringResource(R.string.txt_share_folder)
)

if (isOwner){
if (!isOwner) {
ItemMenuBottomSheet(
onClick = onReportClick,
icon = Outlined.Report,
title = stringResource(R.string.txt_report_folder),
)
}


if (isOwner) {
ItemMenuBottomSheet(
onClick = onDeleteFolder,
icon = Default.DeleteOutline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.pwhs.quickmem.presentation.app.report

data class ReportArgs(
val reportType: ReportTypeEnum,
val username: String? = null,
val studySetId: String? = null,
val classId: String? = null,
val userId: String? = null
val reportedEntityId: String,
val ownerOfReportedEntity: String,
)

Loading

0 comments on commit 29afe46

Please sign in to comment.