Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DBModel.Country> {
countryDetails.borders.contains($0.alpha3Code)
let neighborsFetch = FetchDescriptor(predicate: #Predicate<DBModel.Country> { countryDBModel in
countryDetails.borders?.contains(countryDBModel.alpha3Code) == true
})
let neighbors = try modelContext.fetch(neighborsFetch)
currencies.forEach {
Expand Down
4 changes: 2 additions & 2 deletions CountriesSwiftUI/Repositories/Models/CountryDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +33,6 @@ extension ApiModel {
struct CountryDetails: Codable, Equatable {
let capital: String
let currencies: [Currency]
let borders: [String]
let borders: [String]?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
6 changes: 4 additions & 2 deletions CountriesSwiftUI/UI/CountryDetails/CountryDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down