Skip to content

Commit 59070ab

Browse files
TuikkuMikko Kuivanen
and
Mikko Kuivanen
authored
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 <tuikku_dev@user.startmail.com>
1 parent 8974cbf commit 59070ab

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/TMDb/Models/Show.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
///
44
/// A model representing a show - movie or TV series.
55
///
6-
public enum Show: Identifiable, Equatable, Hashable {
6+
public enum Show: Identifiable, Codable, Equatable, Hashable {
77

88
///
99
/// Show identifier.
@@ -56,7 +56,7 @@ public enum Show: Identifiable, Equatable, Hashable {
5656

5757
}
5858

59-
extension Show: Decodable {
59+
extension Show {
6060

6161
private enum CodingKeys: String, CodingKey {
6262
case mediaType
@@ -80,4 +80,15 @@ extension Show: Decodable {
8080
}
8181
}
8282

83+
public func encode(to encoder: Encoder) throws {
84+
var singleContainer = encoder.singleValueContainer()
85+
86+
switch self {
87+
case .movie(let movie):
88+
try singleContainer.encode(movie)
89+
90+
case .tvSeries(let tvSeries):
91+
try singleContainer.encode(tvSeries)
92+
}
93+
}
8394
}

0 commit comments

Comments
 (0)