Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encodable conformance to Show #136

Merged
merged 12 commits into from
Jan 7, 2024
15 changes: 13 additions & 2 deletions Sources/TMDb/Models/Show.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -56,7 +56,7 @@ public enum Show: Identifiable, Equatable, Hashable {

}

extension Show: Decodable {
extension Show {

private enum CodingKeys: String, CodingKey {
case mediaType
Expand All @@ -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)
}
}
}