Skip to content

Commit f1ac880

Browse files
authored
Merge pull request #110 from adosari/master
Quick fix for the new API rule for \all route
2 parents 8e5c34a + c0a177a commit f1ac880

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

CountriesSwiftUI/Repositories/Database/CountriesDBRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ extension MainDBRepository: CountriesDBRepository {
4141
let alpha3Code = country.alpha3Code
4242
try modelContext.transaction {
4343
let currencies = countryDetails.currencies.map { $0.dbModel() }
44-
let neighborsFetch = FetchDescriptor(predicate: #Predicate<DBModel.Country> {
45-
countryDetails.borders.contains($0.alpha3Code)
44+
let neighborsFetch = FetchDescriptor(predicate: #Predicate<DBModel.Country> { countryDBModel in
45+
countryDetails.borders?.contains(countryDBModel.alpha3Code) == true
4646
})
4747
let neighbors = try modelContext.fetch(neighborsFetch)
4848
currencies.forEach {

CountriesSwiftUI/Repositories/Models/CountryDetails.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension DBModel {
1616
@Attribute(.unique) var alpha3Code: String
1717
var capital: String
1818
var currencies: [Currency]
19-
var neighbors: [Country]
19+
var neighbors: [Country]?
2020

2121
init(alpha3Code: String, capital: String, currencies: [Currency], neighbors: [Country]) {
2222
self.alpha3Code = alpha3Code
@@ -33,6 +33,6 @@ extension ApiModel {
3333
struct CountryDetails: Codable, Equatable {
3434
let capital: String
3535
let currencies: [Currency]
36-
let borders: [String]
36+
let borders: [String]?
3737
}
3838
}

CountriesSwiftUI/Repositories/WebAPI/CountriesWebRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension RealCountriesWebRepository.API: APICall {
4949
var path: String {
5050
switch self {
5151
case .allCountries:
52-
return "/all"
52+
return "/all?fields=name,translations,population,flag,alpha3Code"
5353
case let .countryDetails(countryName):
5454
let encodedName = countryName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
5555
return "/name/\(encodedName ?? countryName)"

CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ private extension CountryDetails {
105105
if countryDetails.currencies.count > 0 {
106106
currenciesSectionView(currencies: countryDetails.currencies)
107107
}
108-
if countryDetails.neighbors.count > 0 {
109-
neighborsSectionView(neighbors: countryDetails.neighbors)
108+
if let neighbors = countryDetails.neighbors {
109+
if neighbors.count > 0 {
110+
neighborsSectionView(neighbors: neighbors)
111+
}
110112
}
111113
}
112114
.listStyle(GroupedListStyle())

0 commit comments

Comments
 (0)