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 {
|
||||
final class ViewModel: ObservableObject {
|
||||
|
||||
// MARK: Constants
|
||||
private let iTunesService: iTunesService
|
||||
// MARK: Type aliases
|
||||
typealias Configuration = FeedViewController.Configuration
|
||||
|
||||
// MARK: Constants
|
||||
private let configuration: Configuration
|
||||
|
||||
// MARK: Properties
|
||||
@Published var loading: Bool = false
|
||||
|
||||
var items: [Review] = []
|
||||
|
||||
// MARK: Initialisers
|
||||
init(_ configuration: Configuration = .init()) {
|
||||
self.iTunesService = .init(configuration: .init(
|
||||
session: configuration.session
|
||||
))
|
||||
init(configuration: Configuration = .init()) {
|
||||
self.configuration = configuration
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
lazy private var iTunesService: iTunesService = {
|
||||
.init(configuration: .init(session: configuration.session))
|
||||
}()
|
||||
|
||||
// MARK: Functions
|
||||
func fetch() {
|
||||
Task {
|
||||
@ -34,8 +40,8 @@ extension FeedViewController {
|
||||
|
||||
do {
|
||||
let output = try await iTunesService.getReviews(.init(
|
||||
appID: "474495017",
|
||||
countryCode: "nl"
|
||||
appID: configuration.appID,
|
||||
countryCode: configuration.countryCode
|
||||
))
|
||||
|
||||
items = output.reviews
|
||||
@ -58,12 +64,6 @@ extension FeedViewController {
|
||||
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(contentLabel)
|
||||
|
||||
ratingVersionLabel.text = review.ratingVersionText()
|
||||
ratingVersionLabel.text = review.rating.appVersion
|
||||
ratingVersionLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
||||
|
||||
authorLabel.text = review.author
|
||||
|
@ -12,15 +12,17 @@ import SwiftUI
|
||||
import UIKit
|
||||
|
||||
public class FeedViewController: UITableViewController {
|
||||
|
||||
|
||||
// MARK: Constants
|
||||
private let viewModel: ViewModel = .init()
|
||||
private let viewModel: ViewModel
|
||||
|
||||
// MARK: Properties
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
// MARK: Initialisers
|
||||
public init() {
|
||||
public init(configuration: Configuration = .init()) {
|
||||
self.viewModel = .init(configuration: configuration)
|
||||
|
||||
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
|
||||
private extension String {
|
||||
enum Cell {
|
||||
|
Loading…
x
Reference in New Issue
Block a user