-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Assignment] 4주차 과제
- Loading branch information
Showing
46 changed files
with
1,217 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Config.swift | ||
// Core | ||
// | ||
// Created by 류희재 on 2023/11/17. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Foundation | ||
|
||
import Foundation | ||
|
||
public struct Config { | ||
public static let apiKey = Bundle.main.infoDictionary?["API_KEY"] as! String | ||
public static let baseURL = Bundle.main.infoDictionary?["BASE_URL"] as! String | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Config.xcconfig | ||
// Core | ||
// | ||
// Created by 류희재 on 2023/11/17. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
// Configuration settings file format documentation can be found at: | ||
// https://help.apple.com/xcode/#/dev745c5c974 | ||
|
||
BASE_URL = https:/$()/api.openweathermap.org/data/2.5 | ||
API_KEY = 7618d35ff394f5dd39212928a3a4692f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// City.swift | ||
// Core | ||
// | ||
// Created by 류희재 on 2023/11/16. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class City { | ||
public static let cityList = ["gongju", "gwangju", "gumi", "gunsan", "daegu", "daejeon", "mokpo", "busan", "seosan", "seoul", "sokcho", "suwon", "suncheon", "ulsan", "iksan", "jeonju", "jeju", "cheonan", "cheongju", "chuncheon"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Weather+.swift | ||
// Core | ||
// | ||
// Created by 류희재 on 2023/11/16. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final public class WeatherUtil { | ||
public static func makeTimeZoneToTime(timeZone: Int) -> String { | ||
let today = Date() | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.timeZone = TimeZone(secondsFromGMT: timeZone) | ||
dateFormatter.dateFormat = "HH:mm" | ||
return dateFormatter.string(from: today) | ||
} | ||
|
||
public static func makedtTextToTime(_ dtText: String) -> String { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
guard let date = dateFormatter.date(from: dtText) else { return ""} | ||
let timeFormatter = DateFormatter() | ||
timeFormatter.dateFormat = "HH" | ||
let timeString = timeFormatter.string(from: date) | ||
return timeString | ||
} | ||
|
||
public static func weatherIconToUrl(_ icon: String) -> String { | ||
return "http://openweathermap.org/img/wn/\(icon).png" | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
Projects/Data/Sources/Repository/DefaultWeatherRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// DefaultWeatherRepository.swift | ||
// ProjectDescriptionHelpers | ||
// | ||
// Created by 류희재 on 2023/11/14. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
import Domain | ||
import Networks | ||
|
||
public class DefaultWeatherRepository: WeatherRepository { | ||
|
||
typealias Error = URLSessionNetworkServiceError | ||
public let urlSessionService: URLSessionNetworkService | ||
private let disposeBag = DisposeBag() | ||
|
||
public init(urlSessionService: URLSessionNetworkService) { | ||
self.urlSessionService = urlSessionService | ||
} | ||
|
||
public func getCityWeatherData(city: String) -> Observable<CurrentWeatherModel> { | ||
return urlSessionService.request(target: WeatherAPI.getCurrentWeatherData(city: city)) | ||
.map({ result in | ||
switch result { | ||
case .success(let data): | ||
guard let dto = self.decode(data: data, to: CurrentWeatherEntity.self) else { throw Error.responseDecodingError } | ||
return dto.toDomain() | ||
case .failure(let error): | ||
throw error | ||
} | ||
}) | ||
} | ||
|
||
public func getHourlyWeatherData(city: String) -> Observable<[HourlyWeatherModel]> { | ||
return urlSessionService.request(target: WeatherAPI.getHourlyWeatherData(city: city)).map({ result in | ||
switch result { | ||
case .success(let data): | ||
guard let dto = self.decode(data: data, to: HourlyWeatherEntity.self) else { throw Error.responseDecodingError } | ||
return dto.toDomain() | ||
case .failure(let error): | ||
throw error | ||
} | ||
}) | ||
} | ||
|
||
|
||
|
||
private func decode<T: Decodable>(data: Data, to target: T.Type) -> T? { | ||
return try? JSONDecoder().decode(target, from: data) | ||
} | ||
|
||
|
||
} | ||
|
25 changes: 25 additions & 0 deletions
25
Projects/Data/Sources/Transform/CurrentWeatherTransform.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// transform.swift | ||
// ProjectDescriptionHelpers | ||
// | ||
// Created by 류희재 on 2023/11/14. | ||
// | ||
|
||
import Foundation | ||
|
||
import Core | ||
import Networks | ||
import Domain | ||
|
||
extension CurrentWeatherEntity { | ||
public func toDomain() -> CurrentWeatherModel { | ||
return CurrentWeatherModel( | ||
time: WeatherUtil.makeTimeZoneToTime(timeZone: timezone), | ||
place: name, | ||
weather: weather[0].main, | ||
temparature: main.temp, | ||
maxTemparature: main.tempMax, | ||
minTemparature: main.tempMin | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Projects/Data/Sources/Transform/HourlyWeatherTransform.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// HourlyWeatherTransform.swift | ||
// Data | ||
// | ||
// Created by 류희재 on 2023/11/16. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Core | ||
import Networks | ||
import Domain | ||
|
||
extension HourlyWeatherEntity { | ||
public func toDomain() -> [HourlyWeatherModel] { | ||
var hourlyWeatherData: [HourlyWeatherModel] = [] | ||
for hourlyWeather in list { | ||
hourlyWeatherData.append( | ||
HourlyWeatherModel( | ||
time: WeatherUtil.makedtTextToTime(hourlyWeather.dtTxt), | ||
temparature: hourlyWeather.main.temp, | ||
weatherImage: WeatherUtil.weatherIconToUrl(hourlyWeather.weather[0].icon) | ||
) | ||
) | ||
} | ||
return hourlyWeatherData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// WeatherModel.swift | ||
// Domain | ||
// | ||
// Created by 류희재 on 2023/10/24. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
public struct CurrentWeatherModel { | ||
public let time, place, weather: String | ||
public let temparature, maxTemparature, minTemparature: Double | ||
|
||
public init( | ||
time: String, | ||
place: String, | ||
weather: String, | ||
temparature: Double, | ||
maxTemparature: Double, | ||
minTemparature: Double | ||
) { | ||
self.time = time | ||
self.place = place | ||
self.weather = weather | ||
self.temparature = temparature | ||
self.maxTemparature = maxTemparature | ||
self.minTemparature = minTemparature | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// WeatherHourlyModel.swift | ||
// Domain | ||
// | ||
// Created by 류희재 on 2023/10/25. | ||
// Copyright © 2023 hellohidi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
import DSKit | ||
|
||
public struct HourlyWeatherModel { | ||
public let time, weatherImage: String | ||
public let temparature: Double | ||
|
||
public init(time: String, temparature: Double, weatherImage: String) { | ||
self.time = time | ||
self.temparature = temparature | ||
self.weatherImage = weatherImage | ||
} | ||
} |
Oops, something went wrong.