Skip to content

Commit

Permalink
Merge pull request #100 from pknu-wap/feature/tgyuu/#74
Browse files Browse the repository at this point in the history
Feature/tgyuu/#74
  • Loading branch information
tgyuuAn authored Jan 13, 2024
2 parents 7024694 + c3a6bae commit c113f97
Show file tree
Hide file tree
Showing 34 changed files with 1,062 additions and 489 deletions.
15 changes: 1 addition & 14 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.navigation.navOptions
import com.wap.designsystem.WappTheme
import com.wap.wapp.core.domain.usecase.auth.SignInUseCase
import com.wap.wapp.feature.auth.signin.navigation.navigateToSignIn
import com.wap.wapp.feature.auth.signin.navigation.signInNavigationRoute
import com.wap.wapp.feature.auth.signin.navigation.signInScreen
import com.wap.wapp.feature.auth.signup.navigation.navigateToSignUp
import com.wap.wapp.feature.auth.signup.navigation.signUpScreen
Expand All @@ -17,9 +18,9 @@ import com.wap.wapp.feature.management.event.navigation.navigateToEventEdit
import com.wap.wapp.feature.management.event.navigation.navigateToEventRegistration
import com.wap.wapp.feature.management.navigation.managementScreen
import com.wap.wapp.feature.management.navigation.navigateToManagement
import com.wap.wapp.feature.management.survey.navigation.managementSurveyNavGraph
import com.wap.wapp.feature.management.survey.navigation.navigateToSurveyFormEdit
import com.wap.wapp.feature.management.survey.navigation.navigateToSurveyFormRegistration
import com.wap.wapp.feature.management.survey.navigation.managementSurveyNavGraph
import com.wap.wapp.feature.notice.navigation.navigateToNotice
import com.wap.wapp.feature.notice.navigation.noticeScreen
import com.wap.wapp.feature.profile.navigation.navigateToProfile
Expand Down Expand Up @@ -93,7 +94,7 @@ fun WappNavHost(
)
profileScreen(
navigateToProfileSetting = navController::navigateToProfileSetting,
navigateToSignInScreen = {
navigateToSignIn = {
navController.navigateToSignIn(
navOptions {
popUpTo(profileNavigationRoute)
Expand All @@ -102,6 +103,13 @@ fun WappNavHost(
},
)
profileSettingScreen(
navigateToSignIn = {
navController.navigateToSignIn(
navOptions {
popUpTo(signInNavigationRoute) { inclusive = true }
},
)
},
navigateToProfile = {
navController.navigateToProfile(
navOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import java.time.LocalDate
import java.time.LocalDateTime

interface EventRepository {
suspend fun getEventList(): Result<List<Event>>

suspend fun getMonthEventList(date: LocalDate): Result<List<Event>>

suspend fun getDateEventList(date: LocalDate): Result<List<Event>>

suspend fun getEventListFromDate(date: LocalDate): Result<List<Event>>

suspend fun getEventList(): Result<List<Event>>

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

suspend fun postEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,32 @@ import javax.inject.Inject
class EventRepositoryImpl @Inject constructor(
private val eventDataSource: EventDataSource,
) : EventRepository {
override suspend fun getMonthEventList(date: LocalDate): Result<List<Event>> =
eventDataSource.getMonthEventList(date).mapCatching { eventResponses ->
eventResponses.map { eventResponse ->
eventResponse.toDomain()
}.sortedBy { it.startDateTime }
}

override suspend fun getEventList(): Result<List<Event>> =
eventDataSource.getEventList().mapCatching { eventResponses ->
eventResponses.map { eventResponse ->
eventResponse.toDomain()
}
}.sortedBy { it.startDateTime }
}

override suspend fun getMonthEventList(date: LocalDate): Result<List<Event>> =
eventDataSource.getMonthEventList(date).mapCatching { eventResponses ->
override suspend fun getDateEventList(date: LocalDate): Result<List<Event>> =
eventDataSource.getDateEventList(date).mapCatching { eventResponses ->
eventResponses.map { eventResponse ->
eventResponse.toDomain()
}.sortedBy { it.startDateTime }
}

override suspend fun getEventListFromDate(date: LocalDate): Result<List<Event>> =
eventDataSource.getEventListFromDate(date).mapCatching { eventResponses ->
eventResponses.map { eventResponse ->
eventResponse.toDomain()
}
}.sortedBy { it.startDateTime }
}

override suspend fun getEvent(eventId: String): Result<Event> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import java.time.LocalDateTime
interface SurveyRepository {
suspend fun getSurveyList(): Result<List<Survey>>

suspend fun getUserRespondedSurveyList(userId: String): Result<List<Survey>>

suspend fun getSurvey(surveyId: String): Result<Survey>

suspend fun postSurvey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ class SurveyRepositoryImpl @Inject constructor(
}
}

override suspend fun getUserRespondedSurveyList(userId: String): Result<List<Survey>> =
surveyDataSource.getUserRespondedSurveyList(userId).mapCatching { surveyList ->
surveyList.map { surveyResponse ->
userDataSource.getUserProfile(userId = surveyResponse.userId)
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()

surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
}.getOrThrow()
}
}

override suspend fun getSurvey(surveyId: String): Result<Survey> =
surveyDataSource.getSurvey(surveyId).mapCatching { surveyResponse ->
userDataSource.getUserProfile(userId = surveyResponse.userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ fun WappMainTopBarWithButton() {
titleRes = R.string.notice,
contentRes = R.string.notice,
showSettingButton = true,
onClickSettingButton = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wap.wapp.core.domain.usecase.event

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

class GetDateEventListUseCase @Inject constructor(
private val eventRepository: EventRepository,
) {
suspend operator fun invoke(date: LocalDate): Result<List<Event>> =
eventRepository.getMonthEventList(date)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wap.wapp.core.domain.usecase.event

import com.wap.wapp.core.data.repository.event.EventRepository
import com.wap.wapp.core.model.event.Event
import java.time.LocalDate
import java.time.ZoneId
import java.time.temporal.ChronoUnit
import javax.inject.Inject

class GetRecentEventListUseCase @Inject constructor(
private val eventRepository: EventRepository,
) {
suspend operator fun invoke(registrationDate: LocalDate): Result<List<Event>> {
val currentDate = LocalDate.now(ZoneId.of("Asia/Seoul"))
val minimumDate = currentDate.minus(3, ChronoUnit.MONTHS)
val selectedDate = maxOf(registrationDate, minimumDate)
return eventRepository.getEventListFromDate(selectedDate)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wap.wapp.core.domain.usecase.survey

import com.wap.wapp.core.data.repository.survey.SurveyRepository
import com.wap.wapp.core.model.survey.Survey
import javax.inject.Inject

class GetUserRespondedSurveyListUseCase @Inject constructor(
private val surveyRepository: SurveyRepository,
) {
suspend operator fun invoke(userId: String): Result<List<Survey>> =
surveyRepository.getUserRespondedSurveyList(userId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wap.wapp.core.domain.usecase.user

import com.wap.wapp.core.data.repository.user.UserRepository
import com.wap.wapp.core.model.user.UserProfile
import javax.inject.Inject

class GetUserProfileUseCase @Inject constructor(private val userRepository: UserRepository) {
suspend operator fun invoke(): Result<UserProfile> = runCatching {
val userId = userRepository.getUserId().getOrThrow()

userRepository.getUserProfile(userId).fold(
onSuccess = { userProfile -> userProfile },
onFailure = { throw it },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.wap.wapp.core.network.model.event.EventResponse
import java.time.LocalDate

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

suspend fun getDateEventList(date: LocalDate): Result<List<EventResponse>>

suspend fun getEventList(): Result<List<EventResponse>>

suspend fun getMonthEventList(date: LocalDate): Result<List<EventResponse>>
suspend fun getEventListFromDate(date: LocalDate): Result<List<EventResponse>>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ class EventDataSourceImpl @Inject constructor(
result
}

override suspend fun getEventListFromDate(date: LocalDate): Result<List<EventResponse>> =
runCatching {
val result = mutableListOf<EventResponse>()

// 선택된 날짜 1일 00시 00분 00초
val startDateTime = date.atStartOfDay().toISOLocalDateTimeString()

val task = firebaseFirestore.collection(EVENT_COLLECTION)
.whereGreaterThanOrEqualTo("startDateTime", startDateTime)
.get()
.await()

for (document in task.documents) {
val event = document.toObject<EventResponse>()
checkNotNull(event)
result.add(event)
}

result
}

override suspend fun getMonthEventList(date: LocalDate): Result<List<EventResponse>> =
runCatching {
val result = mutableListOf<EventResponse>()
Expand Down Expand Up @@ -59,6 +80,28 @@ class EventDataSourceImpl @Inject constructor(
result
}

override suspend fun getDateEventList(date: LocalDate): Result<List<EventResponse>> =
runCatching {
val result = mutableListOf<EventResponse>()

val startDateTime = date.atStartOfDay().toISOLocalDateTimeString()
val endDateTime = date.atTime(LocalTime.MAX).toISOLocalDateTimeString()

val task = firebaseFirestore.collection(EVENT_COLLECTION)
.whereGreaterThanOrEqualTo("startDateTime", startDateTime)
.whereLessThanOrEqualTo("startDateTime", endDateTime)
.get()
.await()

for (document in task.documents) {
val event = document.toObject<EventResponse>()
checkNotNull(event)
result.add(event)
}

result
}

override suspend fun getEvent(eventId: String): Result<EventResponse> =
runCatching {
val document = firebaseFirestore.collection(EVENT_COLLECTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface SurveyDataSource {

suspend fun getSurveyList(): Result<List<SurveyResponse>>

suspend fun getUserRespondedSurveyList(userId: String): Result<List<SurveyResponse>>

suspend fun getSurvey(surveyId: String): Result<SurveyResponse>

suspend fun postSurvey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ class SurveyDataSourceImpl @Inject constructor(
result
}

override suspend fun getUserRespondedSurveyList(userId: String): Result<List<SurveyResponse>> =
runCatching {
val result: MutableList<SurveyResponse> = mutableListOf()

val task = firebaseFirestore.collection(SURVEY_COLLECTION)
.whereEqualTo("userId", userId)
.get()
.await()

for (document in task.documents) {
val surveyResponse = document.toObject(SurveyResponse::class.java)
checkNotNull(surveyResponse)

result.add(surveyResponse)
}

result
}

override suspend fun getSurvey(surveyId: String): Result<SurveyResponse> = runCatching {
val result = firebaseFirestore.collection(SURVEY_COLLECTION)
.document(surveyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ class SurveyFormEditViewModel @Inject constructor(
}

fun getEventList() = viewModelScope.launch {
getEventListUseCase()
.onSuccess { eventList ->
_eventList.value = EventsState.Success(eventList)
}.onFailure { throwable ->
_surveyFormEditUiEvent.emit(SurveyFormEditUiEvent.Failure(throwable))
}
getEventListUseCase().onSuccess { eventList ->
_eventList.value = EventsState.Success(eventList)
}.onFailure { throwable ->
_surveyFormEditUiEvent.emit(SurveyFormEditUiEvent.Failure(throwable))
}
}

fun validateSurveyForm(currentState: SurveyFormState): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ class SurveyFormRegistrationViewModel @Inject constructor(
val surveyDateDeadline = _surveyDateDeadline.asStateFlow()

fun getEventList() = viewModelScope.launch {
getEventListUseCase()
.onSuccess { eventList ->
_eventList.value = EventsState.Success(eventList)
}.onFailure { throwable ->
_surveyRegistrationEvent.emit(SurveyRegistrationEvent.Failure(throwable))
}
getEventListUseCase().onSuccess { eventList ->
_eventList.value = EventsState.Success(eventList)
}.onFailure { throwable ->
_surveyRegistrationEvent.emit(SurveyRegistrationEvent.Failure(throwable))
}
}

fun registerSurvey() = viewModelScope.launch {
Expand Down
Loading

0 comments on commit c113f97

Please sign in to comment.