From 59070ab6dd846a1c7ce5837e905df1af5187f5b2 Mon Sep 17 00:00:00 2001 From: Mikko Kuivanen Date: Sun, 7 Jan 2024 23:17:56 +0200 Subject: [PATCH] Add encodable conformance to Show (#136) * FEATURE: Add tv show tagline * FIX: linting * FEATURE: Add fetching watch providers to movie and tv show services * FIX: linting * TEST: add tests for movie and tvseries watch providers * FIX: linting * FEATURE: add encodable conformance to Show * fix linting --------- Co-authored-by: Mikko Kuivanen --- Sources/TMDb/Models/Show.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/TMDb/Models/Show.swift b/Sources/TMDb/Models/Show.swift index a899f82e..45edfeac 100644 --- a/Sources/TMDb/Models/Show.swift +++ b/Sources/TMDb/Models/Show.swift @@ -3,7 +3,7 @@ import Foundation /// /// A model representing a show - movie or TV series. /// -public enum Show: Identifiable, Equatable, Hashable { +public enum Show: Identifiable, Codable, Equatable, Hashable { /// /// Show identifier. @@ -56,7 +56,7 @@ public enum Show: Identifiable, Equatable, Hashable { } -extension Show: Decodable { +extension Show { private enum CodingKeys: String, CodingKey { case mediaType @@ -80,4 +80,15 @@ extension Show: Decodable { } } + public func encode(to encoder: Encoder) throws { + var singleContainer = encoder.singleValueContainer() + + switch self { + case .movie(let movie): + try singleContainer.encode(movie) + + case .tvSeries(let tvSeries): + try singleContainer.encode(tvSeries) + } + } }