diff --git a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift index 624bf03..8198e6d 100644 --- a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift +++ b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift @@ -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 } } diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift index 526ed1f..b27f16d 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift @@ -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 diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift index d64aa4e..5f14cf1 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift @@ -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 = [] // 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 {