Skip to content

Commit

Permalink
Merge pull request #39 from team-haribo/feature/38-write-the-logic-ou…
Browse files Browse the repository at this point in the history
…ting-current-situation

🔀 :: (#38) -  write the logic outing current situation
  • Loading branch information
diejdkll authored Feb 4, 2024
2 parents de44dba + 303e76d commit a739429
Show file tree
Hide file tree
Showing 24 changed files with 458 additions and 20 deletions.
7 changes: 7 additions & 0 deletions core/data/src/main/java/com/goms/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.goms.data.repository.account.AccountRepository
import com.goms.data.repository.account.AccountRepositoryImpl
import com.goms.data.repository.auth.AuthRepository
import com.goms.data.repository.auth.AuthRepositoryImpl
import com.goms.data.repository.council.CouncilRepository
import com.goms.data.repository.council.CouncilRepositoryImpl
import com.goms.data.repository.late.LateRepository
import com.goms.data.repository.late.LateRepositoryImpl
import com.goms.data.repository.outing.OutingRepository
Expand Down Expand Up @@ -35,4 +37,9 @@ abstract class RepositoryModule {
abstract fun bindOutingRepository(
outingRepositoryImpl: OutingRepositoryImpl
): OutingRepository

@Binds
abstract fun bindCouncilRepository(
councilRepositoryImpl: CouncilRepositoryImpl
): CouncilRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goms.data.repository.council

import kotlinx.coroutines.flow.Flow
import java.util.UUID

interface CouncilRepository {
suspend fun deleteOuting(accountIdx: UUID): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.goms.data.repository.council

import com.goms.network.datasource.council.CouncilDataSource
import kotlinx.coroutines.flow.Flow
import java.util.UUID
import javax.inject.Inject

class CouncilRepositoryImpl @Inject constructor(
private val remoteCouncilDataSource: CouncilDataSource
) : CouncilRepository {
override suspend fun deleteOuting(accountIdx: UUID): Flow<Unit> {
return remoteCouncilDataSource.deleteOuting(accountIdx = accountIdx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface OutingRepository {
suspend fun getOutingList(): Flow<List<OutingResponse>>

suspend fun getOutingCount(): Flow<CountResponse>

suspend fun outingSearch(name: String): Flow<List<OutingResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ class OutingRepositoryImpl @Inject constructor(
override suspend fun getOutingCount(): Flow<CountResponse> {
return remoteOutingDataSource.getOutingCount()
}

override suspend fun outingSearch(name: String): Flow<List<OutingResponse>> {
return remoteOutingDataSource.outingSearch(name = name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.goms.design_system.component.dialog

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.goms.design_system.theme.GomsTheme

@Composable
fun GomsDialog(
openDialog: Boolean,
onStateChange: (Boolean) -> Unit,
title: String,
content: String,
dismissText: String,
checkText: String,
onDismissClick: () -> Unit,
onCheckClick: () -> Unit
) {
var openDialog by remember { mutableStateOf(openDialog) }

if (openDialog) {
Dialog(onDismissRequest = { openDialog = false }) {
GomsTheme { colors, typography ->
Card(
modifier = Modifier.width(280.dp),
shape = RoundedCornerShape(12.dp),
border = BorderStroke(width = 1.dp, color = colors.WHITE.copy(0.15f))
) {
Column(modifier = Modifier.background(colors.G1)) {
Column(
modifier = Modifier
.background(colors.G1)
.padding(top = 16.dp, start = 16.dp, end = 16.dp)
) {
Text(
text = title,
modifier = Modifier.fillMaxWidth(),
color = colors.WHITE,
style = typography.titleSmall,
fontWeight = FontWeight.SemiBold,
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = content,
modifier = Modifier.fillMaxWidth(),
color = colors.G7,
style = typography.textMedium,
fontWeight = FontWeight.Normal,
)
}
Row(
Modifier
.fillMaxWidth()
.height(64.dp)
.padding(end = 8.dp)
.background(colors.G1),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
TextButton(
modifier = Modifier
.weight(1f)
.height(60.dp),
onClick = {
openDialog = false
onDismissClick()
}
) {
Text(
text = dismissText,
color = colors.I5,
style = typography.textMedium,
fontWeight = FontWeight.Medium,
)
}
TextButton(
modifier = Modifier
.weight(1f)
.height(60.dp),
onClick = {
openDialog = false
onCheckClick()
}
) {
Text(
text = checkText,
color = colors.N5,
style = typography.textMedium,
fontWeight = FontWeight.Medium,
)
}
}
}
}
}
}
}
else {
onStateChange(openDialog)
}
}

@Preview(showBackground = true)
@Composable
fun GomsDialogPreview() {
GomsDialog(
openDialog = true,
onStateChange = {},
title = "외출 강제 복귀",
content = "외출자를 강제로 복귀시키시겠습니까?",
dismissText = "취소",
checkText = "복귀",
onDismissClick = {},
onCheckClick = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand All @@ -42,6 +43,7 @@ import com.goms.design_system.component.modifier.gomsClickable
import com.goms.design_system.component.timer.CountdownTimer
import com.goms.design_system.icon.SearchIcon
import com.goms.design_system.theme.GomsTheme
import kotlinx.coroutines.delay

@Composable
fun GomsTextField(
Expand Down Expand Up @@ -438,6 +440,7 @@ fun GomsPasswordTextField(
@Composable
fun GomsSearchTextField(
modifier: Modifier = Modifier,
debounceTime: Long = 300L,
placeHolder: String = "",
readOnly: Boolean = false,
focusManager: FocusManager = LocalFocusManager.current,
Expand All @@ -449,6 +452,7 @@ fun GomsSearchTextField(
singleLine: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
onValueChange: (String) -> Unit = {},
onSearchTextChange: (String) -> Unit = {}
) {
val isFocused = remember { mutableStateOf(false) }

Expand All @@ -458,6 +462,11 @@ fun GomsSearchTextField(
}
}

LaunchedEffect(setText) {
delay(debounceTime)
onSearchTextChange(setText)
}

GomsTheme { colors, typography ->
Column {
OutlinedTextField(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.council

import com.goms.data.repository.council.CouncilRepository
import java.util.UUID
import javax.inject.Inject

class DeleteOutingUseCase @Inject constructor(
private val councilRepository: CouncilRepository
) {
suspend operator fun invoke(accountIdx: UUID) = kotlin.runCatching {
councilRepository.deleteOuting(accountIdx = accountIdx)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.outing

import com.goms.data.repository.outing.OutingRepository
import com.goms.model.response.outing.OutingResponse
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class OutingSearchUseCase @Inject constructor(
private val outingRepository: OutingRepository
) {
suspend operator fun invoke(name: String): Flow<List<OutingResponse>> =
outingRepository.outingSearch(name = name)
}
12 changes: 12 additions & 0 deletions core/network/src/main/java/com/goms/network/api/CouncilAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.goms.network.api

import retrofit2.http.DELETE
import retrofit2.http.Path
import java.util.UUID

interface CouncilAPI {
@DELETE("/api/v2/student-council/outing/{accountIdx}")
suspend fun deleteOuting(
@Path("accountIdx") accountIdx: UUID
)
}
6 changes: 6 additions & 0 deletions core/network/src/main/java/com/goms/network/api/OutingAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package com.goms.network.api
import com.goms.model.response.outing.CountResponse
import com.goms.model.response.outing.OutingResponse
import retrofit2.http.GET
import retrofit2.http.Query

interface OutingAPI {
@GET("/api/v2/outing/")
suspend fun getOutingList(): List<OutingResponse>

@GET("/api/v2/outing/count")
suspend fun getOutingCount(): CountResponse

@GET("/api/v2/outing/search")
suspend fun outingSearch(
@Query("name") name: String
): List<OutingResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goms.network.datasource.council

import kotlinx.coroutines.flow.Flow
import java.util.UUID

interface CouncilDataSource {
suspend fun deleteOuting(accountIdx: UUID): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.goms.network.datasource.council

import com.goms.network.api.CouncilAPI
import com.goms.network.util.GomsApiHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import java.util.UUID
import javax.inject.Inject

class CouncilDataSourceImpl @Inject constructor(
private val councilAPI: CouncilAPI
) : CouncilDataSource {
override suspend fun deleteOuting(accountIdx: UUID): Flow<Unit> = flow {
emit(
GomsApiHandler<Unit>()
.httpRequest { councilAPI.deleteOuting(accountIdx = accountIdx) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface OutingDataSource {
suspend fun getOutingList(): Flow<List<OutingResponse>>

suspend fun getOutingCount(): Flow<CountResponse>

suspend fun outingSearch(name: String): Flow<List<OutingResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ class OutingDataSourceImpl @Inject constructor(
.sendRequest()
)
}.flowOn(Dispatchers.IO)

override suspend fun outingSearch(name: String): Flow<List<OutingResponse>> = flow {
emit(
GomsApiHandler<List<OutingResponse>>()
.httpRequest { outingAPI.outingSearch(name = name) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import com.goms.network.BuildConfig
import com.goms.network.api.AccountAPI
import com.goms.network.api.AuthAPI
import com.goms.network.api.CouncilAPI
import com.goms.network.api.LateAPI
import com.goms.network.api.OutingAPI
import com.goms.network.util.AuthInterceptor
Expand Down Expand Up @@ -92,4 +93,10 @@ object NetworkModule {
fun provideOutingAPI(retrofit: Retrofit): OutingAPI {
return retrofit.create(OutingAPI::class.java)
}

@Provides
@Singleton
fun provideCouncilAPI(retrofit: Retrofit): CouncilAPI {
return retrofit.create(CouncilAPI::class.java)
}
}
Loading

0 comments on commit a739429

Please sign in to comment.