오디션 지원 기능 추가
This commit is contained in:
		@@ -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