-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 Added Episode list to TVShow details
- Loading branch information
Showing
19 changed files
with
375 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Episode.swift | ||
// NetflixLike | ||
// | ||
// Created by Quentin Eude on 11/05/2020. | ||
// Copyright © 2020 Quentin Eude. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
struct Episode: Decodable, Encodable { | ||
let id: Int | ||
let name: String? | ||
let airDate: String? | ||
let episodeNumber: Int | ||
let overview: String? | ||
let seasonNumber: Int | ||
let stillPath: String? | ||
let voteAverage: Double | ||
let voteCount: Int | ||
|
||
|
||
var stillUrl: URL? { | ||
guard let stillPath = stillPath else { | ||
return nil | ||
} | ||
let url = URL(string: "\(APIClient.baseImageStringUrl)\(stillPath)") | ||
return url | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case name | ||
case airDate = "air_date" | ||
case episodeNumber = "episode_number" | ||
case overview | ||
case seasonNumber = "season_number" | ||
case stillPath = "still_path" | ||
case voteAverage = "vote_average" | ||
case voteCount = "vote_count" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Genre.swift | ||
// NetflixLike | ||
// | ||
// Created by Quentin Eude on 20/03/2020. | ||
// Copyright © 2020 Quentin Eude. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
struct Genre: Decodable, Identifiable { | ||
let id: Int | ||
let name: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// TVSeason.swift | ||
// NetflixLike | ||
// | ||
// Created by Quentin Eude on 11/05/2020. | ||
// Copyright © 2020 Quentin Eude. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
struct TVSeason: Decodable, Encodable { | ||
let id: Int | ||
let name: String | ||
let overview: String? | ||
let seasonNumber: Int | ||
let posterPath: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case name | ||
case overview | ||
case seasonNumber = "season_number" | ||
case posterPath = "poster_path" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
NetflixLike/Sources/View Models/TVSeasonListViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// SeasonListViewModel.swift | ||
// NetflixLike | ||
// | ||
// Created by Quentin Eude on 11/05/2020. | ||
// Copyright © 2020 Quentin Eude. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class TVSeasonListViewModel: ObservableObject { | ||
@Published var episodes = [Episode]() | ||
|
||
private var disposables = Set<AnyCancellable>() | ||
private(set) var isLoading = false | ||
private static let episodeProcessingQueue = DispatchQueue(label: "episode-processing") | ||
|
||
init(tvShowId: Int, tvSeasonNumber: Int) { | ||
load(tvShowId: tvShowId, tvSeasonNumber: tvSeasonNumber) | ||
} | ||
|
||
func load(tvShowId: Int, tvSeasonNumber: Int) { | ||
isLoading = true | ||
APIClient().send(APIEndpoints.tvSeason(tvShowId: tvShowId, tvSeasonNumber: tvSeasonNumber)) | ||
.sink(receiveCompletion: { (completion) in | ||
switch completion { | ||
case .failure: | ||
self.isLoading = false | ||
self.episodes = [] | ||
case .finished: | ||
break | ||
} | ||
}, receiveValue: { (response) in | ||
self.isLoading = false | ||
self.episodes = response.episodes | ||
}) | ||
.store(in: &disposables) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
NetflixLike/Sources/View Models/TVShowDetailsViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// TVShowDetailsViewModel.swift | ||
// NetflixLike | ||
// | ||
// Created by Quentin Eude on 20/03/2020. | ||
// Copyright © 2020 Quentin Eude. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class TVShowDetailsViewModel: ObservableObject { | ||
enum State { | ||
case initial | ||
case loading | ||
case error | ||
case data | ||
} | ||
|
||
@Published var tvShow: TVShow? | ||
@Published var state: State = .initial | ||
|
||
private var disposables = Set<AnyCancellable>() | ||
|
||
init(tvShowId: Int) { | ||
fetchTvShowDetails(tvShowId: tvShowId) | ||
} | ||
|
||
private func fetchTvShowDetails(tvShowId: Int) { | ||
self.state = .loading | ||
APIClient().send(APIEndpoints.tvShow(tvShowId: tvShowId)).sink(receiveCompletion: { (completion) in | ||
switch completion { | ||
case .failure: | ||
self.tvShow = nil | ||
self.state = .error | ||
case .finished: | ||
break | ||
} | ||
}, receiveValue: { (response) in | ||
self.tvShow = response | ||
self.state = .data | ||
}) | ||
.store(in: &disposables) | ||
} | ||
|
||
private func fetchEpisodes(tvShowId: Int, tvSeasonNumber: Int) -> AnyPublisher<APIResponseTVSeason, Error> { | ||
return APIClient().send(APIEndpoints.tvSeason(tvShowId: tvShowId, tvSeasonNumber: tvSeasonNumber)) | ||
} | ||
} |
Oops, something went wrong.