Skip to content

Commit

Permalink
[AN] feat: 모임 수정 기능 구현 (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored and takoyakimchi committed Oct 23, 2024
1 parent 9a09fd1 commit c99ce79
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import com.happy.friendogly.domain.usecase.GetPetsUseCase
import com.happy.friendogly.domain.usecase.GetSearchingClubsUseCase
import com.happy.friendogly.domain.usecase.GetWoofAlarmUseCase
import com.happy.friendogly.domain.usecase.KakaoLoginUseCase
import com.happy.friendogly.domain.usecase.PatchClubUseCase
import com.happy.friendogly.domain.usecase.PatchWalkStatusUseCase
import com.happy.friendogly.domain.usecase.PostClubMemberUseCase
import com.happy.friendogly.domain.usecase.PostClubUseCase
Expand Down Expand Up @@ -255,6 +256,8 @@ class AppModule(context: Context) {
PostClubMemberUseCase(repository = clubRepository)
val deleteClubMemberUseCase: DeleteClubMemberUseCase =
DeleteClubMemberUseCase(repository = clubRepository)
val patchClubUseCase: PatchClubUseCase =
PatchClubUseCase(repository = clubRepository)
val getMyClubsUseCase: GetMyClubUseCase =
GetMyClubUseCase(repository = myClubRepository)
val getMyHeadClubsUseCase: GetMyHeadClubUseCase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +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, ClubState.FULL -> 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
Expand Up @@ -8,6 +8,7 @@ import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubDetail
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.ClubParticipation
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.model.Gender
import com.happy.friendogly.domain.model.SizeType
import com.happy.friendogly.domain.repository.ClubRepository
Expand Down Expand Up @@ -62,4 +63,17 @@ class ClubRepositoryImpl(
).mapCatching { it.toDomain() }

override suspend fun deleteClubMember(clubId: Long): Result<Unit> = source.deleteClubMember(clubId)

override suspend fun patchClub(
clubId: Long,
title: String,
content: String,
state: ClubState,
): Result<Unit> =
source.patchClub(
clubId = clubId,
title = title,
content = content,
state = state.toData(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.happy.friendogly.data.model.ClubDetailDto
import com.happy.friendogly.data.model.ClubDto
import com.happy.friendogly.data.model.ClubFilterConditionDto
import com.happy.friendogly.data.model.ClubParticipationDto
import com.happy.friendogly.data.model.ClubStateDto
import com.happy.friendogly.data.model.GenderDto
import com.happy.friendogly.data.model.SizeTypeDto
import okhttp3.MultipartBody
Expand Down Expand Up @@ -36,4 +37,11 @@ interface ClubDataSource {
): Result<ClubParticipationDto>

suspend fun deleteClubMember(clubId: Long): Result<Unit>

suspend fun patchClub(
clubId: Long,
title: String,
content: String,
state: ClubStateDto,
): Result<Unit>
}
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 @@ -5,6 +5,7 @@ import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.ClubDetail
import com.happy.friendogly.domain.model.ClubFilterCondition
import com.happy.friendogly.domain.model.ClubParticipation
import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.model.Gender
import com.happy.friendogly.domain.model.SizeType
import okhttp3.MultipartBody
Expand Down Expand Up @@ -36,4 +37,11 @@ interface ClubRepository {
): Result<ClubParticipation>

suspend fun deleteClubMember(clubId: Long): Result<Unit>

suspend fun patchClub(
clubId: Long,
title: String,
content: String,
state: ClubState,
): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.happy.friendogly.domain.usecase

import com.happy.friendogly.domain.model.ClubState
import com.happy.friendogly.domain.repository.ClubRepository

class PatchClubUseCase(private val repository: ClubRepository) {
suspend operator fun invoke(
clubId: Long,
title: String,
content: String,
state: ClubState,
): Result<Unit> =
repository.patchClub(
clubId = clubId,
title = title,
content = content,
state = state,
)
}
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,17 @@ 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
Expand Up @@ -3,16 +3,25 @@ package com.happy.friendogly.presentation.ui.club.modify
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.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 +42,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,10 +69,25 @@ 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() {
if (isValidModifyState()) {
_modifyEvent.emit(ClubModifyEvent.Navigation.NavigateSelectState)
Expand All @@ -73,5 +98,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
@@ -1,6 +1,7 @@
package com.happy.friendogly.remote.api

import com.happy.friendogly.remote.model.request.ClubFilterConditionRequest
import com.happy.friendogly.remote.model.request.ClubModifyRequest
import com.happy.friendogly.remote.model.request.PostClubMemberRequest
import com.happy.friendogly.remote.model.request.PostClubRequest
import com.happy.friendogly.remote.model.response.BaseResponse
Expand All @@ -13,6 +14,7 @@ import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
Expand Down Expand Up @@ -51,4 +53,10 @@ interface ClubService {
suspend fun deleteClubMember(
@Path("clubId") clubId: Long,
): Response<Unit>

@PATCH(ApiClient.Club.PATCH_CLUB)
suspend fun patchClub(
@Path("clubId") clubId: Long,
@Body request: ClubModifyRequest,
): BaseResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +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, ClubStateDto.FULL -> ClubStateRequest.CLOSE
ClubStateDto.CLOSED -> ClubStateRequest.CLOSED
ClubStateDto.FULL -> ClubStateRequest.FULL
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.happy.friendogly.remote.model.request

import kotlinx.serialization.Serializable

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

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

@SerializedName("FULL")
FULL,
}
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,
}
Loading

0 comments on commit c99ce79

Please sign in to comment.