Files
sodalive-ios/SodaLive/Sources/Content/Series/Detail/GetSeriesDetailResponse.swift

90 lines
2.8 KiB
Swift

//
// GetSeriesDetailResponse.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import Foundation
struct GetSeriesDetailResponse: Decodable {
let seriesId: Int
let title: String
let coverImage: String
let introduction: String
let genre: String
let isAdult: Bool
let writer: String?
let studio: String?
let publishedDate: String
let publishedDateUtc: String
let creator: GetSeriesDetailCreator
let rentalMinPrice: Int
let rentalMaxPrice: Int
let rentalPeriod: Int
let minPrice: Int
let maxPrice: Int
let keywordList: [String]
let publishedDaysOfWeek: String
let contentList: [GetSeriesContentListItem]
let contentCount: Int
let translated: TranslatedSeries?
let translatedGenre: String?
}
struct GetSeriesDetailCreator: Decodable {
let creatorId: Int
let nickname: String
let profileImage: String
let isFollow: Bool
let isNotify: Bool
}
struct TranslatedSeries: Decodable {
let title: String
let introduction: String
let keywords: [String]
}
// :
extension GetSeriesDetailResponse {
//
var displayTitle: String { translated?.title ?? title }
//
var displayIntroduction: String { translated?.introduction ?? introduction }
//
var displayKeywords: [String] { translated?.keywords ?? keywordList }
//
var displayGenre: String { translatedGenre ?? genre }
// ISO8601 UTC yyyy.MM.dd
var displayPublishedDate: String {
// publishedDateUtc : ISO8601
let iso = ISO8601DateFormatter()
// .withInternetDateTime , fractional seconds
iso.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
func format(_ date: Date) -> String {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .gregorian)
formatter.timeZone = .current
formatter.locale = Locale(identifier: Locale.current.identifier)
formatter.dateFormat = "yyyy.MM.dd"
return formatter.string(from: date)
}
if let date = iso.date(from: publishedDateUtc) {
return format(date)
} else {
// fractional seconds
let isoNoFrac = ISO8601DateFormatter()
isoNoFrac.formatOptions = [.withInternetDateTime]
if let date = isoNoFrac.date(from: publishedDateUtc) {
return format(date)
}
}
//
return publishedDate
}
}