Skip to content

Commit

Permalink
Add encodable conformance to Show (#136)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Tuikku and Mikko Kuivanen authored Jan 7, 2024
1 parent 8974cbf commit 59070ab
Showing 1 changed file with 13 additions and 2 deletions.
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)
}
}
}

0 comments on commit 59070ab

Please sign in to comment.