투표기능 추가

This commit is contained in:
Yu Sung
2025-01-07 19:59:19 +09:00
parent a2b7fef39e
commit 7e13689763
7 changed files with 112 additions and 5 deletions

View File

@@ -87,8 +87,12 @@ struct AuditionRoleDetailView: View {
ForEach(0..<viewModel.applicantList.count, id: \.self) {
let applicant = viewModel.applicantList[$0]
AuditionApplicantItemView(item: applicant)
.padding(.bottom, $0 == viewModel.applicantList.count - 1 ? 33 : 0)
AuditionApplicantItemView(
item: applicant,
onClickVote: {
viewModel.voteApplicant(applicantId: $0)
}
).padding(.bottom, $0 == viewModel.applicantList.count - 1 ? 33 : 0)
if $0 == viewModel.applicantList.count - 1 {
Color.clear
@@ -193,6 +197,17 @@ struct AuditionRoleDetailView: View {
viewModel.deleteAllRecordingFilesWithNamePrefix("voiceon_now_voice")
}
}
if viewModel.isShowSodaDialog {
SodaDialog(
title: viewModel.dialogTitle,
desc: viewModel.dialogDesc,
confirmButtonTitle: "확인"
) {
viewModel.isShowSodaDialog = false
viewModel.isShowNotifyVote = false
}
}
}
}

View File

@@ -36,6 +36,11 @@ final class AuditionRoleDetailViewModel: ObservableObject {
@Published var soundData: Data? = nil
@Published var phoneNumber = ""
@Published var isShowNotifyVote = true
@Published var isShowSodaDialog = false
@Published var dialogTitle = ""
@Published var dialogDesc = ""
var page = 1
var isLast = false
private var pageSize = 10
@@ -262,6 +267,62 @@ final class AuditionRoleDetailViewModel: ObservableObject {
}
}
func voteApplicant(applicantId: Int) {
isLoading = true
repository.voteApplicant(applicantId: applicantId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
if self.isShowNotifyVote {
self.dialogTitle = "[오디션 응원]"
self.dialogDesc = "오디션을 응원하셨습니다\n(무료응원 : 1계정당 1일 1회)\n1캔으로 추가 응원을 해보세요."
self.isShowSodaDialog = true
}
if let index = self.applicantList.firstIndex(where: { $0.applicantId == applicantId }) {
var applicant = self.applicantList[index]
applicant.voteCount += 1
self.applicantList.remove(at: index)
self.applicantList.insert(applicant, at: index)
}
} else {
if let message = decoded.message {
if message.contains("오늘 응원은 여기까지") {
self.dialogTitle = "[오늘 응원 제한]"
self.dialogDesc = "오늘 응원은 여기까지!\n하루 최대 10회까지 이용이 가능합니다.\n내일 다시 이용해주세요."
self.isShowSodaDialog = true
} else {
self.errorMessage = message
self.isShowPopup = true
}
} else {
self.errorMessage = "알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
self.isShowPopup = true
}
}
} catch {
self.errorMessage = "알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
func deleteAllRecordingFilesWithNamePrefix(_ prefix: String) {
let fileManager = FileManager.default
let documentsURL = getDocumentsDirectory()