시리즈 상세 - 번역 데이터가 있으면 번역 데이터를 표시하도록 수정

This commit is contained in:
Yu Sung
2025-12-17 00:35:16 +09:00
parent b61f432b72
commit 30c70ee638
3 changed files with 60 additions and 9 deletions

View File

@@ -17,6 +17,7 @@ struct GetSeriesDetailResponse: Decodable {
let writer: String?
let studio: String?
let publishedDate: String
let publishedDateUtc: String
let creator: GetSeriesDetailCreator
let rentalMinPrice: Int
let rentalMaxPrice: Int
@@ -27,6 +28,8 @@ struct GetSeriesDetailResponse: Decodable {
let publishedDaysOfWeek: String
let contentList: [GetSeriesContentListItem]
let contentCount: Int
let translated: TranslatedSeries?
let translatedGenre: String?
}
struct GetSeriesDetailCreator: Decodable {
@@ -36,3 +39,51 @@ struct GetSeriesDetailCreator: Decodable {
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
}
}