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/mz 134 vote add #89

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
@@ -0,0 +1,32 @@
package com.susu.core.designsystem.component.appbar.icon

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.susu.core.designsystem.R
import com.susu.core.designsystem.theme.Gray100
import com.susu.core.designsystem.theme.SusuTheme

@Composable
fun RegisterText(
modifier: Modifier = Modifier,
color: Color = Gray100,
) {
Text(
modifier = modifier,
text = stringResource(com.susu.core.ui.R.string.word_register),
style = SusuTheme.typography.title_xxs,
color = color,
)
}

@Preview
@Composable
fun RegisterTextPreview() {
SusuTheme {
RegisterText()
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package com.susu.core.designsystem.component.button

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import com.susu.core.designsystem.R
import com.susu.core.designsystem.theme.Gray30
import com.susu.core.ui.extension.susuClickable

@Composable
fun ClearIconButton(
iconSize: Dp,
tint: Color = Gray30,
onClick: () -> Unit,
) {
Image(
Icon(
modifier = Modifier
.clip(CircleShape)
.size(iconSize)
.susuClickable(onClick = onClick),
painter = painterResource(id = R.drawable.ic_clear),
contentDescription = "",
tint = tint,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ private fun InnerButtons(
onClickCloseIcon: () -> Unit = {},
onClickFilledButton: () -> Unit = {},
) {
val (innerButtonTextColor, innerButtonBackgroundColor) = with(color) {
val (innerButtonTextColor, innerButtonBackgroundColor, clearIconColor) = with(color) {
when {
isFocused.not() -> (unFocusedContentColor to unFocusedBackgroundColor)
isActive || isSaved -> (activeContentColor to activeBackgroundColor)
else -> (inactiveContentColor to inactiveBackgroundColor)
isFocused.not() -> listOf(unFocusedContentColor, unFocusedBackgroundColor, activeClearIconColor)
isActive || isSaved -> listOf(activeContentColor, activeBackgroundColor, activeClearIconColor)
else -> listOf(inactiveContentColor, inactiveBackgroundColor, inactiveClearIconColor)
}
}

Expand All @@ -317,6 +317,7 @@ private fun InnerButtons(
ClearIconButton(
iconSize = clearIconSize,
onClick = onClickClearIcon,
tint = clearIconColor,
)
}
}
Expand Down Expand Up @@ -423,7 +424,7 @@ fun TextFieldButtonPreview() {
onClickButton = { isFocused = !isFocused },
showClearIcon = false,
showCloseIcon = false,
color = TextFieldButtonColor.Orange,
color = TextFieldButtonColor.Gray,
style = LargeTextFieldButtonStyle.height46,
onClickFilledButton = { isSaved = isSaved.not() },
onClickClearIcon = { text = "" },
Expand Down Expand Up @@ -482,7 +483,7 @@ fun TextFieldButtonFocusedPreview() {
) {
Text(text = "ํ…์ŠคํŠธ ๊ธธ์ด์— ๋”ฑ ๋งž๋Š” ๋„ˆ๋น„ (wrap)")
SusuTextFieldWrapContentButton(
color = TextFieldButtonColor.Orange,
color = TextFieldButtonColor.Gray,
text = text,
onTextChange = { text = it },
placeholder = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.susu.core.designsystem.component.textfieldbutton
import androidx.compose.ui.graphics.Color
import com.susu.core.designsystem.theme.Gray10
import com.susu.core.designsystem.theme.Gray100
import com.susu.core.designsystem.theme.Gray15
import com.susu.core.designsystem.theme.Gray30
import com.susu.core.designsystem.theme.Gray40
import com.susu.core.designsystem.theme.Gray50
import com.susu.core.designsystem.theme.Orange10
import com.susu.core.designsystem.theme.Orange20
import com.susu.core.designsystem.theme.Orange60

Expand Down Expand Up @@ -38,6 +41,16 @@ enum class TextFieldButtonColor(
placeholderColor = Gray30,
unFocusedTextColor = Gray10,
),
Gray(
buttonColor = TextButtonInnerButtonColor.Gray,
savedBackgroundColor = Orange10,
editBackgroundColor = Gray15,
unFocusedBackgroundColor = Gray15,
unFocusedTextColor = Gray50,
editTextColor = Gray100,
savedTextColor = Gray100,
placeholderColor = Gray40,
),
}

enum class TextButtonInnerButtonColor(
Expand All @@ -47,6 +60,8 @@ enum class TextButtonInnerButtonColor(
val activeBackgroundColor: Color,
val inactiveBackgroundColor: Color,
val unFocusedBackgroundColor: Color,
val activeClearIconColor: Color,
val inactiveClearIconColor: Color,
val rippleColor: Color,
) {
Black(
Expand All @@ -56,6 +71,19 @@ enum class TextButtonInnerButtonColor(
activeBackgroundColor = Gray100,
inactiveBackgroundColor = Gray40,
unFocusedBackgroundColor = Gray40,
activeClearIconColor = Gray30,
inactiveClearIconColor = Gray30,
rippleColor = Gray10,
),
Gray(
activeContentColor = Gray10,
inactiveContentColor = Gray10,
unFocusedContentColor = Gray10,
activeBackgroundColor = Gray100,
inactiveBackgroundColor = Gray50,
unFocusedBackgroundColor = Gray50,
activeClearIconColor = Gray30,
inactiveClearIconColor = Gray40,
rippleColor = Gray10,
),
}
7 changes: 4 additions & 3 deletions core/designsystem/src/main/res/drawable/ic_clear.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:pathData="M12,0L12,0A12,12 0,0 1,24 12L24,12A12,12 0,0 1,12 24L12,24A12,12 0,0 1,0 12L0,12A12,12 0,0 1,12 0z"
android:fillColor="#E7E7E7"/>
<path
android:pathData="M12,13.4L9.083,16.325C8.899,16.508 8.664,16.6 8.379,16.6C8.094,16.6 7.859,16.508 7.675,16.325C7.492,16.142 7.4,15.908 7.4,15.625C7.4,15.342 7.492,15.108 7.675,14.925L10.6,12L7.675,9.108C7.492,8.924 7.4,8.689 7.4,8.404C7.4,8.119 7.492,7.885 7.675,7.7C7.858,7.517 8.092,7.425 8.375,7.425C8.658,7.425 8.892,7.517 9.075,7.7L12,10.625L14.892,7.7C15.076,7.517 15.311,7.425 15.596,7.425C15.881,7.425 16.115,7.517 16.3,7.7C16.5,7.9 16.6,8.137 16.6,8.412C16.6,8.687 16.5,8.916 16.3,9.1L13.375,12L16.3,14.917C16.483,15.101 16.575,15.336 16.575,15.621C16.575,15.906 16.483,16.141 16.3,16.325C16.1,16.525 15.863,16.625 15.588,16.625C15.313,16.625 15.084,16.525 14.9,16.325L12,13.4Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M12,13.4L9.083,16.325C8.899,16.508 8.664,16.6 8.379,16.6C8.094,16.6 7.859,16.508 7.675,16.325C7.492,16.142 7.4,15.908 7.4,15.625C7.4,15.342 7.492,15.108 7.675,14.925L10.6,12L7.675,9.108C7.492,8.924 7.4,8.689 7.4,8.404C7.4,8.119 7.492,7.885 7.675,7.7C7.858,7.517 8.092,7.425 8.375,7.425C8.658,7.425 8.892,7.517 9.075,7.7L12,10.625L14.892,7.7C15.076,7.517 15.311,7.425 15.596,7.425C15.881,7.425 16.115,7.517 16.3,7.7C16.5,7.9 16.6,8.137 16.6,8.412C16.6,8.687 16.5,8.916 16.3,9.1L13.375,12L16.3,14.917C16.483,15.101 16.575,15.336 16.575,15.621C16.575,15.906 16.483,16.141 16.3,16.325C16.1,16.525 15.863,16.625 15.588,16.625C15.313,16.625 15.084,16.525 14.9,16.325L12,13.4Z"
android:fillColor="#ffffff"/>
</vector>
9 changes: 9 additions & 0 deletions core/model/src/main/java/com/susu/core/model/Vote.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.susu.core.model

data class Vote(
val id: Long,
val category: String,
val content: String,
val isModified: Boolean,
val optionList: List<String>,
)
2 changes: 2 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
<string name="word_no">์•„๋‹ˆ์š”</string>
<string name="word_phone_number">์—ฐ๋ฝ์ฒ˜</string>
<string name="word_memo">๋ฉ”๋ชจ</string>
<string name="word_register">๋“ฑ๋ก</string>
<string name="word_free">์ž์œ </string>
</resources>
7 changes: 7 additions & 0 deletions data/src/main/java/com/susu/data/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.susu.data.data.repository.SignUpRepositoryImpl
import com.susu.data.data.repository.TermRepositoryImpl
import com.susu.data.data.repository.TokenRepositoryImpl
import com.susu.data.data.repository.UserRepositoryImpl
import com.susu.data.data.repository.VoteRepositoryImpl
import com.susu.domain.repository.CategoryConfigRepository
import com.susu.domain.repository.ExcelRepository
import com.susu.domain.repository.LedgerRecentSearchRepository
Expand All @@ -18,6 +19,7 @@ import com.susu.domain.repository.SignUpRepository
import com.susu.domain.repository.TermRepository
import com.susu.domain.repository.TokenRepository
import com.susu.domain.repository.UserRepository
import com.susu.domain.repository.VoteRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -71,4 +73,9 @@ abstract class RepositoryModule {
abstract fun bindExcelRepository(
excelRepositoryImpl: ExcelRepositoryImpl,
): ExcelRepository

@Binds
abstract fun bindVoteRepository(
voteRepositoryImpl: VoteRepositoryImpl,
): VoteRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.susu.data.data.repository

import com.susu.core.model.Vote
import com.susu.data.local.model.toModel
import com.susu.data.remote.api.VoteService
import com.susu.data.remote.model.request.CreateVoteRequest
import com.susu.data.remote.model.request.VoteOption
import com.susu.data.remote.model.response.toModel
import com.susu.domain.repository.VoteRepository
import javax.inject.Inject

class VoteRepositoryImpl @Inject constructor(
private val api: VoteService,
) : VoteRepository {
override suspend fun createVote(
content: String,
optionList: List<String>,
categoryId: Int,
): Vote = api.createVote(
createVoteRequest = CreateVoteRequest(
content = content,
optionList = optionList.mapIndexed { index, voteContent ->
VoteOption(
content = voteContent,
seq = index + 1,
)
},
categoryId = categoryId,
),
).getOrThrow().toModel()
}
15 changes: 15 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/VoteService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.susu.data.remote.api

import com.susu.data.remote.model.request.CreateVoteRequest
import com.susu.data.remote.model.response.VoteResponse
import com.susu.data.remote.retrofit.ApiResult
import retrofit2.http.Body
import retrofit2.http.POST

interface VoteService {

@POST("/api/v1/votes")
suspend fun createVote(
@Body createVoteRequest: CreateVoteRequest,
): ApiResult<VoteResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.susu.data.remote.api.SignUpService
import com.susu.data.remote.api.TermService
import com.susu.data.remote.api.TokenService
import com.susu.data.remote.api.UserService
import com.susu.data.remote.api.VoteService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -59,4 +60,10 @@ object ApiServiceModule {
fun providesUserService(retrofit: Retrofit): UserService {
return retrofit.create(UserService::class.java)
}

@Singleton
@Provides
fun providesVoteService(retrofit: Retrofit): VoteService {
return retrofit.create(VoteService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.susu.data.remote.model.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CreateVoteRequest(
val content: String,
@SerialName("options")
val optionList: List<VoteOption>,
@SerialName("postCategoryId")
val categoryId: Int,
)

@Serializable
data class VoteOption(
val content: String,
val seq: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.susu.data.remote.model.response

import com.susu.core.model.Vote
import com.susu.data.remote.model.request.VoteOption
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class VoteResponse(
val id: Long,
val category: String,
val content: String,
val isModified: Boolean,
@SerialName("options")
val optionList: List<VoteOption>,
)

internal fun VoteResponse.toModel() = Vote(
id = id,
category = category,
content = content,
isModified = isModified,
optionList = optionList.sortedBy { it.seq }.map { it.content },
)
11 changes: 11 additions & 0 deletions domain/src/main/java/com/susu/domain/repository/VoteRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.susu.domain.repository

import com.susu.core.model.Vote

interface VoteRepository {
suspend fun createVote(
content: String,
optionList: List<String>,
categoryId: Int,
): Vote
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.susu.domain.usecase.vote

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.domain.repository.VoteRepository
import javax.inject.Inject

class CreateVoteUseCase @Inject constructor(
private val voteRepository: VoteRepository,
) {
suspend operator fun invoke(param: Param) = runCatchingIgnoreCancelled {
with(param) {
voteRepository.createVote(
content = content,
optionList = optionList,
categoryId = categoryId,
)
}
}

data class Param(
val content: String,
val optionList: List<String>,
val categoryId: Int,
)
}
Loading