Skip to content

Commit

Permalink
Merge pull request #73 from pknu-wap/feature/tgyuu/#69
Browse files Browse the repository at this point in the history
Feature/tgyuu/#69
  • Loading branch information
tgyuuAn authored Jan 3, 2024
2 parents 97848fa + f027b29 commit f95fb41
Show file tree
Hide file tree
Showing 56 changed files with 1,224 additions and 646 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package com.wap.wapp.core.commmon.util

import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

object DateUtil {

fun generateNowTime(zoneId: ZoneId = ZoneId.of("Asia/Seoul")): LocalTime = LocalTime.now(zoneId)

fun generateNowDate(zoneId: ZoneId = ZoneId.of("Asia/Seoul")): LocalDate = LocalDate.now(zoneId)

fun generateNowDateTime(zoneId: ZoneId = ZoneId.of("Asia/Seoul")): LocalDateTime =
LocalDateTime.now(zoneId)

const val YEAR_MONTH_START_INDEX = 0
const val YEAR_MONTH_END_INDEX = 7
const val MONTH_DATE_START_INDEX = 5
const val DAYS_IN_WEEK = 7

// 현재 날짜에서 시간, 분만 반환해주는 포맷 ex 19:00
val HHmmFormatter = DateTimeFormatter.ofPattern("HH:mm")

// 현재 날짜에서 일만 반환해주는 포맷 ex 2023-11-20 -> 20
val ddFormatter = DateTimeFormatter.ofPattern("dd")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@ import javax.inject.Inject
class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource,
) : AuthRepository {
override suspend fun hasPendingResult(): Boolean {
return authDataSource.hasPendingResult()
}
override suspend fun hasPendingResult(): Boolean = authDataSource.hasPendingResult()

override suspend fun signIn(email: String): Result<String> {
return authDataSource.signIn(email)
}
override suspend fun signIn(email: String): Result<String> = authDataSource.signIn(email)

override suspend fun signOut(): Result<Unit> {
return authDataSource.signOut()
}
override suspend fun signOut(): Result<Unit> = authDataSource.signOut()

override suspend fun deleteUser(): Result<Unit> {
return authDataSource.deleteUser()
}
override suspend fun deleteUser(): Result<Unit> = authDataSource.deleteUser()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package com.wap.wapp.core.data.repository.event

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

interface EventRepository {
suspend fun getMonthEvents(date: LocalDate): Result<List<Event>>

suspend fun postEvent(
date: LocalDate,
eventTitle: String,
eventContent: String,
eventLocation: String,
eventDate: String,
eventTime: String,
eventStartDateTime: LocalDateTime,
eventEndDateTime: LocalDateTime,
): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.wap.wapp.core.data.repository.event

import com.wap.wapp.core.data.utils.toISOLocalDateTimeString
import com.wap.wapp.core.model.event.Event
import com.wap.wapp.core.network.model.event.EventRequest
import com.wap.wapp.core.network.source.event.EventDataSource
import java.time.LocalDate
import java.time.LocalDateTime
import javax.inject.Inject

class EventRepositoryImpl @Inject constructor(
Expand All @@ -17,21 +18,17 @@ class EventRepositoryImpl @Inject constructor(
}

override suspend fun postEvent(
date: LocalDate,
eventTitle: String,
eventContent: String,
eventLocation: String,
eventDate: String,
eventTime: String,
eventStartDateTime: LocalDateTime,
eventEndDateTime: LocalDateTime,
): Result<Unit> =
eventDataSource.postEvent(
date = date,
EventRequest(
title = eventTitle,
content = eventContent,
location = eventLocation,
period = eventDate,
time = eventTime,
),
title = eventTitle,
content = eventContent,
location = eventLocation,
startDateTime = eventStartDateTime.toISOLocalDateTimeString(),
endDateTime = eventEndDateTime.toISOLocalDateTimeString(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import javax.inject.Inject
class ManagementRepositoryImpl @Inject constructor(
private val managementDataSource: ManagementDataSource,
) : ManagementRepository {
override suspend fun getManager(userId: String): Result<Boolean> {
return managementDataSource.getManager(userId)
}
override suspend fun getManager(userId: String): Result<Boolean> =
managementDataSource.getManager(userId)

override suspend fun postManager(userId: String): Result<Unit> {
return managementDataSource.postManager(userId)
}
override suspend fun postManager(userId: String): Result<Unit> =
managementDataSource.postManager(userId)

override suspend fun getManagementCode(code: String): Result<Boolean> {
return managementDataSource.getManagementCode(code)
}
override suspend fun getManagementCode(code: String): Result<Boolean> =
managementDataSource.getManagementCode(code)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.wap.wapp.core.data.repository.survey

import com.wap.wapp.core.data.utils.toISOLocalDateTimeString
import com.wap.wapp.core.model.survey.SurveyForm
import com.wap.wapp.core.network.model.survey.form.SurveyFormRequest
import com.wap.wapp.core.network.source.survey.SurveyFormDataSource
import java.time.format.DateTimeFormatter
import javax.inject.Inject

class SurveyFormRepositoryImpl @Inject constructor(
Expand All @@ -14,23 +14,21 @@ class SurveyFormRepositoryImpl @Inject constructor(
surveyFormResponse.toDomain()
}

override suspend fun getSurveyFormList(): Result<List<SurveyForm>> {
return surveyFormDataSource.getSurveyFormList().mapCatching { surveyFormResponseList ->
override suspend fun getSurveyFormList(): Result<List<SurveyForm>> =
surveyFormDataSource.getSurveyFormList().mapCatching { surveyFormResponseList ->
surveyFormResponseList.map { surveyFormResponse ->
surveyFormResponse.toDomain()
}
}
}

override suspend fun postSurveyForm(surveyForm: SurveyForm): Result<Unit> {
return surveyFormDataSource.postSurveyForm(
override suspend fun postSurveyForm(surveyForm: SurveyForm): Result<Unit> =
surveyFormDataSource.postSurveyForm(
surveyFormRequest = SurveyFormRequest(
eventId = surveyForm.eventId,
title = surveyForm.title,
content = surveyForm.content,
surveyQuestionList = surveyForm.surveyQuestionList,
deadline = surveyForm.deadline.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
deadline = surveyForm.deadline.toISOLocalDateTimeString(),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface SurveyRepository {
suspend fun getSurvey(surveyId: String): Result<Survey>

suspend fun postSurvey(
eventId: Int,
eventId: String,
userId: String,
title: String,
content: String,
surveyAnswerList: List<SurveyAnswer>,
surveyedAt: LocalDateTime,
): Result<Unit>

suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result<Boolean>
suspend fun isSubmittedSurvey(eventId: String, userId: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.wap.wapp.core.data.repository.survey

import com.wap.wapp.core.data.utils.toISOLocalDateTimeString
import com.wap.wapp.core.model.survey.Survey
import com.wap.wapp.core.model.survey.SurveyAnswer
import com.wap.wapp.core.network.source.survey.SurveyDataSource
import com.wap.wapp.core.network.source.user.UserDataSource
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

class SurveyRepositoryImpl @Inject constructor(
private val surveyDataSource: SurveyDataSource,
private val userDataSource: UserDataSource,
) : SurveyRepository {
override suspend fun getSurveyList(): Result<List<Survey>> {
return surveyDataSource.getSurveyList().mapCatching { surveyList ->
override suspend fun getSurveyList(): Result<List<Survey>> =
surveyDataSource.getSurveyList().mapCatching { surveyList ->
surveyList.map { surveyResponse ->
userDataSource.getUserProfile(userId = surveyResponse.userId)
.mapCatching { userProfileResponse ->
Expand All @@ -27,10 +27,9 @@ class SurveyRepositoryImpl @Inject constructor(
}.getOrThrow()
}
}
}

override suspend fun getSurvey(surveyId: String): Result<Survey> {
return surveyDataSource.getSurvey(surveyId).mapCatching { surveyResponse ->
override suspend fun getSurvey(surveyId: String): Result<Survey> =
surveyDataSource.getSurvey(surveyId).mapCatching { surveyResponse ->
userDataSource.getUserProfile(userId = surveyResponse.userId)
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName
Expand All @@ -42,29 +41,25 @@ class SurveyRepositoryImpl @Inject constructor(
}.getOrThrow()
}.getOrThrow()
}
}

override suspend fun postSurvey(
eventId: Int,
eventId: String,
userId: String,
title: String,
content: String,
surveyAnswerList: List<SurveyAnswer>,
surveyedAt: LocalDateTime,
): Result<Unit> {
return surveyDataSource.postSurvey(
eventId = eventId,
userId = userId,
title = title,
content = content,
surveyAnswerList = surveyAnswerList,
surveyedAt = surveyedAt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
)
}
): Result<Unit> = surveyDataSource.postSurvey(
eventId = eventId,
userId = userId,
title = title,
content = content,
surveyAnswerList = surveyAnswerList,
surveyedAt = surveyedAt.toISOLocalDateTimeString(),
)

override suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result<Boolean> {
return surveyDataSource.isSubmittedSurvey(eventId, userId)
}
override suspend fun isSubmittedSurvey(eventId: String, userId: String): Result<Boolean> =
surveyDataSource.isSubmittedSurvey(eventId, userId)

private val noticeNameResponse: Result<String> = Result.success("notice datasource dummy data")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,24 @@ import javax.inject.Inject
class UserRepositoryImpl @Inject constructor(
private val userDataSource: UserDataSource,
) : UserRepository {
override suspend fun getUserProfile(userId: String): Result<UserProfile> {
return userDataSource.getUserProfile(userId).mapCatching { response ->
override suspend fun getUserProfile(userId: String): Result<UserProfile> =
userDataSource.getUserProfile(userId).mapCatching { response ->
response.toDomain()
}
}

override suspend fun getUserId(): Result<String> {
return userDataSource.getUserId()
}
override suspend fun getUserId(): Result<String> = userDataSource.getUserId()

override suspend fun postUserProfile(
userId: String,
userName: String,
studentId: String,
registeredAt: String,
): Result<Unit> {
return userDataSource.postUserProfile(
UserProfileRequest(
userId = userId,
userName = userName,
studentId = studentId,
registeredAt = registeredAt,
),
)
}
): Result<Unit> = userDataSource.postUserProfile(
UserProfileRequest(
userId = userId,
userName = userName,
studentId = studentId,
registeredAt = registeredAt,
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wap.wapp.core.data.utils

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

internal fun LocalDateTime.toISOLocalDateTimeString(): String =
this.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@ import com.wap.wapp.core.domain.model.AuthState
import com.wap.wapp.core.domain.model.AuthState.SIGN_IN
import com.wap.wapp.core.domain.model.AuthState.SIGN_UP
import dagger.hilt.android.scopes.ActivityScoped
import java.lang.IllegalStateException
import javax.inject.Inject

@ActivityScoped
class SignInUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(email: String): Result<AuthState> {
return runCatching {
val userId = authRepository.signIn(email)
.getOrThrow()
suspend operator fun invoke(email: String): Result<AuthState> = runCatching {
val userId = authRepository.signIn(email)
.getOrThrow()

userRepository.getUserProfile(userId)
.fold(
onFailure = { exception ->
// 등록되지 않은 사용자인 경우
if (exception is IllegalStateException) {
return@fold SIGN_UP
}
// 그 외의 예외인 경우
throw (exception)
},
onSuccess = {
SIGN_IN
},
)
}
userRepository.getUserProfile(userId)
.fold(
onFailure = { exception ->
// 등록되지 않은 사용자인 경우
if (exception is IllegalStateException) {
return@fold SIGN_UP
}
// 그 외의 예외인 경우
throw (exception)
},
onSuccess = { SIGN_IN },
)
}
}
Loading

0 comments on commit f95fb41

Please sign in to comment.