Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class RecruitmentDetailsEntity(
val endDate: String?,
val etc: String?,
val isApplicable: Boolean,
val unapplicableReason: String?,
val bookmarked: Boolean,
val winterIntern: Boolean,
val integrationPlan: Boolean?,
Expand Down Expand Up @@ -71,6 +72,7 @@ internal fun FetchRecruitmentDetailsResponse.toEntity() = RecruitmentDetailsEnti
endDate = this.endDate,
etc = this.etc,
isApplicable = this.isApplicable,
unapplicableReason = this.unapplicableReason,
bookmarked = this.bookmarked,
winterIntern = this.winterIntern,
integrationPlan = this.integrationPlan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class FetchRecruitmentDetailsResponse(
@Json(name = "end_date") val endDate: String?,
@Json(name = "etc") val etc: String?,
@Json(name = "is_applicable") val isApplicable: Boolean,
@Json(name = "unapplicable_reason") val unapplicableReason: String?,
@Json(name = "bookmarked") val bookmarked: Boolean,
@Json(name = "winter_intern") val winterIntern: Boolean,
@Json(name = "integration_plan") val integrationPlan: Boolean?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ private suspend fun ApplicationViewModel.handleApplicationSideEffect(
drawable = JobisIcon.Error,
).show()
}

is ApplicationSideEffect.ApplyFailure -> {
JobisToast.create(
context = context,
message = context.getString(
if (it.isReApply) R.string.toast_re_apply_failure else R.string.toast_apply_failure,
),
drawable = JobisIcon.Error,
).show()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import team.retum.common.base.BaseViewModel
import team.retum.common.enums.AttachmentType
import team.retum.common.exception.BadRequestException
import team.retum.common.exception.ConflictException
import team.retum.common.exception.ForbiddenException
import team.retum.common.exception.NotFoundException
import team.retum.common.exception.UnAuthorizedException
import team.retum.common.utils.FileUtil
import team.retum.usecase.entity.file.PresignedUrlEntity
import team.retum.usecase.usecase.application.ApplyCompanyUseCase
Expand Down Expand Up @@ -118,7 +118,7 @@ internal class ApplicationViewModel @Inject constructor(

private fun setButtonEnabled(isSubmitting: Boolean = state.value.isSubmitting) = setState {
state.value.copy(
buttonEnabled = files.isNotEmpty() && !isSubmitting,
buttonEnabled = (files.isNotEmpty() || urls.any(String::isNotBlank)) && !isSubmitting,
isSubmitting = isSubmitting,
)
}
Expand All @@ -129,13 +129,15 @@ internal class ApplicationViewModel @Inject constructor(

internal fun removeUrl(index: Int) {
urls.removeAt(index)
setButtonEnabled()
}

internal fun onUrlChange(
index: Int,
url: String,
) {
urls[index] = url
setButtonEnabled()
}

private suspend fun applyCompany(attachments: List<Pair<String, AttachmentType>>) {
Expand Down Expand Up @@ -171,7 +173,7 @@ internal class ApplicationViewModel @Inject constructor(
)
}

is UnAuthorizedException -> {
is ForbiddenException -> {
postSideEffect(ApplicationSideEffect.UnexpectedGrade)
}

Expand All @@ -182,6 +184,10 @@ internal class ApplicationViewModel @Inject constructor(
is ConflictException -> {
postSideEffect(ApplicationSideEffect.ConflictApply)
}

else -> {
postSideEffect(ApplicationSideEffect.ApplyFailure(isReApply = isReApply))
}
}
}
}
Expand All @@ -190,30 +196,44 @@ internal class ApplicationViewModel @Inject constructor(
if (state.value.isSubmitting) return
setButtonEnabled(isSubmitting = true)
val submissionFiles = files.toList()
val submissionUrls = urls.filter(String::isNotBlank)
viewModelScope.launch(Dispatchers.IO) {
createPresignedUseCase(files = submissionFiles.toFileNames()).onSuccess {
if (uploadFiles(urls = it.urls, files = submissionFiles)) {
val attachments = it.urls.toFileTypeAttachments() + urls.toUrlTypeAttachments()
if (state.value.isReApply) {
reApplyCompany(attachments = attachments)
if (submissionFiles.isEmpty()) {
submitApplication(attachments = submissionUrls.toUrlTypeAttachments())
} else {
createPresignedUseCase(files = submissionFiles.toFileNames()).onSuccess {
if (uploadFiles(urls = it.urls, files = submissionFiles)) {
submitApplication(
attachments = it.urls.toFileTypeAttachments() + submissionUrls.toUrlTypeAttachments(),
)
} else {
applyCompany(attachments = attachments)
setButtonEnabled(isSubmitting = false)
postSideEffect(ApplicationSideEffect.AttachmentUploadFailure)
}
} else {
}.onFailure {
setButtonEnabled(isSubmitting = false)
postSideEffect(ApplicationSideEffect.AttachmentUploadFailure)
}
}.onFailure {
setButtonEnabled(isSubmitting = false)
when (it) {
is BadRequestException -> {
postSideEffect(ApplicationSideEffect.InvalidFileExtension)
when (it) {
is BadRequestException -> {
postSideEffect(ApplicationSideEffect.InvalidFileExtension)
}

else -> {
postSideEffect(ApplicationSideEffect.ApplyFailure(isReApply = state.value.isReApply))
}
}
}
}
}
}

private suspend fun submitApplication(attachments: List<Pair<String, AttachmentType>>) {
if (state.value.isReApply) {
reApplyCompany(attachments = attachments)
} else {
applyCompany(attachments = attachments)
}
}

private suspend fun uploadFiles(
urls: List<PresignedUrlEntity.UrlEntity>,
files: List<File>,
Expand Down Expand Up @@ -262,4 +282,5 @@ internal sealed interface ApplicationSideEffect {
data object ConflictApply : ApplicationSideEffect
data object NotFoundRecruitment : ApplicationSideEffect
data object UnexpectedGrade : ApplicationSideEffect
data class ApplyFailure(val isReApply: Boolean) : ApplicationSideEffect
}
6 changes: 4 additions & 2 deletions feature/application/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<string name="toast_attachment_upload_failure">첨뢀 파일 μ—…λ‘œλ“œμ— μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”</string>
<string name="toast_success_apply">μ„±κ³΅μ μœΌλ‘œ 지원이 μ™„λ£Œλ˜μ—ˆμ–΄μš”!</string>
<string name="toast_success_re_apply">μ„±κ³΅μ μœΌλ‘œ μž¬μ§€μ› λ˜μ—ˆμ–΄μš”!</string>
<string name="toast_conflict_apply">이미 μ§€μ›ν•œ κΈ°μ—…μ΄μ—μš”</string>
<string name="toast_conflict_apply">이미 μ§€μ›ν–ˆκ±°λ‚˜ μ§„ν–‰ 쀑인 지원이 μžˆμ–΄μš”</string>
<string name="toast_not_found_recruitment">μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” λͺ¨μ§‘μ˜λ’°μ„œμ—μš”</string>
<string name="toast_unexpected_grade">3ν•™λ…„λ§Œ 지원할 수 μžˆμ–΄μš”</string>
<string name="toast_unexpected_grade">지원 κ°€λŠ₯ν•œ 학년이 μ•„λ‹ˆμ—μš”</string>
<string name="toast_apply_failure">지원에 μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”</string>
<string name="toast_re_apply_failure">μž¬μ§€μ›μ— μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private fun RecruitmentDetailsScreen(
onBookmarkClick = onBookmarkClick,
isBookmark = recruitmentDetail.bookmarked,
isApplicable = recruitmentDetail.isApplicable,
unapplicableReason = recruitmentDetail.unapplicableReason,
)
}
}
Expand Down Expand Up @@ -413,6 +414,7 @@ private fun BottomBar(
onBookmarkClick: () -> Unit,
isBookmark: Boolean,
isApplicable: Boolean,
unapplicableReason: String?,
) {
Row(
modifier = Modifier
Expand All @@ -439,13 +441,12 @@ private fun BottomBar(
onClick = onApplyClick,
) {
JobisText(
text = stringResource(
id = if (isApplicable) {
R.string.apply
} else {
R.string.can_do_not_apply
},
),
text = if (isApplicable) {
stringResource(R.string.apply)
} else {
unapplicableReason?.takeIf(String::isNotBlank)
?: stringResource(R.string.can_do_not_apply)
},
style = JobisTypography.SubHeadLine,
color = Color.White,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal data class RecruitmentDetailsState(
endDate = "",
etc = null,
isApplicable = false,
unapplicableReason = null,
bookmarked = false,
winterIntern = false,
integrationPlan = false,
Expand Down
Loading