diff --git a/CountriesSwiftUI/Repositories/Database/CountriesDBRepository.swift b/CountriesSwiftUI/Repositories/Database/CountriesDBRepository.swift index c145abf..388f9da 100644 --- a/CountriesSwiftUI/Repositories/Database/CountriesDBRepository.swift +++ b/CountriesSwiftUI/Repositories/Database/CountriesDBRepository.swift @@ -41,8 +41,8 @@ extension MainDBRepository: CountriesDBRepository { let alpha3Code = country.alpha3Code try modelContext.transaction { let currencies = countryDetails.currencies.map { $0.dbModel() } - let neighborsFetch = FetchDescriptor(predicate: #Predicate { - countryDetails.borders.contains($0.alpha3Code) + let neighborsFetch = FetchDescriptor(predicate: #Predicate { countryDBModel in + countryDetails.borders?.contains(countryDBModel.alpha3Code) == true }) let neighbors = try modelContext.fetch(neighborsFetch) currencies.forEach { diff --git a/CountriesSwiftUI/Repositories/Models/CountryDetails.swift b/CountriesSwiftUI/Repositories/Models/CountryDetails.swift index a6efa7b..89e67c5 100644 --- a/CountriesSwiftUI/Repositories/Models/CountryDetails.swift +++ b/CountriesSwiftUI/Repositories/Models/CountryDetails.swift @@ -16,7 +16,7 @@ extension DBModel { @Attribute(.unique) var alpha3Code: String var capital: String var currencies: [Currency] - var neighbors: [Country] + var neighbors: [Country]? init(alpha3Code: String, capital: String, currencies: [Currency], neighbors: [Country]) { self.alpha3Code = alpha3Code @@ -33,6 +33,6 @@ extension ApiModel { struct CountryDetails: Codable, Equatable { let capital: String let currencies: [Currency] - let borders: [String] + let borders: [String]? } } diff --git a/CountriesSwiftUI/Repositories/WebAPI/CountriesWebRepository.swift b/CountriesSwiftUI/Repositories/WebAPI/CountriesWebRepository.swift index ed91db9..b0c702d 100644 --- a/CountriesSwiftUI/Repositories/WebAPI/CountriesWebRepository.swift +++ b/CountriesSwiftUI/Repositories/WebAPI/CountriesWebRepository.swift @@ -49,7 +49,7 @@ extension RealCountriesWebRepository.API: APICall { var path: String { switch self { case .allCountries: - return "/all" + return "/all?fields=name,translations,population,flag,alpha3Code" case let .countryDetails(countryName): let encodedName = countryName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) return "/name/\(encodedName ?? countryName)" diff --git a/CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift b/CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift index 7a147a3..8113c58 100644 --- a/CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift +++ b/CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift @@ -105,8 +105,10 @@ private extension CountryDetails { if countryDetails.currencies.count > 0 { currenciesSectionView(currencies: countryDetails.currencies) } - if countryDetails.neighbors.count > 0 { - neighborsSectionView(neighbors: countryDetails.neighbors) + if let neighbors = countryDetails.neighbors { + if neighbors.count > 0 { + neighborsSectionView(neighbors: neighbors) + } } } .listStyle(GroupedListStyle())