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

πŸ”€ :: (#214) - Expo_Id의 νƒ€μž…μ„ Longμ—μ„œ String으둜 λ°˜ν™˜ν•©λ‹ˆλ‹€. #215

Merged
merged 11 commits into from
Nov 25, 2024
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.school_of_company.data.repository.expo

import com.school_of_company.model.entity.expo.ExpoIdResponseEntity
import com.school_of_company.model.entity.expo.ExpoListResponseEntity
import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel
import kotlinx.coroutines.flow.Flow

interface ExpoRepository {
fun getExpoList() : Flow<List<ExpoListResponseEntity>>
fun getExpoInformation(expoId: Long) : Flow<ExpoRequestAndResponseModel>
fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow<Unit>
fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponseModel) : Flow<Unit>
fun deleteExpoInformation(expoId: Long) : Flow<Unit>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponseModel>
fun registerExpoInformation(body: ExpoRequestAndResponseModel) : Flow<ExpoIdResponseEntity>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponseModel) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.school_of_company.data.repository.expo

import com.school_of_company.model.entity.expo.ExpoIdResponseEntity
import com.school_of_company.model.entity.expo.ExpoListResponseEntity
import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel
import com.school_of_company.network.datasource.expo.ExpoDataSource
Expand All @@ -19,18 +20,20 @@ class ExpoRepositoryImpl @Inject constructor(
}
}

override fun getExpoInformation(expoId: Long): Flow<ExpoRequestAndResponseModel> {
override fun getExpoInformation(expoId: String): Flow<ExpoRequestAndResponseModel> {
return dataSource.getExpoInformation(expoId = expoId).transform { response ->
emit(response.toModel())
}
}

override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow<Unit> {
return dataSource.registerExpoInformation(body = body.toDto())
override fun registerExpoInformation(body: ExpoRequestAndResponseModel): Flow<ExpoIdResponseEntity> {
return dataSource.registerExpoInformation(body = body.toDto()).transform { response ->
emit(response.toEntity())
}
}

override fun modifyExpoInformation(
expoId: Long,
expoId: String,
body: ExpoRequestAndResponseModel
): Flow<Unit> {
return dataSource.modifyExpoInformation(
Expand All @@ -39,7 +42,7 @@ class ExpoRepositoryImpl @Inject constructor(
)
}

override fun deleteExpoInformation(expoId: Long): Flow<Unit> {
override fun deleteExpoInformation(expoId: String): Flow<Unit> {
return dataSource.deleteExpoInformation(expoId = expoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.inject.Inject
class DeleteExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(expoId: Long) = runCatching {
operator fun invoke(expoId: String) = runCatching {
repository.deleteExpoInformation(expoId = expoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import javax.inject.Inject
class GetExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(expoId: Long) : Flow<ExpoRequestAndResponseModel> =
operator fun invoke(expoId: String) : Flow<ExpoRequestAndResponseModel> =
repository.getExpoInformation(expoId = expoId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ModifyExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(
expoId: Long,
expoId: String,
body: ExpoRequestAndResponseModel
) = runCatching {
repository.modifyExpoInformation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.school_of_company.domain.usecase.expo

import com.school_of_company.data.repository.expo.ExpoRepository
import com.school_of_company.model.entity.expo.ExpoIdResponseEntity
import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class RegisterExpoInformationUseCase @Inject constructor(
private val repository: ExpoRepository
) {
operator fun invoke(body: ExpoRequestAndResponseModel) = runCatching {
operator fun invoke(body: ExpoRequestAndResponseModel): Flow<ExpoIdResponseEntity> =
repository.registerExpoInformation(body = body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.school_of_company.model.entity.expo

data class ExpoIdResponseEntity(
val expoId: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.school_of_company.model.entity.expo

data class ExpoListResponseEntity(
val id: Long,
val id: String,
val title: String,
val description: String,
val startedDay: String, // yyyy-mm-dd
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.school_of_company.network.api

import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse
import com.school_of_company.network.dto.expo.response.ExpoIdResponse
import com.school_of_company.network.dto.expo.response.ExpoListResponse
import retrofit2.http.*

Expand All @@ -11,22 +12,22 @@ interface ExpoAPI {

@GET("/expo/{expo_id}")
suspend fun getExpoInformation(
@Path("expo_id") expoId: Long
@Path("expo_id") expoId: String
) : ExpoRequestAndResponse

@POST("/expo")
suspend fun registerExpoInformation(
@Body body: ExpoRequestAndResponse
)
) : ExpoIdResponse

@PATCH("/expo/{expo_id}")
suspend fun modifyExpoInformation(
@Path("expo_id") expoId: Long,
@Path("expo_id") expoId: String,
@Body body: ExpoRequestAndResponse
)

@DELETE("/expo/{expo_id}")
suspend fun deleteExpoInformation(
@Path("expo_id") expoId: Long
@Path("expo_id") expoId: String
)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.school_of_company.network.datasource.expo

import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse
import com.school_of_company.network.dto.expo.response.ExpoIdResponse
import com.school_of_company.network.dto.expo.response.ExpoListResponse
import kotlinx.coroutines.flow.Flow

interface ExpoDataSource {
fun getExpoList() : Flow<List<ExpoListResponse>>
fun getExpoInformation(expoId: Long) : Flow<ExpoRequestAndResponse>
fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow<Unit>
fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponse) : Flow<Unit>
fun deleteExpoInformation(expoId: Long) : Flow<Unit>
fun getExpoInformation(expoId: String) : Flow<ExpoRequestAndResponse>
fun registerExpoInformation(body: ExpoRequestAndResponse) : Flow<ExpoIdResponse>
fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse) : Flow<Unit>
fun deleteExpoInformation(expoId: String) : Flow<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.school_of_company.network.datasource.expo

import com.school_of_company.network.api.ExpoAPI
import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse
import com.school_of_company.network.dto.expo.response.ExpoIdResponse
import com.school_of_company.network.dto.expo.response.ExpoListResponse
import com.school_of_company.network.util.performApiRequest
import kotlinx.coroutines.flow.Flow
Expand All @@ -13,18 +14,18 @@ class ExpoDataSourceImpl @Inject constructor(
override fun getExpoList(): Flow<List<ExpoListResponse>> =
performApiRequest { service.getExpoList() }

override fun getExpoInformation(expoId: Long): Flow<ExpoRequestAndResponse> =
override fun getExpoInformation(expoId: String): Flow<ExpoRequestAndResponse> =
performApiRequest { service.getExpoInformation(expoId = expoId) }

override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow<Unit> =
override fun registerExpoInformation(body: ExpoRequestAndResponse): Flow<ExpoIdResponse> =
performApiRequest { service.registerExpoInformation(body = body) }

override fun modifyExpoInformation(expoId: Long, body: ExpoRequestAndResponse): Flow<Unit> =
override fun modifyExpoInformation(expoId: String, body: ExpoRequestAndResponse): Flow<Unit> =
performApiRequest { service.modifyExpoInformation(
expoId = expoId,
body = body
) }

override fun deleteExpoInformation(expoId: Long): Flow<Unit> =
override fun deleteExpoInformation(expoId: String): Flow<Unit> =
performApiRequest { service.deleteExpoInformation(expoId = expoId) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.school_of_company.network.dto.expo.response

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ExpoIdResponse(
@Json(name = "expoId") val expoId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ExpoListResponse(
@Json(name = "id") val id: Long,
@Json(name = "id") val id: String,
@Json(name = "title") val title: String,
@Json(name = "description") val description: String,
@Json(name = "startedDay") val startedDay: String, // yyyy-mm-dd
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.school_of_company.network.mapper.expo.response

import com.school_of_company.model.entity.expo.ExpoIdResponseEntity
import com.school_of_company.network.dto.expo.response.ExpoIdResponse

fun ExpoIdResponse.toEntity(): ExpoIdResponseEntity =
ExpoIdResponseEntity(expoId = this.expoId)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun NavController.navigateToHome(navOptions: NavOptions? = null) {
}

fun NavController.navigateToExpoDetail(
id: Long,
id: String,
navOptions: NavOptions? = null
) {
this.navigate(
Expand All @@ -29,7 +29,7 @@ fun NavController.navigateToExpoDetail(
}

fun NavController.navigateToExpoModify(
id: Long,
id: String,
navOptions: NavOptions? = null
) {
this.navigate(
Expand All @@ -43,7 +43,7 @@ fun NavController.navigateToExpoCreate(navOptions: NavOptions? = null) {
}

fun NavGraphBuilder.expoScreen(
navigationToDetail: (Long) -> Unit
navigationToDetail: (String) -> Unit
) {
composable(route = homeRoute) {
ExpoRoute(
Expand All @@ -57,22 +57,20 @@ fun NavGraphBuilder.expoDetailScreen(
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit
) {
composable(route = "$expoDetailRoute/{id}") { backStackEntry ->
val id = backStackEntry.arguments?.getString("id")?.toLongOrNull()
if (id != null) {
ExpoDetailRoute(
id = id,
onBackClick = onBackClick,
onMessageClick = onMessageClick,
onCheckClick = onCheckClick,
onQrGenerateClick = onQrGenerateClick,
onModifyClick = onModifyClick,
onProgramClick = onProgramClick
)
}
val id = backStackEntry.arguments?.getString("id") ?: ""
ExpoDetailRoute(
id = id,
onBackClick = onBackClick,
onMessageClick = onMessageClick,
onCheckClick = onCheckClick,
onQrGenerateClick = onQrGenerateClick,
onModifyClick = onModifyClick,
onProgramClick = onProgramClick
)
audgns10 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -81,14 +79,12 @@ fun NavGraphBuilder.expoModifyScreen(
onErrorToast: (throwable: Throwable?, message: Int?) -> Unit
) {
composable(route = "$expoModifyRoute/{id}") { backStackEntry ->
val id = backStackEntry.arguments?.getString("id")?.toLongOrNull()
if (id != null) {
ExpoModifyRoute(
id = id,
onBackClick = onBackClick,
onErrorToast = onErrorToast
)
}
val id = backStackEntry.arguments?.getString("id") ?: ""
ExpoModifyRoute(
id = id,
onBackClick = onBackClick,
onErrorToast = onErrorToast
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ internal fun ExpoCreateRoute(
is RegisterExpoInformationUiState.Loading -> Unit
is RegisterExpoInformationUiState.Success -> {
viewModel.resetExpoInformation()
selectedImageUri = null
makeToast(context, "λ°•λžŒνšŒ 등둝을 μ™„λ£Œν•˜μ˜€μŠ΅λ‹ˆλ‹€.")
}
is RegisterExpoInformationUiState.Error -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ import com.school_of_company.ui.util.formatServerDate

@Composable
internal fun ExpoDetailRoute(
id: Long,
id: String,
onBackClick: () -> Unit,
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
Expand All @@ -82,7 +82,7 @@ internal fun ExpoDetailRoute(

@Composable
internal fun ExpoDetailScreen(
id: Long,
id: String,
modifier: Modifier = Modifier,
scrollState: ScrollState = rememberScrollState(),
getExpoInformationUiState: GetExpoInformationUiState,
Expand All @@ -91,7 +91,7 @@ internal fun ExpoDetailScreen(
onMessageClick: () -> Unit,
onCheckClick: () -> Unit,
onQrGenerateClick: () -> Unit,
onModifyClick: (Long) -> Unit,
onModifyClick: (String) -> Unit,
onProgramClick: () -> Unit
) {
val (openDialog, isOpenDialog) = rememberSaveable { mutableStateOf(false) }
Expand Down Expand Up @@ -421,6 +421,6 @@ private fun HomeDetailScreenPreview() {
onProgramClick = {},
qrData = QrCode(content = "121231342352"),
getExpoInformationUiState = GetExpoInformationUiState.Loading,
id = 0
id = ""
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import com.school_of_company.ui.toast.makeToast
@Composable
internal fun ExpoModifyRoute(
onBackClick: () -> Unit,
id: Long,
id: String,
onErrorToast: (throwable: Throwable?, message: Int?) -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import kotlinx.collections.immutable.toImmutableList

@Composable
internal fun ExpoRoute(
navigationToDetail: (Long) -> Unit,
navigationToDetail: (String) -> Unit,
viewModel: ExpoViewModel = hiltViewModel()
) {
val swipeRefreshLoading by viewModel.swipeRefreshLoading.collectAsStateWithLifecycle()
Expand All @@ -74,7 +74,7 @@ internal fun ExpoScreen(
swipeRefreshState: SwipeRefreshState,
getExpoListData: GetExpoListUiState,
getExpoList: () -> Unit,
navigationToDetail: (Long) -> Unit
navigationToDetail: (String) -> Unit
) {
var filterButtonText by rememberSaveable { mutableStateOf("μ΅œμ‹ μˆœ") }

Expand Down
Loading
Loading