Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
[feature/review-register] (#70)
Browse files Browse the repository at this point in the history
* 🐛 버튼 활성화 안되는 현상 수정

* 💄 별 색 레벨에 따라 반영 안되는 현상 수정

* 🐛 서버통신 연결 안되는 현상 해결

* 🎨 Delete API 연결

* 🔥 로깅 코드 삭제
  • Loading branch information
l2hyunwoo authored Feb 2, 2023
1 parent c75ff63 commit fabda6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import okhttp3.MultipartBody
import okhttp3.RequestBody
import org.sopt.stamp.data.remote.model.response.ModifyStampResponse
import org.sopt.stamp.data.remote.model.response.StampResponse
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
Expand All @@ -14,6 +16,7 @@ import retrofit2.http.Path
interface StampService {
@GET("stamp/{missionId}")
suspend fun retrieveStamp(
@Header("userId") userId: Int = -1,
@Path("missionId") missionId: Int
): StampResponse

Expand All @@ -28,8 +31,12 @@ interface StampService {
@Multipart
@POST("stamp/{missionId}")
suspend fun registerStamp(
@Header("userId") userId: Int = -1,
@Path("missionId") missionId: Int,
@Part stampContent: RequestBody,
@Part("stampContent") stampContent: RequestBody,
@Part imageUrl: List<MultipartBody.Part>? = null
): StampResponse

@DELETE("stamp/{missionId}")
suspend fun deleteStamp(@Path("missionId") missionId: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class StampRepositoryImpl @Inject constructor(
}
return runCatching {
service.registerStamp(
missionId,
contentRequestBody,
imageRequestBody
missionId = missionId,
stampContent = contentRequestBody,
imageUrl = imageRequestBody
)
}
}

override suspend fun getMissionContent(missionId: Int): Result<Archive> {
return runCatching {
service.retrieveStamp(missionId).toDomain()
service.retrieveStamp(missionId = missionId).toDomain()
}
}

Expand Down Expand Up @@ -85,4 +85,8 @@ class StampRepositoryImpl @Inject constructor(
)
}
}

override suspend fun deleteMission(missionId: Int): Result<Unit> {
return runCatching { service.deleteStamp(missionId) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ interface StampRepository {
imageUri: ImageModel,
content: String
): Result<Unit>

suspend fun deleteMission(
missionId: Int
): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.defaultMinSize
Expand Down Expand Up @@ -49,6 +50,7 @@ import org.sopt.stamp.designsystem.style.SoptTheme
import org.sopt.stamp.domain.MissionLevel
import org.sopt.stamp.feature.mission.model.ImageModel
import org.sopt.stamp.feature.mission.model.MissionNavArgs
import org.sopt.stamp.feature.ranking.getRankTextColor
import org.sopt.stamp.util.DefaultPreview

@Composable
Expand All @@ -70,7 +72,11 @@ private fun HeaderView(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
RatingBar(icon = R.drawable.ic_star, stars = stars)
RatingBar(
icon = R.drawable.ic_star,
stars = stars,
selectedColor = getRankTextColor(rank = stars)
)
Text(
text = title,
style = SoptTheme.typography.sub1,
Expand Down Expand Up @@ -201,13 +207,13 @@ fun MissionDetailScreen(
val content by viewModel.content.collectAsState("")
val imageModel by viewModel.imageModel.collectAsState(ImageModel.Empty)
val isSuccess by viewModel.isSuccess.collectAsState(false)
val isSubmitEnabled by viewModel.isSubmitEnabled.collectAsState(false)

LaunchedEffect(id) {
viewModel.initMissionState(id)
}
LaunchedEffect(isSuccess) {
if (isSuccess) {
// TODO by Nunu 로티 애니메이션 뷰 보여줘야됨
resultNavigator.navigateBack(true)
}
}
Expand Down Expand Up @@ -248,18 +254,19 @@ fun MissionDetailScreen(
onClick = viewModel::onSubmit,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 24.dp, top = 12.dp),
enabled = false,
.padding(bottom = 32.dp),
enabled = isSubmitEnabled,
shape = RoundedCornerShape(10.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = SoptTheme.colors.mint300,
disabledBackgroundColor = SoptTheme.colors.mint300.copy(alpha = 0.8f)
)
backgroundColor = getRankTextColor(rank = level.value),
disabledBackgroundColor = getRankTextColor(rank = level.value).copy(alpha = 0.8f)
),
contentPadding = PaddingValues(vertical = 16.dp)
) {
Text(
text = "제출",
style = SoptTheme.typography.caption1,
color = SoptTheme.colors.onSurface70
text = "미션 완료",
style = SoptTheme.typography.h2,
color = if (level.value == 3) SoptTheme.colors.onSurface70 else Color.White
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.zip
Expand Down Expand Up @@ -45,12 +46,15 @@ class MissionDetailViewModel @Inject constructor(
val isSuccess = uiState.map { it.isSuccess }
val content = uiState.map { it.content }
val imageModel = uiState.map { it.imageUri }
val isSubmitEnabled = content.combine(imageModel) { content, image ->
content.isNotEmpty() && image !is ImageModel.Empty
}

fun initMissionState(id: Int) {
viewModelScope.launch {
uiState.update { it.copy(id = id, isError = false, error = null, isLoading = true) }
repository.getMissionContent(id)
.onSuccess { it ->
.onSuccess {
val result = PostUiState.from(it).copy(id = id)
uiState.update { result }
}.onFailure { error ->
Expand Down Expand Up @@ -94,4 +98,25 @@ class MissionDetailViewModel @Inject constructor(
}
}
}

fun onDelete() {
viewModelScope.launch {
val currentState = uiState.value
val (id) = currentState
uiState.update {
it.copy(isError = false, error = null, isLoading = true)
}
repository.deleteMission(id)
.onSuccess {
uiState.update {
it.copy(isLoading = false, isSuccess = true)
}
}.onFailure { error ->
Timber.e(error)
uiState.update {
it.copy(isLoading = false, isError = true, error = error)
}
}
}
}
}

0 comments on commit fabda6f

Please sign in to comment.