Skip to content

Commit

Permalink
[Merge] #40 -> develop
Browse files Browse the repository at this point in the history
[Feat/#40] 신고페이지 POST API 연결
  • Loading branch information
chrin05 authored Nov 28, 2024
2 parents 7d7ca0e + deaef91 commit 4746cf8
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sopt.shinmungo.data.dto.request

import com.sopt.shinmungo.domain.entity.ReportPhotoItem
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ReportRequest(
@SerialName("photoList")
val photoList: List<ReportPhotoItem>,
@SerialName("address")
val address: String,
@SerialName("content")
val content: String,
@SerialName("phoneNumber")
val phoneNumber: String,
@SerialName("category")
val category: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sopt.shinmungo.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ReportResponse(
@SerialName("reportId")
val reportId: Int,
@SerialName("photoList")
val photoList: List<PhotoDto>,
@SerialName("address")
val address: String,
@SerialName("content")
val content: String,
@SerialName("phoneNumber")
val phoneNumber: String,
@SerialName("category")
val category: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sopt.shinmungo.data.remote
import com.sopt.shinmungo.data.service.HomeService
import com.sopt.shinmungo.data.service.AllCategoryService
import com.sopt.shinmungo.data.service.GalleryService
import com.sopt.shinmungo.data.service.ReportService

object ServicePool {
val allCategoryService: AllCategoryService by lazy {
Expand All @@ -17,4 +18,8 @@ object ServicePool {
val homeService by lazy {
ApiFactory.create<HomeService>()
}

val reportService by lazy {
ApiFactory.create<ReportService>()
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/sopt/shinmungo/data/service/ReportService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sopt.shinmungo.data.service

import com.sopt.shinmungo.data.dto.BaseResponse
import com.sopt.shinmungo.data.dto.request.ReportRequest
import com.sopt.shinmungo.data.dto.response.ReportResponse
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface ReportService {
@POST("report")
suspend fun postReport(
@Header("userId") userId: Long,
@Body request: ReportRequest
): BaseResponse<ReportResponse>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.sopt.shinmungo.domain.entity

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ReportPhotoItem(
@SerialName("photoId")
val photoId: Int,
@SerialName("photoUrl")
val photoUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sopt.shinmungo.domain.repository

import com.sopt.shinmungo.data.dto.request.ReportRequest
import com.sopt.shinmungo.data.dto.response.ReportResponse
import com.sopt.shinmungo.data.remote.ServicePool

class ReportRepository {
private val service = ServicePool.reportService

suspend fun postReport(userId: Long, request: ReportRequest): Result<ReportResponse> = runCatching {
val response = service.postReport(userId, request)
response.data ?: throw Throwable("Failed to post report")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ object RepositoryPool {
val homeRepository by lazy {
HomeRepository()
}

val reportRepository by lazy {
ReportRepository()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,14 @@ fun ReportScreen(
cameraCooldownTime = cameraCooldownTime.value,
isCameraButtonActive = isCameraButtonActive.value,
onCameraButtonClick = {
/*viewModel.startCameraCooldown(300)*/
viewModel.updateDialogVisibility(ReportDialogType.CAMERA_SELECTION)
},
onGalleryButtonClick = {
viewModel.updateDialogVisibility(ReportDialogType.GALLERY_SELECTION)
/* 갤러리 화면으로 이동 *//*
val newPhotoList = arrayListOf(
// 임시로 값 연결
ReportPhotoItem(1, "https://via.placeholder.com/70"),
ReportPhotoItem(2, "https://via.placeholder.com/70"),
ReportPhotoItem(3, "https://via.placeholder.com/70"),
ReportPhotoItem(4, "https://via.placeholder.com/70"),
)
viewModel.updatePhotoList(newPhotoList)*/
},
onDeleteButtonClick = {
viewModel.updateDeletePhoto(it)
viewModel.updateDialogVisibility(ReportDialogType.PHOTO_DELETE)
//viewModel.deletePhotoFromList(it)
},
showDeleteIcons = showDeleteIcons.value,
onClickShowDeleteIcon = { viewModel.showDeleteIconForPhoto(it) },
Expand All @@ -148,7 +137,6 @@ fun ReportScreen(
location = location.value,
onLocationButtonClick = {
onMoveToMapClick()
//viewModel.updateLocation(selectedLocation)
}
)

Expand Down Expand Up @@ -235,7 +223,7 @@ fun ReportScreen(
onMoveToHomeClick()
},
onResetClick = {
// TODO: 모든 입력값들 지우는 로직
viewModel.resetContent()
},
onPhotoDeleteConfirm = {
viewModel.deletePhotoFromList()
Expand All @@ -244,10 +232,7 @@ fun ReportScreen(
onMoveToGalleryClick()
},
onCameraSelectionConfirm = { viewModel.startCameraCooldown(300) },
onSubmitConfirmClick = {
// TODO: api 통신 후 성공하면 다이얼로그 띄우기
viewModel.updateDialogVisibility(ReportDialogType.SUBMIT)
}
onSubmitConfirmClick = { viewModel.postReport() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.sopt.shinmungo.presentation.report

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.shinmungo.data.dto.request.ReportRequest
import com.sopt.shinmungo.domain.entity.ReportPhotoItem
import com.sopt.shinmungo.domain.repository.ReportRepository
import com.sopt.shinmungo.domain.repository.RepositoryPool
import com.sopt.shinmungo.presentation.report.state.ReportDialogState
import com.sopt.shinmungo.presentation.report.type.ReportDialogType
import kotlinx.coroutines.Job
Expand All @@ -17,6 +20,8 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

class ReportViewModel : ViewModel() {
private val repository: ReportRepository = RepositoryPool.reportRepository

val illegalParkingCategory = listOf(
"소화전",
"교차로 모퉁이",
Expand All @@ -30,8 +35,9 @@ class ReportViewModel : ViewModel() {
"친환경차 전용구역"
)

private val _dialogState: MutableStateFlow<ReportDialogState> = MutableStateFlow(ReportDialogState())
val dialogState:StateFlow<ReportDialogState> = _dialogState.asStateFlow()
private val _dialogState: MutableStateFlow<ReportDialogState> =
MutableStateFlow(ReportDialogState())
val dialogState: StateFlow<ReportDialogState> = _dialogState.asStateFlow()

private val _deletePhoto: MutableStateFlow<ReportPhotoItem?> = MutableStateFlow(null)
val deletePhoto: StateFlow<ReportPhotoItem?> get() = _deletePhoto.asStateFlow()
Expand Down Expand Up @@ -111,18 +117,12 @@ class ReportViewModel : ViewModel() {

fun updateIsDropdownOpen() {
_isDropdownOpen.value = !_isDropdownOpen.value
if (_isDropdownOpen.value) {
_selectedCategory.value = "불법 주정차 신고"
}
}

fun updatePhotoList(newPhotoList: List<ReportPhotoItem>) {
_photoList.value = newPhotoList
}

/*fun deletePhotoFromList(deletePhoto: ReportPhotoItem) {
_photoList.value = _photoList.value.filter { it.photoId != deletePhoto.photoId }
}*/
fun deletePhotoFromList() {
_photoList.value = _photoList.value.filter { it.photoId != deletePhoto.value?.photoId }
}
Expand Down Expand Up @@ -169,7 +169,19 @@ class ReportViewModel : ViewModel() {
}

fun updateDeletePhoto(deletePhoto: ReportPhotoItem) {
_deletePhoto.value = deletePhoto
_deletePhoto.value = deletePhoto
}

fun resetContent() {
_isCategorySelected.value = false
_selectedCategory.value = ""
_photoList.value = emptyList()
_location.value = ""
_content.value = ""
_isRecommendWord.value = false
_isReportSharingAgreed.value = false
_cameraCooldownTime.value = 0
_isCameraButtonActive.value = false
}

fun updateDialogVisibility(type: ReportDialogType) {
Expand Down Expand Up @@ -230,6 +242,23 @@ class ReportViewModel : ViewModel() {
}
}

fun postReport() = viewModelScope.launch {
val request = ReportRequest(
photoList = photoList.value,
address = location.value,
content = content.value,
phoneNumber = phoneNumber.value,
category = "PARKING"
)
repository.postReport(userId = 1, request = request)
.onSuccess { homeInformation ->
updateDialogVisibility(ReportDialogType.SUBMIT)
}
.onFailure { exception ->
exception.printStackTrace()
}
}

companion object {
const val RECOMMEND_WORD_CONTEXT = "소방차 전용구역 불법주차 신고입니다."
const val USER_PHONE_NUMBER = "010-1234-5678"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.sopt.shinmungo.core.designsystem.theme.ShinMunGoTheme
@Composable
fun CategoryGrid(
illegalParkingCategory: List<String>,
selectedCategory: String,
updateSelectedCategory: (String) -> Unit,
updateIsDropDownOpen: () -> Unit,
modifier: Modifier = Modifier
Expand All @@ -34,9 +35,9 @@ fun CategoryGrid(
item(span = { GridItemSpan(2) }) {
CategoryButton(
category = category,
isClicked = false,
onCategoryButtonClick = { selectedCategory ->
updateSelectedCategory(selectedCategory)
isClicked = selectedCategory == category,
onCategoryButtonClick = {
updateSelectedCategory(category)
updateIsDropDownOpen()
},
)
Expand All @@ -55,9 +56,9 @@ fun CategoryGrid(
item {
CategoryButton(
category = category,
isClicked = false,
onCategoryButtonClick = { selectedCategory ->
updateSelectedCategory(selectedCategory)
isClicked = selectedCategory == category,
onCategoryButtonClick = {
updateSelectedCategory(category)
updateIsDropDownOpen()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ fun DropdownCategory(
Column {
Row {
val text =
if (selectedCategory.isEmpty()) stringResource(R.string.report_select_report_type) else selectedCategory
val textStyle =
if (selectedCategory.isEmpty()) ShinMunGoTheme.typography.body6 else ShinMunGoTheme.typography.body4
val textColor =
if (selectedCategory.isEmpty()) ShinMunGoTheme.color.primary else ShinMunGoTheme.color.gray13
val spacerModifier = Modifier.width(if (selectedCategory.isEmpty()) 10.dp else 8.dp)
if (isDropdownOpen) stringResource(R.string.report_reporting_illegal_parking)
else selectedCategory.ifEmpty { stringResource(R.string.report_select_report_type) }
val isEmptyAndClosed = selectedCategory.isEmpty() && !isDropdownOpen
val textStyle = if (isEmptyAndClosed) ShinMunGoTheme.typography.body6 else ShinMunGoTheme.typography.body4
val textColor = if (isEmptyAndClosed) ShinMunGoTheme.color.primary else ShinMunGoTheme.color.gray13
val spacerModifier = Modifier.width(if (isEmptyAndClosed) 10.dp else 8.dp)

TextWithInfoIcon(
text = text,
Expand All @@ -81,6 +81,7 @@ fun DropdownCategory(
if (isDropdownOpen) {
CategoryGrid(
illegalParkingCategory = illegalParkingCategory,
selectedCategory = selectedCategory,
updateSelectedCategory = { updateSelectedCategory(it) },
updateIsDropDownOpen = updateIsDropDownOpen
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fun ShowPhotoList(
photoItem = photoItem,
showDeleteIcon = showDelete,
onDelete = {
/* 다이얼로그 연결 */
onDelete(it)
},
onClick = {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="report_to_next_photo_apply">다음 사진 첨부까지 :</string>
<string name="report_add_photo_placeholder">사진을 추가해주세요</string>
<string name="report_phone_number_placeholder">전화번호를 입력해주세요</string>
<string name="report_reporting_illegal_parking">불법 주정차 신고</string>

<!--Button Component-->
<string name="check_button_content_description">체크 아이콘</string>
Expand Down

0 comments on commit 4746cf8

Please sign in to comment.