diff --git a/SodaLive/Sources/Content/Create/ContentCreateView.swift b/SodaLive/Sources/Content/Create/ContentCreateView.swift index 1e34034..f201e67 100644 --- a/SodaLive/Sources/Content/Create/ContentCreateView.swift +++ b/SodaLive/Sources/Content/Create/ContentCreateView.swift @@ -321,6 +321,55 @@ struct ContentCreateView: View { .padding(.top, 26.7) .padding(.horizontal, 13.3) + VStack(spacing: 13.3) { + Text("미리듣기 시간 설정") + .font(.custom(Font.bold.rawValue, size: 16.7)) + .foregroundColor(Color(hex: "eeeeee")) + .frame(maxWidth: .infinity, alignment: .leading) + + HStack(spacing: 13.3) { + VStack(spacing: 5.3) { + Text("시작 시간") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "d2d2d2")) + .frame(maxWidth: .infinity, alignment: .leading) + + TextField("00:00:00", text: $viewModel.previewStartTime) + .autocapitalization(.none) + .disableAutocorrection(true) + .font(.custom(Font.bold.rawValue, size: 14.6)) + .foregroundColor(Color(hex: "777777")) + .padding(.vertical, 16.7) + .padding(.horizontal, 13.3) + .background(Color(hex: "222222")) + .cornerRadius(6.7) + .keyboardType(.default) + .multilineTextAlignment(.center) + } + + VStack(spacing: 5.3) { + Text("종료 시간") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "d2d2d2")) + .frame(maxWidth: .infinity, alignment: .leading) + + TextField("00:00:30", text: $viewModel.previewEndTime) + .autocapitalization(.none) + .disableAutocorrection(true) + .font(.custom(Font.bold.rawValue, size: 14.6)) + .foregroundColor(Color(hex: "777777")) + .padding(.vertical, 16.7) + .padding(.horizontal, 13.3) + .background(Color(hex: "222222")) + .cornerRadius(6.7) + .keyboardType(.default) + .multilineTextAlignment(.center) + } + } + } + .padding(.top, 26.7) + .padding(.horizontal, 13.3) + VStack(spacing: 0) { HStack(alignment: .top, spacing: 0) { Text("등록") diff --git a/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift b/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift index 2f11e08..f043e06 100644 --- a/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift +++ b/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift @@ -58,6 +58,9 @@ final class ContentCreateViewModel: ObservableObject { } } + @Published var previewStartTime: String = "" + @Published var previewEndTime: String = "" + var placeholder = "내용을 입력하세요" func uploadAudioContent() { @@ -71,7 +74,9 @@ final class ContentCreateViewModel: ObservableObject { price: price, themeId: theme!.id, isAdult: isAdult, - isCommentAvailable: isAvailableComment + isCommentAvailable: isAvailableComment, + previewStartTime: previewStartTime, + previewEndTime: previewEndTime ) var multipartData = [MultipartFormData]() @@ -211,6 +216,62 @@ final class ContentCreateViewModel: ObservableObject { return false } + if previewStartTime.count > 0 && previewEndTime.count > 0 { + let startTimeArray = previewStartTime.split(separator: ":") + if startTimeArray.count != 3 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + + for time in startTimeArray { + if time.count != 2 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + } + + let endTimeArray = previewStartTime.split(separator: ":") + if endTimeArray.count != 3 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + + for time in endTimeArray { + if time.count != 2 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + } + + let timeDifference = timeDifference(startTime: previewStartTime, endTime: previewEndTime) + if timeDifference < 30.0 { + errorMessage = "미리 듣기의 최소 시간은 30초 입니다" + isShowPopup = true + return false + } + } else { + if previewStartTime.count > 0 || previewEndTime.count > 0 { + errorMessage = "미리 듣기 시작 시간과 종료 시간 둘 다 입력을 하거나 둘 다 입력 하지 않아야 합니다." + isShowPopup = true + return false + } + } + return true } + + private func timeDifference(startTime: String, endTime: String) -> Double { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "HH:mm:ss" + + if let date1 = dateFormatter.date(from: startTime), let date2 = dateFormatter.date(from: endTime) { + return date2.timeIntervalSince(date1) + } + + return 0 + } } diff --git a/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift b/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift index 98bc462..458b18c 100644 --- a/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift +++ b/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift @@ -15,4 +15,6 @@ struct CreateAudioContentRequest: Encodable { let themeId: Int let isAdult: Bool let isCommentAvailable: Bool + let previewStartTime: String + let previewEndTime: String }