Skip to content

Commit

Permalink
feat: 모집 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong committed Aug 20, 2024
1 parent 71fdaba commit 5e250dc
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import com.happy.friendogly.domain.model.ClubState
fun ClubStateDto.toDomain(): ClubState {
return when (this) {
ClubStateDto.OPEN -> ClubState.OPEN
ClubStateDto.CLOSE -> ClubState.CLOSE
ClubStateDto.CLOSED -> ClubState.CLOSED
ClubStateDto.FULL -> ClubState.FULL
}
}

fun ClubState.toData(): ClubStateDto {
return when (this) {
ClubState.OPEN -> ClubStateDto.OPEN
ClubState.CLOSE -> ClubStateDto.CLOSE
ClubState.CLOSED -> ClubStateDto.CLOSED
ClubState.FULL -> ClubStateDto.FULL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.happy.friendogly.data.model

enum class ClubStateDto {
OPEN,
CLOSE,
CLOSED,
FULL,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.happy.friendogly.domain.model

enum class ClubState(
val clubStateName: String,
) {
OPEN("모집중"),
CLOSE("모집종료"),
FULL("모집완료"),
enum class ClubState {
OPEN,
CLOSED,
FULL,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class ClubDetailUiModel(
) {
fun toClubModifyUiModel(): ClubModifyUiModel {
return ClubModifyUiModel(
clubId = clubId,
title = title,
content = content,
clubState = clubState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ fun TextView.bindClubStateTextStyle(clubState: ClubState) {
val textStyle =
when (clubState) {
ClubState.OPEN -> context.getColor(R.color.coral500)
ClubState.CLOSE, ClubState.FULL -> context.getColor(R.color.gray700)
ClubState.CLOSED, ClubState.FULL -> context.getColor(R.color.gray700)
}
this.setTextColor(textStyle)
}

@BindingAdapter("clubStateText")
fun TextView.bindClubStateText(clubState: ClubState){
this.text = when(clubState){
ClubState.OPEN -> context.getString(R.string.club_state_open)
ClubState.CLOSED -> context.getString(R.string.club_state_closed)
ClubState.FULL -> context.getString(R.string.club_state_full)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import androidx.activity.viewModels
import com.happy.friendogly.R
import com.happy.friendogly.application.di.AppModule
import com.happy.friendogly.databinding.ActivityClubModifyBinding
import com.happy.friendogly.presentation.base.BaseActivity
import com.happy.friendogly.presentation.base.observeEvent
Expand All @@ -16,7 +17,11 @@ import com.happy.friendogly.presentation.utils.putSerializable

class ClubModifyActivity :
BaseActivity<ActivityClubModifyBinding>(R.layout.activity_club_modify) {
private val viewModel: ClubModifyViewModel by viewModels()
private val viewModel: ClubModifyViewModel by viewModels<ClubModifyViewModel> {
ClubModifyViewModel.factory(
patchClubUseCase = AppModule.getInstance().patchClubUseCase,
)
}

override fun initCreateView() {
initDataBinding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class ClubModifyUiModel(
val clubId: Long,
val title: String,
val content: String,
val clubState: ClubState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.happy.friendogly.presentation.ui.club.modify

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.usecase.PatchClubUseCase
import com.happy.friendogly.presentation.base.BaseViewModel
import com.happy.friendogly.presentation.base.BaseViewModelFactory
import com.happy.friendogly.presentation.base.Event
import com.happy.friendogly.presentation.base.emit
import com.happy.friendogly.presentation.ui.club.menu.ClubMenuViewModel
import com.happy.friendogly.presentation.utils.addSourceList
import kotlinx.coroutines.launch

class ClubModifyViewModel : BaseViewModel(), ClubModifyActionHandler {
class ClubModifyViewModel(
private val patchClubUseCase: PatchClubUseCase,
): BaseViewModel(), ClubModifyActionHandler {
private val _modifyEvent: MutableLiveData<Event<ClubModifyEvent>> = MutableLiveData()
val modifyEvent: LiveData<Event<ClubModifyEvent>> get() = _modifyEvent

private var clubId: Long ?= null

private val _clubState: MutableLiveData<ClubState> = MutableLiveData(null)
val clubState: LiveData<ClubState> get() = _clubState

Expand All @@ -33,6 +44,7 @@ class ClubModifyViewModel : BaseViewModel(), ClubModifyActionHandler {
}

fun initUiModel(clubModifyUiModel: ClubModifyUiModel) {
clubId = clubModifyUiModel.clubId
clubTitle.value = clubModifyUiModel.title
clubContent.value = clubModifyUiModel.content
updateClubState(clubModifyUiModel.clubState)
Expand All @@ -59,8 +71,22 @@ class ClubModifyViewModel : BaseViewModel(), ClubModifyActionHandler {
}

override fun submitModify() {
// TODO: submit api
_modifyEvent.emit(ClubModifyEvent.Navigation.NavigateSubmit)
submitClubModify()
}

private fun submitClubModify() = viewModelScope.launch{
patchClubUseCase(
clubId = clubId ?: return@launch,
title = clubTitle.value ?: return@launch,
content = clubContent.value ?: return@launch,
state = clubState.value ?: return@launch,
)
.onSuccess {
_modifyEvent.emit(ClubModifyEvent.Navigation.NavigateSubmit)
}
.onFailure {
_modifyEvent.emit(ClubModifyEvent.FailModify)
}
}

override fun openSelectState() {
Expand All @@ -73,5 +99,13 @@ class ClubModifyViewModel : BaseViewModel(), ClubModifyActionHandler {
private const val MIN_TEXT_LENGTH = 1
private const val MAX_TITLE_LENGTH = 100
private const val MAX_CONTENT_LENGTH = 1000

fun factory(patchClubUseCase: PatchClubUseCase): ViewModelProvider.Factory {
return BaseViewModelFactory {
ClubModifyViewModel(
patchClubUseCase= patchClubUseCase,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ClubRecruitmentBottomSheet(

private fun initClickListener() {
binding.btnClubClose.setOnClickListener {
clickSubmit(ClubState.CLOSE)
clickSubmit(ClubState.CLOSED)
dismiss()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ApiClient {
const val GET_CLUB = "$BASE_URL/{id}"
const val POST_CLUB_MEMBER = "$BASE_URL/{clubId}$MEMBER_URL"
const val DELETE_CLUB_MEMBER = "$BASE_URL/{clubId}$MEMBER_URL"
const val PATCH_CLUB = "$BASE_URL/{clubId}"
}

object MyClub {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface ClubService {
@Path("clubId") clubId: Long,
): Response<Unit>

@PATCH
@PATCH(ApiClient.Club.PATCH_CLUB)
suspend fun patchClub(
@Path("clubId") clubId: Long,
@Body request: ClubModifyRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import com.happy.friendogly.remote.model.response.ClubStateResponse
fun ClubStateResponse.toData(): ClubStateDto {
return when (this) {
ClubStateResponse.OPEN -> ClubStateDto.OPEN
ClubStateResponse.CLOSE -> ClubStateDto.CLOSE
ClubStateResponse.CLOSED -> ClubStateDto.CLOSED
ClubStateResponse.FULL -> ClubStateDto.FULL
}
}

fun ClubStateDto.toRemote(): ClubStateRequest {
return when (this) {
ClubStateDto.OPEN -> ClubStateRequest.OPEN
ClubStateDto.CLOSE -> ClubStateRequest.CLOSE
ClubStateDto.CLOSED -> ClubStateRequest.CLOSED
ClubStateDto.FULL -> ClubStateRequest.FULL
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.happy.friendogly.remote.model.request

import kotlinx.serialization.Serializable

@Serializable
class ClubModifyRequest(
val title: String,
val content: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ enum class ClubStateRequest {
@SerializedName("OPEN")
OPEN,

@SerializedName("CLOSE")
CLOSE,
@SerializedName("CLOSED")
CLOSED,

@SerializedName("FULL")
FULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import kotlinx.serialization.Serializable
@Serializable
enum class ClubStateResponse {
OPEN,
CLOSE,
CLOSED,
FULL,
}
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/activity_club_modify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{vm.clubState.clubStateName}"
app:clubStateText="@{vm.clubState}"
app:selectModifyStateTypeStyle="@{vm.clubState}"
tools:style="@style/Theme.AppCompat.TextView.SemiBold.White.Size16"
tools:text="모집중" />
Expand Down
12 changes: 2 additions & 10 deletions android/app/src/main/res/layout/bottom_sheet_club_recruitment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="clubState"
type="com.happy.friendogly.domain.model.ClubState" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -26,7 +18,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp"
android:text="@{clubState.OPEN.clubStateName}"
android:text="@string/club_state_open"
app:layout_constraintTop_toTopOf="parent"
tools:text="모집중" />

Expand All @@ -44,7 +36,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp"
android:text="@{clubState.CLOSE.clubStateName}"
android:text="@string/club_state_closed"
app:layout_constraintTop_toBottomOf="@id/line"
tools:layout_editor_absoluteX="0dp"
tools:text="모집 종료" />
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/item_club.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="@{club.clubState.clubStateName}"
app:clubStateText="@{club.clubState}"
style="@style/Theme.AppCompat.TextView.SemiBold.Orange.Size14"
app:clubStateTextStyle="@{club.clubState}"
app:layout_constraintStart_toStartOf="parent"
Expand Down
5 changes: 3 additions & 2 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@
<string name="club_list_error_content">잠시 후에 다시 시도해주세요..</string>
<string name="club_number_of_people">%d/%d</string>
<string name="club_club_info">%s · %s</string>
<string name="club_participate_name">모집중</string>
<string name="club_complete_participate_name">모집완료</string>
<string name="club_state_open">모집중</string>
<string name="club_state_closed">모집종료</string>
<string name="club_state_full">모집완료</string>

<!--멍개 생성-->
<string name="club_list_add_title">모임 생성하기</string>
Expand Down

0 comments on commit 5e250dc

Please sign in to comment.