Skip to content

Commit

Permalink
FEATURE: Merged list items (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung authored Sep 10, 2020
1 parent 7349ee0 commit bbff646
Show file tree
Hide file tree
Showing 38 changed files with 279 additions and 506 deletions.
24 changes: 0 additions & 24 deletions Sources/TMDb/Extensions/URL+QueryItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,4 @@ extension URL {
return appendingQueryItem(name: "with_people", value: value)
}

func appendingWithAppendToResponse(_ includes: [MovieDetailsIncludeKey]?) -> Self {
guard let includes = includes else {
return self
}

let value = includes
.map(\.rawValue)
.joined(separator: ",")

return appendingQueryItem(name: "append_to_response", value: value)
}

func appendingWithAppendToResponse(_ includes: [TVShowDetailsIncludeKey]?) -> Self {
guard let includes = includes else {
return self
}

let value = includes
.map(\.rawValue)
.joined(separator: ",")

return appendingQueryItem(name: "append_to_response", value: value)
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Foundation

public enum MultiTypeListResultItem: Identifiable {
public enum Media: Identifiable {

public var id: String {
public var id: Int {
switch self {
case .movie(let movie):
return "movie-\(movie.id)"
return movie.id

case .tvShow(let tvShow):
return "tvShow-\(tvShow.id)"
return tvShow.id

case .person(let person):
return "person-\(person.id)"
return person.id
}
}

case movie(MovieListResultItem)
case tvShow(TVShowListResultItem)
case person(PersonListResultItem)
case movie(Movie)
case tvShow(TVShow)
case person(Person)

}

extension MultiTypeListResultItem: Decodable {
extension Media: Decodable {

private enum CodingKeys: String, CodingKey {
case mediaType
Expand All @@ -39,13 +39,13 @@ extension MultiTypeListResultItem: Decodable {

switch mediaType {
case .movie:
self = .movie(try MovieListResultItem(from: decoder))
self = .movie(try Movie(from: decoder))

case .tvShow:
self = .tvShow(try TVShowListResultItem(from: decoder))
self = .tvShow(try TVShow(from: decoder))

case .person:
self = .person(try PersonListResultItem(from: decoder))
self = .person(try Person(from: decoder))
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/TMDb/Models/MediaPageableList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foundation

public typealias MediaPageableList = PageableListResult<Media>
109 changes: 71 additions & 38 deletions Sources/TMDb/Models/Movie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,36 @@ public struct Movie: Identifiable, Decodable {
public let id: Int
public let title: String
public let tagline: String?
public let originalTitle: String
public let originalLanguage: String
public let originalTitle: String?
public let originalLanguage: String?
public let overview: String?
public let runtime: Int?
public let genres: [Genre]
public let releaseDate: Date
public let genres: [Genre]?
public let posterPath: URL?
public let backdropPath: URL?
public let budget: Float
public let revenue: Float
private let homepage: String?
public let budget: Float?
public let revenue: Float?
public let imdbId: String?
public let status: Status
public let productionCompanies: [ProductionCompany]
public let productionCountries: [ProductionCountry]
public let spokenLanguages: [SpokenLanguage]
public let popularity: Float
public let voteAverage: Float
public let voteCount: Int
public let video: Bool
public let adult: Bool

public let credits: Credits?
public let recommendations: MoviePageableListResult?
public let similar: MoviePageableListResult?
public let images: ImageCollection?
public let videos: VideoCollection?

public init(id: Int, title: String, tagline: String? = nil, originalTitle: String, originalLanguage: String,
overview: String? = nil, runtime: Int? = nil, genres: [Genre], releaseDate: Date,
posterPath: URL? = nil, backdropPath: URL? = nil, budget: Float, revenue: Float,
homepageURL: URL? = nil, imdbId: String? = nil, status: Status,
productionCompanies: [ProductionCompany], productionCountries: [ProductionCountry],
spokenLanguages: [SpokenLanguage], popularity: Float, voteAverage: Float, voteCount: Int, video: Bool,
adult: Bool, credits: Credits? = nil, recommendations: MoviePageableListResult? = nil,
similar: MoviePageableListResult? = nil, images: ImageCollection? = nil,
videos: VideoCollection? = nil) {
public let status: Status?
public let productionCompanies: [ProductionCompany]?
public let productionCountries: [ProductionCountry]?
public let spokenLanguages: [SpokenLanguage]?
public let popularity: Float?
public let voteAverage: Float?
public let voteCount: Int?
public let video: Bool?
public let adult: Bool?

private let releaseDateString: String?
private let homepage: String?

public init(id: Int, title: String, tagline: String? = nil, originalTitle: String? = nil,
originalLanguage: String? = nil, overview: String? = nil, runtime: Int? = nil, genres: [Genre]? = nil,
releaseDate: Date? = nil, posterPath: URL? = nil, backdropPath: URL? = nil, budget: Float? = nil,
revenue: Float? = nil, homepageURL: URL? = nil, imdbId: String? = nil, status: Status? = nil,
productionCompanies: [ProductionCompany]? = nil, productionCountries: [ProductionCountry]? = nil,
spokenLanguages: [SpokenLanguage]? = nil, popularity: Float? = nil, voteAverage: Float? = nil,
voteCount: Int? = nil, video: Bool? = nil, adult: Bool? = nil) {
self.id = id
self.title = title
self.tagline = tagline
Expand All @@ -50,7 +43,13 @@ public struct Movie: Identifiable, Decodable {
self.overview = overview
self.runtime = runtime
self.genres = genres
self.releaseDate = releaseDate
self.releaseDateString = {
guard let releaseDate = releaseDate else {
return nil
}

return DateFormatter.theMovieDatabase.string(from: releaseDate)
}()
self.posterPath = posterPath
self.backdropPath = backdropPath
self.budget = budget
Expand All @@ -66,17 +65,20 @@ public struct Movie: Identifiable, Decodable {
self.voteCount = voteCount
self.video = video
self.adult = adult
self.credits = credits
self.recommendations = recommendations
self.similar = similar
self.images = images
self.videos = videos
}

}

extension Movie {

public var releaseDate: Date? {
guard let releaseDateString = releaseDateString else {
return nil
}

return DateFormatter.theMovieDatabase.date(from: releaseDateString)
}

public var homepageURL: URL? {
guard let homepage = homepage else {
return nil
Expand All @@ -97,3 +99,34 @@ extension Movie {
}

}

extension Movie {

enum CodingKeys: String, CodingKey {
case id
case title
case tagline
case originalTitle
case originalLanguage
case overview
case runtime
case genres
case releaseDateString = "releaseDate"
case posterPath
case backdropPath
case budget
case revenue
case imdbId
case status
case homepage
case productionCompanies
case productionCountries
case spokenLanguages
case popularity
case voteAverage
case voteCount
case video
case adult
}

}
75 changes: 0 additions & 75 deletions Sources/TMDb/Models/MovieListResultItem.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/TMDb/Models/MoviePageableList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foundation

public typealias MoviePageableList = PageableListResult<Movie>
3 changes: 0 additions & 3 deletions Sources/TMDb/Models/MoviePageableListResult.swift

This file was deleted.

3 changes: 0 additions & 3 deletions Sources/TMDb/Models/MultiTypePageableListResult.swift

This file was deleted.

17 changes: 9 additions & 8 deletions Sources/TMDb/Models/Person.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ public struct Person: Identifiable, Decodable {

public let id: Int
public let name: String
public let alsoKnownAs: [String]
public let alsoKnownAs: [String]?
public let knownForDepartment: String?
public let biography: String
public let biography: String?
public let birthday: Date?
public let deathday: Date?
public let gender: Gender
public let gender: Gender?
public let placeOfBirth: String?
public let profilePath: URL?
public let popularity: Float
public let imdbId: String
public let popularity: Float?
public let imdbId: String?
public let homepage: URL?

public init(id: Int, name: String, alsoKnownAs: [String] = [], knownForDepartment: String? = nil, biography: String,
birthday: Date, deathday: Date? = nil, gender: Gender = .unknown, placeOfBirth: String? = nil,
profilePath: URL? = nil, popularity: Float, imdbId: String, homepage: URL? = nil) {
public init(id: Int, name: String, alsoKnownAs: [String]? = nil, knownForDepartment: String? = nil,
biography: String? = nil, birthday: Date? = nil, deathday: Date? = nil, gender: Gender? = nil,
placeOfBirth: String? = nil, profilePath: URL? = nil, popularity: Float? = nil, imdbId: String? = nil,
homepage: URL? = nil) {
self.id = id
self.name = name
self.alsoKnownAs = alsoKnownAs
Expand Down
6 changes: 3 additions & 3 deletions Sources/TMDb/Models/PersonCombinedCredits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation
public struct PersonCombinedCredits: Identifiable, Decodable {

public let id: Int
public let cast: [ShowListResultItem]
public let crew: [ShowListResultItem]
public let cast: [Show]
public let crew: [Show]

public init(id: Int, cast: [ShowListResultItem], crew: [ShowListResultItem]) {
public init(id: Int, cast: [Show], crew: [Show]) {
self.id = id
self.cast = cast
self.crew = crew
Expand Down
Loading

0 comments on commit bbff646

Please sign in to comment.