Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/jaino/#140 #146

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "๋ฐฉ๊ธˆ"
Comment on lines +25 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐฉ๊ธˆ ์žฌ๋ฐŒ๋Š”๋ฐ์š” ์ง„ํ˜ธ์ƒ ใ…‹ใ…‹ใ…‹ใ…‹

} 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 + "์ผ ์ „ ์ž‘์„ฑ"
}
Comment on lines +26 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ ๋งค์ง๋„˜๋ฒ„๋“ค์€ ์ƒ์ˆ˜ํ™” ์‹œํ‚ฌ ๋งŒ ํ• ๊นŒ์š” ...?

๋งŒ์•ฝ ํ•œ๋‹ค๋ฉด ๋‹ค๋ฅธ ๊ณณ๋“ค๋„ ๋‹ค ํ•˜๊ธด ํ•ด์•ผ ํ•  ํ…๋ฐ ..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ•œ๋‹ค๋ฉด companionObject ๋‚ด์—์„œ ํ•ด์•ผํ•˜๋Š”๋ฐ

๋ฌธ๋งฅ์ƒ ์ดํ•ด๊ฐ€ ๋ผ์„œ
์ €๋Š” ๊ทธ๋ƒฅ ๊ทธ๋Œ€๋กœ ๋‚˜๋‘ฌ๋„ ๋ฌด๋ฐฉํ•  ๊ฒƒ ๊ฐ™์•„์š” ใ…Žใ…Ž


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
Loading