Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/pknu-wap/WAPP into featu…
Browse files Browse the repository at this point in the history
…re/tgyuu/#76
  • Loading branch information
tgyuuAn committed Jan 3, 2024
2 parents 1c6a5be + 5aebcc6 commit e3e6b1c
Show file tree
Hide file tree
Showing 23 changed files with 729 additions and 83 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/wap/wapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.wap.wapp.feature.auth.signin.navigation.signInNavigationRoute
import com.wap.wapp.feature.auth.signup.navigation.signUpNavigationRoute
import com.wap.wapp.feature.management.registration.event.navigation.eventRegistrationNavigationRoute
import com.wap.wapp.feature.management.registration.survey.navigation.surveyRegistrationNavigationRoute
import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.navigation.TopLevelDestination
import com.wap.wapp.navigation.WappNavHost
Expand Down Expand Up @@ -103,6 +104,7 @@ private fun handleBottomBarState(
signInNavigationRoute -> setBottomBarState(false)
signUpNavigationRoute -> setBottomBarState(false)
splashNavigationRoute -> setBottomBarState(false)
profileSettingNavigationRoute -> setBottomBarState(false)
surveyRegistrationNavigationRoute -> setBottomBarState(false)
eventRegistrationNavigationRoute -> setBottomBarState(false)
else -> setBottomBarState(true)
Expand Down
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 @@ -32,7 +32,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 @@ -72,7 +72,7 @@ internal fun ManagementEventContent(
ManagementEventItem(
item = event,
cardColor = ManagementCardColor(currentIndex = currentIndex),
onCardClicked = { eventId -> onCardClicked(eventId) },
onCardClicked = onCardClicked,
)
}
}
Expand All @@ -93,13 +93,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 @@ -133,9 +133,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
Loading

0 comments on commit e3e6b1c

Please sign in to comment.