Skip to content

Commit

Permalink
Merge pull request #154 from hellokitty-coding-club/feat/delete-mission
Browse files Browse the repository at this point in the history
[FEAT] Mission 삭제 api 연동 (#153)
  • Loading branch information
KxxHyoRim authored Oct 24, 2023
2 parents 0ec2f4a + 57a77f1 commit 271f4c2
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 17 deletions.
3 changes: 3 additions & 0 deletions common-ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<string name="want_to_logout">로그아웃 하시겠어요?</string>
<string name="cannot_cancle_after_participate_mission">참여한 미션은 취소가 불가능해요</string>
<string name="do_you_want_to_participate_mission">미션에 참여하시겠어요?</string>
<string name="delete_mission_title">미션을 삭제하시겠어요?</string>
<string name="delete_mission_message">이미 미션에 참여한 리뷰이가 있다면 미션 삭제가 불가능합니다.</string>
<string name="delete_mission_success">미션이 삭제되었습니다.</string>

<!-- Profile -->
<string name="visit_github">Github 방문</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.lgtm.android.data.model.response.PingPongSeniorDTO
import com.lgtm.android.data.model.response.PostMissionResponseDTO
import com.lgtm.android.data.service.MissionService
import com.lgtm.domain.entity.request.PostMissionRequestDTO
import com.lgtm.domain.entity.response.DeleteMissionResponse
import com.lgtm.domain.entity.response.PingPongResponse
import javax.inject.Inject

Expand Down Expand Up @@ -69,12 +70,20 @@ class MissionDataSource @Inject constructor(
)
}

suspend fun codeReviewCompleted(missionId: Int, juniorId: Int): BaseDTO<PingPongResponse> {
suspend fun codeReviewCompleted(missionId: Int, juniorId: Int): BaseDTO<PingPongResponse> {
return checkResponse(
missionService.codeReviewCompleted(
missionId = missionId,
juniorId = juniorId
)
)
}

suspend fun deleteMission(missionId: Int): BaseDTO<DeleteMissionResponse> {
return checkResponse(
missionService.deleteMission(
missionId = missionId,
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ class MissionRepositoryImpl @Inject constructor(
)
Result.success(response.data.toVO())
} catch (e: IllegalArgumentException) {
Log.e(TAG, "fetchSeniorMissionStatus: ${this.javaClass} ${e.message} / casting 도중 null 값 발생")
Log.e(
TAG,
"fetchSeniorMissionStatus: ${this.javaClass} ${e.message} / casting 도중 null 값 발생"
)
Result.failure(e)
} catch (e: Exception) {
Log.e(TAG, "fetchSeniorMissionStatus: ${this.javaClass} ${e.message}")
Expand Down Expand Up @@ -174,4 +177,14 @@ class MissionRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun deleteMission(missionId: Int): Result<Boolean> {
return try {
val response = missionDataSource.deleteMission(missionId)
Result.success(response.data.writerId != null)
} catch (e: Exception) {
Log.e(TAG, "deleteMission: ${this.javaClass} ${e.message}")
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import com.lgtm.android.data.model.response.PingPongSeniorDTO
import com.lgtm.android.data.model.response.PostMissionResponseDTO
import com.lgtm.android.data.model.response.SduiDTO
import com.lgtm.domain.entity.request.PostMissionRequestDTO
import com.lgtm.domain.entity.response.DeleteMissionResponse
import com.lgtm.domain.entity.response.PingPongResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
Expand Down Expand Up @@ -80,5 +82,10 @@ interface MissionService {
@Path("missionId") missionId: Int,
@Path("juniorId") juniorId: Int
): Response<BaseDTO<PingPongResponse>>

@DELETE("v1/mission/{missionId}")
suspend fun deleteMission(
@Path("missionId") missionId: Int,
): Response<BaseDTO<DeleteMissionResponse>>
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lgtm.domain.entity.response

data class DeleteMissionResponse(
val writerId: Int?,
val missionId: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface MissionRepository {

suspend fun submitPullRequest(missionId: Int, githubPrUrl: String): Result<Boolean>
suspend fun codeReviewCompleted(missionId: Int, juniorId: Int): Result<Boolean>

suspend fun deleteMission(missionId: Int): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ class MissionUseCase @Inject constructor(
}
}

suspend fun deleteMission(missionId: Int): Result<Boolean> {
return try {
missionRepository.deleteMission(missionId)
} catch (e: Exception) {
Result.failure(e)
}
}

companion object {
// viewType
private const val ONGOING_MISSION_EMPTY_VIEW = "ongoing_mission_empty_view"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.lgtm.android.common_ui.ui.LgtmConfirmationDialog
import com.lgtm.android.common_ui.util.NetworkState
import com.lgtm.android.common_ui.util.getDrawableCompat
import com.lgtm.android.mission_detail.databinding.ActivityMissionDetailBinding
import com.lgtm.domain.constants.MissionDetailStatus
import com.lgtm.domain.constants.MissionDetailStatus.JUNIOR_NOT_PARTICIPATE_MISSION_FINISH
import com.lgtm.domain.constants.MissionDetailStatus.JUNIOR_NOT_PARTICIPATE_RECRUITING
import com.lgtm.domain.constants.MissionDetailStatus.JUNIOR_PARTICIPATE_MISSION_FINISH
Expand Down Expand Up @@ -58,6 +57,7 @@ class MissionDetailActivity :
initAdapter()
setRecyclerViewLayoutManager()
observeParticipateMissionUiState()
observeDeleteMissionStatus()
}

override fun onResume() {
Expand All @@ -78,11 +78,21 @@ class MissionDetailActivity :
}

private fun observeMissionDetailUiState() {
missionDetailViewModel.missionDetailUiState.observe(this) {
missionDetailViewModel.setRecommendToEmptyVisibility()
missionDetailViewModel.setNotRecommendToEmptyVisibility()
techTagAdapter.submitList(it.techTagList)
binding.profileGlance.data = requireNotNull(it.memberProfile)
missionDetailViewModel.missionDetailStatus.observe(this) {
when (it) {
is NetworkState.Init -> { /* no-op */}
is NetworkState.Success -> {
val missionDetailUi = missionDetailViewModel.missionDetailUiState.value
missionDetailViewModel.setRecommendToEmptyVisibility()
missionDetailViewModel.setNotRecommendToEmptyVisibility()
techTagAdapter.submitList(missionDetailUi?.techTagList)
binding.profileGlance.data = requireNotNull(missionDetailUi?.memberProfile)
}

is NetworkState.Failure -> {
Toast.makeText(this, it.msg, Toast.LENGTH_SHORT).show()
}
}
}
}

Expand Down Expand Up @@ -159,25 +169,56 @@ class MissionDetailActivity :

override fun onMenuItemClick(item: MenuItem): Boolean {
return when (item.itemId) {
id.report -> {
id.report, id.edit_profile -> {
Toast.makeText(this, string.service_under_preparation, Toast.LENGTH_SHORT).show()
true
}

id.delete_mission -> {
Toast.makeText(this, string.service_under_preparation, Toast.LENGTH_SHORT).show()
true
}

id.edit_profile -> {
Toast.makeText(this, string.service_under_preparation, Toast.LENGTH_SHORT).show()
showDeleteMissionDialog()
true
}

else -> false
}
}

private fun showDeleteMissionDialog() {
val title = getString(string.delete_mission_title)
val description = getString(string.delete_mission_message)
val dialog = LgtmConfirmationDialog(
title = title,
description = description,
doAfterConfirm = ::deleteMission,
confirmBtnBackground = LgtmConfirmationDialog.ConfirmButtonBackground.GREEN
)
dialog.show(supportFragmentManager, this.javaClass.name)
}

private fun deleteMission() {
missionDetailViewModel.deleteMission()
}

private fun observeDeleteMissionStatus() {
missionDetailViewModel.deleteMissionState.observe(this) {
when (it) {
is NetworkState.Init -> { /* no-op*/ }
is NetworkState.Success -> {
showMissionDeleteSuccessToast()
finish()
}

is NetworkState.Failure -> {
Toast.makeText(this, it.msg, Toast.LENGTH_SHORT).show()
}
}
}
}

private fun showMissionDeleteSuccessToast() {
Toast.makeText(this, getString(string.delete_mission_success), Toast.LENGTH_SHORT).show()
}

private fun setOnMissionUrlClickListener() {
binding.clMissionUrl.setOnClickListener {
val url: String = missionDetailViewModel.getMissionUrl() ?: return@setOnClickListener
Expand All @@ -190,7 +231,7 @@ class MissionDetailActivity :

private fun setOnClickBottomButton() {
binding.btnMissionDetail.setOnClickListener {
val missionDetailStatus: MissionDetailStatus =
val missionDetailStatus =
missionDetailViewModel.getMissionDetailStatus() ?: return@setOnClickListener
when (missionDetailStatus) {
JUNIOR_PARTICIPATE_RECRUITING -> navigateJuniorMyMission()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class MissionDetailViewModel @Inject constructor(
MutableLiveData(NetworkState.Init)
val participateMissionUiState: LiveData<NetworkState<Boolean>> = _participateMissionUiState

private val _deleteMissionState: MutableLiveData<NetworkState<Boolean>> =
MutableLiveData(NetworkState.Init)
val deleteMissionState: LiveData<NetworkState<Boolean>> = _deleteMissionState

private val _missionDetailStatus: MutableLiveData<NetworkState<Boolean>> =
MutableLiveData(NetworkState.Init)
val missionDetailStatus: LiveData<NetworkState<Boolean>> = _missionDetailStatus

fun isMyMission() =
_missionDetailVO.value?.missionDetailStatus == MissionDetailStatus.SENIOR_PARTICIPATE_RECRUITING ||
_missionDetailVO.value?.missionDetailStatus == MissionDetailStatus.SENIOR_PARTICIPATE_MISSION_FINISH
Expand Down Expand Up @@ -74,7 +82,9 @@ class MissionDetailViewModel @Inject constructor(
.onSuccess {
_missionDetailVO.postValue(it)
_missionDetailUiState.postValue(it.toUiModel())
_missionDetailStatus.postValue(NetworkState.Success(true))
}.onFailure {
_missionDetailStatus.postValue(NetworkState.Failure(it.message))
Log.e(TAG, "getMissionDetail: $it")
}
}
Expand All @@ -93,4 +103,15 @@ class MissionDetailViewModel @Inject constructor(
}

fun getMissionId() = _missionDetailVO.value?.missionId ?: -1
fun deleteMission() {
val missionId = _missionDetailVO.value?.missionId ?: return
viewModelScope.launch(lgtmErrorHandler) {
missionUseCase.deleteMission(missionId)
.onSuccess {
_deleteMissionState.postValue(NetworkState.Success(it))
}.onFailure {
_deleteMissionState.postValue(NetworkState.Failure(it.message))
}
}
}
}

0 comments on commit 271f4c2

Please sign in to comment.