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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct FetchWeatherUseCase: FetchWeatherType {
}

if date > currentDate && DateUtil.isWithinThreeDaysFromToday(startDate: currentDate, endDate: date) {
return try await fetchDayWeather(location: location)
return try await fetchDayWeather(location: location, targetDate: date)
}

return nil
Expand All @@ -45,14 +45,22 @@ struct FetchWeatherUseCase: FetchWeatherType {
return .init(weatherCondition: condition, uvIndex: uv)
}

private func fetchDayWeather(location: CLLocation) async throws -> WeatherEntity? {
private func fetchDayWeather(
location: CLLocation,
targetDate: Date
) async throws -> WeatherEntity? {
let dailyWeather = try await WeatherService.shared.weather(for: location, including: .daily)
guard let dailyFirstWeather = dailyWeather.forecast.first else {

let calendar = Calendar.current

guard let targetDayWeather = dailyWeather.forecast.first(where: {
calendar.isDate($0.date, inSameDayAs: targetDate)
}) else {
return nil
}
let condition = dailyFirstWeather.condition
let uv = dailyFirstWeather.uvIndex

let condition = targetDayWeather.condition
let uv = targetDayWeather.uvIndex

return .init(weatherCondition: condition, uvIndex: uv)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,16 @@ final class HomeViewModel: ViewModeling {
}

private func makeSupplyString(_ weather: WeatherEntity) -> NSMutableAttributedString? {
guard let weatherSupply = weather.weatherCondition.supply,
let uvSupply = weather.uvIndex.supply else {
let supplies = [
weather.weatherCondition.supply,
weather.uvIndex.supply
].compactMap { $0 }

guard !supplies.isEmpty else {
return nil
}
let supplyString = "\(weatherSupply), \(uvSupply)!"

let supplyString = supplies.joined(separator: ", ")
let customedSupplyString = supplyString.customText(
rangedText: supplyString,
color: UIColor.blue700.cgColor
Expand Down
Loading