Skip to content

Commit

Permalink
Merge pull request #146 from pknu-wap/feature/jaino/#140
Browse files Browse the repository at this point in the history
Feature/jaino/#140
  • Loading branch information
jeongjaino authored Mar 4, 2024
2 parents e64ac5f + b3b495e commit 5abfab1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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.event.EventDataSource
import com.wap.wapp.core.network.source.survey.SurveyDataSource
import com.wap.wapp.core.network.source.user.UserDataSource
import java.time.LocalDateTime
Expand All @@ -11,6 +12,7 @@ import javax.inject.Inject
class SurveyRepositoryImpl @Inject constructor(
private val surveyDataSource: SurveyDataSource,
private val userDataSource: UserDataSource,
private val eventDataSource: EventDataSource,
) : SurveyRepository {
override suspend fun getSurveyList(): Result<List<Survey>> =
surveyDataSource.getSurveyList().mapCatching { surveyList ->
Expand All @@ -19,11 +21,12 @@ class SurveyRepositoryImpl @Inject constructor(
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()
eventDataSource.getEvent(eventId = surveyResponse.eventId)
.mapCatching { eventResponse ->
val eventName = eventResponse.toDomain().title

surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
}.getOrThrow()
}
}
Expand All @@ -35,11 +38,12 @@ class SurveyRepositoryImpl @Inject constructor(
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()
eventDataSource.getEvent(eventId = eventId)
.mapCatching { eventResponse ->
val eventName = eventResponse.toDomain().title

surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
}.getOrThrow()
}
}
Expand All @@ -51,11 +55,12 @@ class SurveyRepositoryImpl @Inject constructor(
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()
eventDataSource.getEvent(eventId = surveyResponse.eventId)
.mapCatching { eventResponse ->
val eventName = eventResponse.toDomain().title

surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
}.getOrThrow()
}
}
Expand All @@ -67,11 +72,12 @@ class SurveyRepositoryImpl @Inject constructor(
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()
eventDataSource.getEvent(eventId = surveyResponse.eventId)
.mapCatching { eventResponse ->
val eventName = eventResponse.toDomain().title

surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
surveyResponse.toDomain(userName = userName, eventName = eventName)
}.getOrThrow()
}.getOrThrow()
}
}
Expand All @@ -82,11 +88,12 @@ class SurveyRepositoryImpl @Inject constructor(
.mapCatching { userProfileResponse ->
val userName = userProfileResponse.toDomain().userName

noticeNameResponse.mapCatching { noticeNameResponse ->
val eventName = noticeNameResponse.toDomain()
eventDataSource.getEvent(eventId = surveyResponse.eventId)
.mapCatching { eventResponse ->
val eventName = eventResponse.toDomain().title

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

Expand All @@ -113,9 +120,4 @@ class SurveyRepositoryImpl @Inject constructor(

override suspend fun isSubmittedSurvey(surveyFormId: String, userId: String): Result<Boolean> =
surveyDataSource.isSubmittedSurvey(surveyFormId, userId)

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

// TODO 도메인 모델 구현을 위한 익스텐션, notice DataSource 구현 후 소거
private fun String.toDomain(): String = this
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.wap.wapp.core.model.survey

import java.time.Duration
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

/*
회원이 작성하는 설문 모델
Expand All @@ -15,4 +18,33 @@ data class Survey(
val content: String,
val surveyAnswerList: List<SurveyAnswer>,
val surveyedAt: LocalDateTime,
)
) {
fun calculateSurveyedAt(): String {
val currentDateTime = LocalDateTime.now(TIME_ZONE_SEOUL)
val duration = Duration.between(surveyedAt, currentDateTime)

if (duration.toMinutes() == 0L) {
return "방금"
} else if (duration.toMinutes() < 60) {
val leftMinutes = duration.toMinutes().toString()
return leftMinutes + "분 전 작성"
}

if (duration.toHours() < 24) {
val leftHours = duration.toHours().toString()
return leftHours + "시간 전 작성"
}

if (duration.toDays() < 31) {
val leftDays = duration.toDays().toString()
return leftDays + "일 전 작성"
}

return surveyedAt.format(yyyyMMddFormatter) + " 작성"
}

companion object {
val yyyyMMddFormatter = DateTimeFormatter.ofPattern("yyyy.MM.dd")
val TIME_ZONE_SEOUL = ZoneId.of("Asia/Seoul")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.wap.designsystem.WappTheme
import com.wap.wapp.core.model.survey.Survey
Expand All @@ -30,31 +32,35 @@ internal fun SurveyItemCard(
) {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.padding(horizontal = 16.dp),
modifier = Modifier.padding(16.dp),
) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(),
) {
Text(
text = survey.title,
modifier = Modifier.weight(1f),
maxLines = 1,
color = WappTheme.colors.white,
style = WappTheme.typography.titleBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)

Text(
text = survey.eventName,
color = WappTheme.colors.grayA2,
text = survey.calculateSurveyedAt(),
color = WappTheme.colors.yellow34,
style = WappTheme.typography.captionMedium,
modifier = Modifier.padding(start = 8.dp),
)
}

Text(
text = survey.userName,
text = "${survey.userName}${survey.eventName}",
color = WappTheme.colors.grayBD,
style = WappTheme.typography.contentMedium,
style = WappTheme.typography.labelMedium,
maxLines = 1,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.wap.designsystem.WappTheme
import com.wap.wapp.core.model.survey.SurveyForm
Expand All @@ -34,26 +36,29 @@ internal fun SurveyFormItemCard(
) {
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(),
) {
Text(
text = surveyForm.title,
color = WappTheme.colors.white,
modifier = Modifier.weight(1f),
maxLines = 1,
style = WappTheme.typography.titleBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(
text = surveyForm.calculateDeadline(),
color = WappTheme.colors.yellow34,
style = WappTheme.typography.captionMedium,
modifier = Modifier.padding(start = 8.dp),
)
}
Text(
text = surveyForm.content,
color = WappTheme.colors.grayBD,
maxLines = 1,
style = WappTheme.typography.contentMedium,
style = WappTheme.typography.labelMedium,
)
}
}
Expand Down

0 comments on commit 5abfab1

Please sign in to comment.