Moved the Configuration struct from the FeedViewModel view model to the FeedViewController view controller in the Feed framework.
This commit is contained in:
parent
3d42c5887a
commit
5bd1de11e4
@ -12,21 +12,27 @@ import ReviewsiTunesKit
|
|||||||
extension FeedViewController {
|
extension FeedViewController {
|
||||||
final class ViewModel: ObservableObject {
|
final class ViewModel: ObservableObject {
|
||||||
|
|
||||||
// MARK: Constants
|
// MARK: Type aliases
|
||||||
private let iTunesService: iTunesService
|
typealias Configuration = FeedViewController.Configuration
|
||||||
|
|
||||||
|
// MARK: Constants
|
||||||
|
private let configuration: Configuration
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
@Published var loading: Bool = false
|
@Published var loading: Bool = false
|
||||||
|
|
||||||
var items: [Review] = []
|
var items: [Review] = []
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
init(_ configuration: Configuration = .init()) {
|
init(configuration: Configuration = .init()) {
|
||||||
self.iTunesService = .init(configuration: .init(
|
self.configuration = configuration
|
||||||
session: configuration.session
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Computed
|
||||||
|
lazy private var iTunesService: iTunesService = {
|
||||||
|
.init(configuration: .init(session: configuration.session))
|
||||||
|
}()
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
func fetch() {
|
func fetch() {
|
||||||
Task {
|
Task {
|
||||||
@ -34,8 +40,8 @@ extension FeedViewController {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
let output = try await iTunesService.getReviews(.init(
|
let output = try await iTunesService.getReviews(.init(
|
||||||
appID: "474495017",
|
appID: configuration.appID,
|
||||||
countryCode: "nl"
|
countryCode: configuration.countryCode
|
||||||
))
|
))
|
||||||
|
|
||||||
items = output.reviews
|
items = output.reviews
|
||||||
@ -58,12 +64,6 @@ extension FeedViewController {
|
|||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Structs
|
|
||||||
extension FeedViewController.ViewModel {
|
|
||||||
struct Configuration {
|
|
||||||
let session: URLSessionConfiguration = .ephemeral
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class DetailsViewController: UIViewController {
|
|||||||
view.addSubview(titleLabel)
|
view.addSubview(titleLabel)
|
||||||
view.addSubview(contentLabel)
|
view.addSubview(contentLabel)
|
||||||
|
|
||||||
ratingVersionLabel.text = review.ratingVersionText()
|
ratingVersionLabel.text = review.rating.appVersion
|
||||||
ratingVersionLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
ratingVersionLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
||||||
|
|
||||||
authorLabel.text = review.author
|
authorLabel.text = review.author
|
||||||
|
@ -12,15 +12,17 @@ import SwiftUI
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class FeedViewController: UITableViewController {
|
public class FeedViewController: UITableViewController {
|
||||||
|
|
||||||
// MARK: Constants
|
// MARK: Constants
|
||||||
private let viewModel: ViewModel = .init()
|
private let viewModel: ViewModel
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
private var cancellables: Set<AnyCancellable> = []
|
private var cancellables: Set<AnyCancellable> = []
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
public init() {
|
public init(configuration: Configuration = .init()) {
|
||||||
|
self.viewModel = .init(configuration: configuration)
|
||||||
|
|
||||||
super.init(style: .plain)
|
super.init(style: .plain)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +115,29 @@ private extension FeedViewController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Configuration
|
||||||
|
extension FeedViewController {
|
||||||
|
public struct Configuration {
|
||||||
|
|
||||||
|
// MARK: Constants
|
||||||
|
let appID: String
|
||||||
|
let countryCode: String
|
||||||
|
let session: URLSessionConfiguration
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
public init(
|
||||||
|
appID: String = "474495017",
|
||||||
|
countryCode: String = "nl",
|
||||||
|
session: URLSessionConfiguration = .ephemeral
|
||||||
|
) {
|
||||||
|
self.appID = appID
|
||||||
|
self.countryCode = countryCode
|
||||||
|
self.session = session
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - String+Constants
|
// MARK: - String+Constants
|
||||||
private extension String {
|
private extension String {
|
||||||
enum Cell {
|
enum Cell {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user