Skip to content

Commit

Permalink
Merge pull request #79 from pknu-wap/feature/tgyuu/#78
Browse files Browse the repository at this point in the history
Feature/tgyuu/#78
  • Loading branch information
tgyuuAn authored Jan 3, 2024
2 parents f95fb41 + 778b54f commit 3d15a25
Show file tree
Hide file tree
Showing 19 changed files with 659 additions and 59 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.wap.wapp.feature.auth.signup.navigation.navigateToSignUp
import com.wap.wapp.feature.auth.signup.navigation.signUpScreen
import com.wap.wapp.feature.management.check.navigation.navigateToSurveyCheck
import com.wap.wapp.feature.management.check.navigation.surveyCheckScreen
import com.wap.wapp.feature.management.edit.event.navigation.eventEditScreen
import com.wap.wapp.feature.management.edit.event.navigation.navigateToEventEdit
import com.wap.wapp.feature.management.navigation.managementScreen
import com.wap.wapp.feature.management.navigation.navigateToManagement
import com.wap.wapp.feature.management.registration.event.navigation.eventRegistrationScreen
Expand Down Expand Up @@ -78,6 +80,9 @@ fun WappNavHost(
eventRegistrationScreen(
navigateToManagement = navController::navigateToManagement,
)
eventEditScreen(
navigateToManagement = navController::navigateToManagement,
)
profileScreen(
navigateToProfileSetting = navController::navigateToProfileSetting,
navigateToSignInScreen = {
Expand All @@ -100,6 +105,7 @@ fun WappNavHost(
managementScreen(
navigateToSurveyRegistration = navController::navigateToSurveyRegistration,
navigateToEventRegistration = navController::navigateToEventRegistration,
navigateToEventEdit = navController::navigateToEventEdit,
navigateToSurveyCheck = navController::navigateToSurveyCheck,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import java.time.LocalDateTime
interface EventRepository {
suspend fun getMonthEvents(date: LocalDate): Result<List<Event>>

suspend fun getEvent(date: LocalDateTime, eventId: String): Result<Event>

suspend fun postEvent(
eventTitle: String,
eventContent: String,
eventLocation: String,
eventStartDateTime: LocalDateTime,
eventEndDateTime: LocalDateTime,
title: String,
content: String,
location: String,
startDateTime: LocalDateTime,
endDateTime: LocalDateTime,
): Result<Unit>

suspend fun updateEvent(
eventId: String,
title: String,
content: String,
location: String,
startDateTime: LocalDateTime,
endDateTime: LocalDateTime,
): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,40 @@ class EventRepositoryImpl @Inject constructor(
}
}

override suspend fun getEvent(date: LocalDateTime, eventId: String): Result<Event> =
eventDataSource.getEvent(date, eventId).mapCatching { eventResponse ->
eventResponse.toDomain()
}

override suspend fun postEvent(
eventTitle: String,
eventContent: String,
eventLocation: String,
eventStartDateTime: LocalDateTime,
eventEndDateTime: LocalDateTime,
title: String,
content: String,
location: String,
startDateTime: LocalDateTime,
endDateTime: LocalDateTime,
): Result<Unit> =
eventDataSource.postEvent(
title = eventTitle,
content = eventContent,
location = eventLocation,
startDateTime = eventStartDateTime.toISOLocalDateTimeString(),
endDateTime = eventEndDateTime.toISOLocalDateTimeString(),
title = title,
content = content,
location = location,
startDateTime = startDateTime.toISOLocalDateTimeString(),
endDateTime = endDateTime.toISOLocalDateTimeString(),
)

override suspend fun updateEvent(
eventId: String,
title: String,
content: String,
location: String,
startDateTime: LocalDateTime,
endDateTime: LocalDateTime,
): Result<Unit> =
eventDataSource.updateEvent(
eventId = eventId,
title = title,
content = content,
location = location,
startDateTime = startDateTime.toISOLocalDateTimeString(),
endDateTime = endDateTime.toISOLocalDateTimeString(),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wap.wapp.core.domain.usecase.event

import com.wap.wapp.core.data.repository.event.EventRepository
import java.time.LocalDateTime
import javax.inject.Inject

class GetEventUseCase @Inject constructor(
private val eventRepository: EventRepository,
) {
suspend operator fun invoke(date: LocalDateTime, eventId: String) =
eventRepository.getEvent(date = date, eventId = eventId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class RegisterEventUseCase @Inject constructor(
eventEndTime: LocalTime,
): Result<Unit> = runCatching {
eventRepository.postEvent(
eventTitle = eventTitle,
eventContent = eventContent,
eventLocation = eventLocation,
eventStartDateTime = LocalDateTime.of(eventStartDate, eventStartTime),
eventEndDateTime = LocalDateTime.of(eventEndDate, eventEndTime),
title = eventTitle,
content = eventContent,
location = eventLocation,
startDateTime = LocalDateTime.of(eventStartDate, eventStartTime),
endDateTime = LocalDateTime.of(eventEndDate, eventEndTime),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.wap.wapp.core.domain.usecase.event

import com.wap.wapp.core.data.repository.event.EventRepository
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import javax.inject.Inject

class UpdateEventUseCase @Inject constructor(
private val eventRepository: EventRepository,
) {
suspend operator fun invoke(
eventId: String,
eventTitle: String,
eventContent: String,
eventLocation: String,
eventStartDate: LocalDate,
eventStartTime: LocalTime,
eventEndDate: LocalDate,
eventEndTime: LocalTime,
): Result<Unit> = runCatching {
eventRepository.updateEvent(
eventId = eventId,
title = eventTitle,
content = eventContent,
location = eventLocation,
startDateTime = LocalDateTime.of(eventStartDate, eventStartTime),
endDateTime = LocalDateTime.of(eventEndDate, eventEndTime),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wap.wapp.core.domain.usecase.management
package com.wap.wapp.core.domain.usecase.survey

import com.wap.wapp.core.data.repository.survey.SurveyFormRepository
import com.wap.wapp.core.model.event.Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ package com.wap.wapp.core.network.source.event

import com.wap.wapp.core.network.model.event.EventResponse
import java.time.LocalDate
import java.time.LocalDateTime

interface EventDataSource {
suspend fun getMonthEvents(date: LocalDate): Result<List<EventResponse>>

suspend fun getEvent(date: LocalDateTime, eventId: String): Result<EventResponse>

suspend fun postEvent(
title: String,
content: String,
location: String,
startDateTime: String,
endDateTime: String,
): Result<Unit>

suspend fun updateEvent(
eventId: String,
title: String,
content: String,
location: String,
startDateTime: String,
endDateTime: String,
): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.wap.wapp.core.network.model.event.EventResponse
import com.wap.wapp.core.network.utils.await
import com.wap.wapp.core.network.utils.toISOLocalDateTime
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

Expand All @@ -34,34 +35,70 @@ class EventDataSourceImpl @Inject constructor(
result
}

override suspend fun getEvent(date: LocalDateTime, eventId: String): Result<EventResponse> =
runCatching {
val document = firebaseFirestore.collection(EVENT_COLLECTION)
.document(getMonth(date.toLocalDate()))
.collection(EVENT_COLLECTION)
.document(eventId)
.get()
.await()

checkNotNull(document.toObject<EventResponse>())
}

override suspend fun postEvent(
title: String,
content: String,
location: String,
startDateTime: String,
endDateTime: String,
): Result<Unit> =
runCatching {
val documentId = firebaseFirestore.collection(SURVEY_COLLECTION).document().id
): Result<Unit> = runCatching {
val documentId = firebaseFirestore.collection(SURVEY_COLLECTION).document().id

val eventRequest = EventRequest(
title = title,
content = content,
location = location,
startDateTime = startDateTime,
endDateTime = endDateTime,
eventId = documentId,
)
val eventRequest = EventRequest(
title = title,
content = content,
location = location,
startDateTime = startDateTime,
endDateTime = endDateTime,
eventId = documentId,
)

val startDate = startDateTime.toISOLocalDateTime().toLocalDate()
val startDate = startDateTime.toISOLocalDateTime().toLocalDate()

firebaseFirestore.collection(EVENT_COLLECTION)
.document(getMonth(startDate))
.collection(EVENT_COLLECTION)
.document(documentId)
.set(eventRequest)
.await()
}
firebaseFirestore.collection(EVENT_COLLECTION)
.document(getMonth(startDate))
.collection(EVENT_COLLECTION)
.document(documentId)
.set(eventRequest)
.await()
}

override suspend fun updateEvent(
eventId: String,
title: String,
content: String,
location: String,
startDateTime: String,
endDateTime: String,
): Result<Unit> = runCatching {
val startDate = startDateTime.toISOLocalDateTime().toLocalDate()
val updateData = mapOf(
"title" to title,
"content" to content,
"location" to location,
"startDateTime" to startDateTime,
"endDateTime" to endDateTime,
)

firebaseFirestore.collection(EVENT_COLLECTION)
.document(getMonth(startDate))
.collection(EVENT_COLLECTION)
.document(eventId)
.update(updateData)
.await()
}

private fun getMonth(date: LocalDate): String {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.wap.wapp.core.model.event.Event
@Composable
internal fun ManagementEventContent(
eventsState: ManagementViewModel.EventsState,
onCardClicked: (String) -> Unit,
onCardClicked: (String, String) -> Unit,
onAddEventButtonClicked: () -> Unit,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -70,7 +70,7 @@ internal fun ManagementEventContent(
ManagementEventItem(
item = event,
cardColor = ManagementCardColor(currentIndex = currentIndex),
onCardClicked = { eventId -> onCardClicked(eventId) },
onCardClicked = onCardClicked,
)
}
}
Expand All @@ -91,13 +91,13 @@ internal fun ManagementEventContent(
private fun ManagementEventItem(
item: Event,
cardColor: Color,
onCardClicked: (String) -> Unit,
onCardClicked: (String, String) -> Unit,
) {
Card(
shape = RoundedCornerShape(10.dp),
modifier = Modifier
.fillMaxSize()
.clickable { onCardClicked(item.eventId) },
.clickable { onCardClicked(item.startDateTime.toString(), item.eventId) },
colors = CardDefaults.cardColors(containerColor = cardColor),
) {
Row(
Expand Down Expand Up @@ -131,9 +131,7 @@ private fun ManagementEventItem(
painter = painterResource(com.wap.wapp.core.designresource.R.drawable.ic_forward),
contentDescription = stringResource(R.string.detail_icon_description),
tint = WappTheme.colors.yellow34,
modifier = Modifier
.clickable { onCardClicked(item.eventId) }
.size(20.dp),
modifier = Modifier.size(20.dp),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ import kotlinx.coroutines.flow.collectLatest

@Composable
internal fun ManagementRoute(
viewModel: ManagementViewModel = hiltViewModel(),
navigateToEventEdit: (String, String) -> Unit,
navigateToEventRegistration: () -> Unit,
navigateToSurveyRegistration: () -> Unit,
navigateToSurveyCheck: (String) -> Unit,
viewModel: ManagementViewModel = hiltViewModel(),
) {
var isShowDialog by rememberSaveable { mutableStateOf(false) }
val context = LocalContext.current

ManagementScreen(
showManageCodeDialog = { isShowDialog = true },
viewModel = viewModel,
showManageCodeDialog = { isShowDialog = true },
navigateToEventRegistration = navigateToEventRegistration,
navigateToSurveyRegistration = navigateToSurveyRegistration,
navigateToSurveyCheck = navigateToSurveyCheck,
navigateToEventEdit = navigateToEventEdit,
)

if (isShowDialog) {
Expand All @@ -62,8 +64,9 @@ internal fun ManagementRoute(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun ManagementScreen(
showManageCodeDialog: () -> Unit,
viewModel: ManagementViewModel,
showManageCodeDialog: () -> Unit,
navigateToEventEdit: (String, String) -> Unit,
navigateToEventRegistration: () -> Unit,
navigateToSurveyRegistration: () -> Unit,
navigateToSurveyCheck: (String) -> Unit,
Expand Down Expand Up @@ -114,7 +117,7 @@ internal fun ManagementScreen(
) {
ManagementEventContent(
eventsState = eventsState,
onCardClicked = {},
onCardClicked = navigateToEventEdit,
onAddEventButtonClicked = navigateToEventRegistration,
)

Expand Down
Loading

0 comments on commit 3d15a25

Please sign in to comment.