오디션 지원 기능 추가
This commit is contained in:
@@ -13,6 +13,12 @@ struct AuditionRoleDetailView: View {
|
||||
let roleId: Int
|
||||
|
||||
@StateObject var viewModel = AuditionRoleDetailViewModel()
|
||||
@StateObject var keyboardHandler = KeyboardHandler()
|
||||
|
||||
@State private var isShowApplyMethodView = false
|
||||
@State private var isShowSelectAudioView = false
|
||||
@State private var isShowRecordingView = false
|
||||
@State private var isShowApplyView = false
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
@@ -83,6 +89,14 @@ struct AuditionRoleDetailView: View {
|
||||
|
||||
AuditionApplicantItemView(item: applicant)
|
||||
.padding(.bottom, $0 == viewModel.applicantList.count - 1 ? 33 : 0)
|
||||
|
||||
if $0 == viewModel.applicantList.count - 1 {
|
||||
Color.clear
|
||||
.frame(height: 0)
|
||||
.onAppear {
|
||||
viewModel.getAuditionApplicantList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,8 +133,96 @@ struct AuditionRoleDetailView: View {
|
||||
.cornerRadius(44)
|
||||
.padding(.trailing, 19)
|
||||
.padding(.bottom, 19)
|
||||
.onTapGesture {
|
||||
isShowApplyMethodView = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.fileImporter(
|
||||
isPresented: $isShowSelectAudioView,
|
||||
allowedContentTypes: [.audio],
|
||||
allowsMultipleSelection: false
|
||||
) { result in
|
||||
handleFileImport(result: result)
|
||||
}
|
||||
|
||||
if isShowApplyMethodView {
|
||||
ApplyMethodView(
|
||||
isShowing: $isShowApplyMethodView,
|
||||
onClickSelectAudioFile: {
|
||||
isShowApplyMethodView = false
|
||||
isShowSelectAudioView = true
|
||||
},
|
||||
onClickRecording: {
|
||||
isShowApplyMethodView = false
|
||||
isShowRecordingView = true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if isShowRecordingView {
|
||||
AuditionApplicantRecordingView(
|
||||
isShowing: $isShowRecordingView,
|
||||
isShowPopup: $viewModel.isShowPopup,
|
||||
errorMessage: $viewModel.errorMessage,
|
||||
onClickCompleteRecording: { fileName, soundData in
|
||||
viewModel.fileName = fileName
|
||||
viewModel.soundData = soundData
|
||||
isShowRecordingView = false
|
||||
isShowApplyView = true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if isShowApplyView {
|
||||
AuditionApplyView(
|
||||
isShowing: $isShowApplyView,
|
||||
phoneNumber: $viewModel.phoneNumber,
|
||||
filename: viewModel.fileName,
|
||||
onClickApply: {
|
||||
viewModel.applyAudition {
|
||||
isShowApplyView = false
|
||||
isShowRecordingView = false
|
||||
}
|
||||
}
|
||||
)
|
||||
.offset(y: 0 - (keyboardHandler.keyboardHeight / 10))
|
||||
.onDisappear {
|
||||
viewModel.soundData = nil
|
||||
viewModel.fileName = ""
|
||||
viewModel.deleteAllRecordingFilesWithNamePrefix("voiceon_now_voice")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleFileImport(result: Result<[URL], Error>) {
|
||||
switch result {
|
||||
case .success(let url):
|
||||
let fileUrl = url[0]
|
||||
|
||||
if fileUrl.startAccessingSecurityScopedResource() {
|
||||
defer {
|
||||
fileUrl.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
|
||||
if let data = try? Data(contentsOf: fileUrl) {
|
||||
viewModel.soundData = data
|
||||
viewModel.fileName = fileUrl.lastPathComponent
|
||||
isShowApplyView = true
|
||||
} else {
|
||||
viewModel.errorMessage = "콘텐츠 파일을 불러오지 못했습니다.\n다시 선택해 주세요"
|
||||
viewModel.isShowPopup = true
|
||||
}
|
||||
} else {
|
||||
viewModel.errorMessage = "콘텐츠 파일을 불러오지 못했습니다.\n다시 선택해 주세요"
|
||||
viewModel.isShowPopup = true
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
DEBUG_LOG("error: \(error.localizedDescription)")
|
||||
viewModel.errorMessage = "콘텐츠 파일을 불러오지 못했습니다.\n다시 선택해 주세요"
|
||||
viewModel.isShowPopup = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Moya
|
||||
import Combine
|
||||
|
||||
final class AuditionRoleDetailViewModel: ObservableObject {
|
||||
@@ -31,6 +32,10 @@ final class AuditionRoleDetailViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
@Published var fileName = ""
|
||||
@Published var soundData: Data? = nil
|
||||
@Published var phoneNumber = ""
|
||||
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private var pageSize = 10
|
||||
@@ -169,4 +174,109 @@ final class AuditionRoleDetailViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func applyAudition(onSuccess: @escaping () -> Void) {
|
||||
if phoneNumber.count != 11 {
|
||||
errorMessage = "잘못된 연락처 입니다.\n다시 입력해 주세요."
|
||||
isShowPopup = true
|
||||
return
|
||||
}
|
||||
|
||||
guard let soundData = soundData else {
|
||||
errorMessage = "잘못된 녹음 파일 입니다.\n다시 선택해 주세요."
|
||||
isShowPopup = true
|
||||
return
|
||||
}
|
||||
|
||||
isLoading = true
|
||||
|
||||
let request = ApplyAuditionRoleRequest(roleId: auditionRoleId, phoneNumber: phoneNumber)
|
||||
var multipartData = [MultipartFormData]()
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .withoutEscapingSlashes
|
||||
let jsonData = try? encoder.encode(request)
|
||||
|
||||
if let jsonData = jsonData {
|
||||
multipartData.append(MultipartFormData(provider: .data(jsonData), name: "request"))
|
||||
multipartData.append(
|
||||
MultipartFormData(
|
||||
provider: .data(soundData),
|
||||
name: "contentFile",
|
||||
fileName: fileName,
|
||||
mimeType: "audio/*"
|
||||
)
|
||||
)
|
||||
|
||||
repository.applyAudition(parameters: multipartData)
|
||||
.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 {
|
||||
self.errorMessage = "오디션 지원이 완료되었습니다."
|
||||
self.isShowPopup = true
|
||||
self.deleteAllRecordingFilesWithNamePrefix("voiceon_")
|
||||
self.applicantList = []
|
||||
self.totalCount = 0
|
||||
|
||||
self.page = 1
|
||||
self.isLast = false
|
||||
self.getAuditionRoleDetail()
|
||||
|
||||
onSuccess()
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "오디션 지원을 완료하지 못했습니다.\n다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "오디션 지원을 완료하지 못했습니다.\n다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
} else {
|
||||
self.errorMessage = "오디션 지원을 완료하지 못했습니다.\n다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
self.isLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
func deleteAllRecordingFilesWithNamePrefix(_ prefix: String) {
|
||||
let fileManager = FileManager.default
|
||||
let documentsURL = getDocumentsDirectory()
|
||||
|
||||
do {
|
||||
let fileURLs = try fileManager.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: [])
|
||||
for fileURL in fileURLs {
|
||||
if fileURL.lastPathComponent.hasPrefix(prefix) {
|
||||
try fileManager.removeItem(at: fileURL)
|
||||
DEBUG_LOG("녹음 파일 삭제 성공: \(fileURL)")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
DEBUG_LOG("녹음 파일 삭제 실패: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
private func getDocumentsDirectory() -> URL {
|
||||
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
return paths[0]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user