오디션 상세 페이지 추가

This commit is contained in:
Yu Sung
2025-01-06 18:31:49 +09:00
parent 3d8817275c
commit 739a9b42b7
12 changed files with 329 additions and 3 deletions

View File

@@ -0,0 +1,83 @@
//
// AuditionDetailView.swift
// SodaLive
//
// Created by klaus on 1/6/25.
//
import SwiftUI
import Kingfisher
struct AuditionDetailView: View {
@StateObject var viewModel = AuditionDetailViewModel()
let auditionId: Int
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: viewModel.title)
if let response = viewModel.response {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 0) {
KFImage(URL(string: response.imageUrl))
.cancelOnDisappear(true)
.downsampling(size: CGSize(width: 1000, height: 530))
.resizable()
.aspectRatio(1000/530, contentMode: .fit)
.frame(maxWidth: .infinity)
.cornerRadius(6.7)
Text("오디션 정보")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
.padding(.top, 15)
ExpandableTextView(text: response.information)
.padding(.top, 13.3)
Text("오디션 캐릭터")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
.padding(.vertical, 15)
LazyVStack(spacing: 15) {
ForEach(0..<response.roleList.count, id: \.self) {
AuditionDetailRoleItemView(item: response.roleList[$0])
}
}
}
.padding(.horizontal, 13.3)
.padding(.vertical, 8)
}
}
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .bottom, autohideIn: 2) {
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: screenSize().width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color.button)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.cornerRadius(20)
.padding(.bottom, 66.7)
Spacer()
}
}
.onAppear {
viewModel.getAuditionDetail(auditionId: auditionId) {
AppState.shared.back()
}
}
}
}
}
#Preview {
AuditionDetailView(auditionId: 1)
}

View File

@@ -0,0 +1,68 @@
//
// AuditionDetailViewModel.swift
// SodaLive
//
// Created by klaus on 1/6/25.
//
import Foundation
import Combine
final class AuditionDetailViewModel: ObservableObject {
private let repository = AuditionRepository()
private var subscription = Set<AnyCancellable>()
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
@Published var response: GetAuditionDetailResponse? = nil
@Published var title: String = "보이스온"
func getAuditionDetail(auditionId: Int, onFailure: () -> Void) {
isLoading = true
repository.getAuditionDetail(auditionId: auditionId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<GetAuditionDetailResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.response = data
self.title = data.title
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
onFailure()
}
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
onFailure()
}
}
self.isLoading = false
}
.store(in: &subscription)
}
}

View File

@@ -0,0 +1,21 @@
//
// GetAuditionDetailResponse.swift
// SodaLive
//
// Created by klaus on 1/6/25.
//
struct GetAuditionDetailResponse: Decodable {
let auditionId: Int
let title: String
let imageUrl: String
let information: String
let roleList: [GetAuditionRoleListData]
}
struct GetAuditionRoleListData: Decodable {
let roleId: Int
let name: String
let imageUrl: String
let isComplete: Bool
}