forked from yagom-academy/ios-diary
-
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.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 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,35 @@ | ||
// | ||
// APIError.swift | ||
// Diary | ||
// | ||
// Created by Max, Hemg on 2023/09/13. | ||
// | ||
|
||
enum APIError: Error { | ||
case invalidURL | ||
case requestFail | ||
case invalidData | ||
case dataTransferFail | ||
case decodingFail | ||
case invalidHTTPStatusCode | ||
case requestTimeOut | ||
|
||
var errorDescription: String? { | ||
switch self { | ||
case .invalidURL: | ||
return "유효하지 않은 URL입니다." | ||
case .requestFail: | ||
return "요청에 실패했습니다." | ||
case .decodingFail: | ||
return "디코딩 실패했습니다." | ||
case .invalidData: | ||
return "잘못된 데이터 입니다." | ||
case .dataTransferFail: | ||
return "데이터 변환에 실패했습니다." | ||
case .invalidHTTPStatusCode: | ||
return "잘못된 HTTPStatusCode입니다." | ||
case . requestTimeOut: | ||
return "요청시간이 초과되었습니다." | ||
} | ||
} | ||
} |
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,75 @@ | ||
// | ||
// WeatherResult.swift | ||
// Diary | ||
// | ||
// Created by Max, Hemg on 2023/09/13. | ||
// | ||
|
||
struct WeatherResult: Decodable { | ||
let coord: Coord | ||
let weather: [Weather] | ||
let base: String | ||
let main: Main | ||
let visibility: Int | ||
let wind: Wind | ||
let clouds: Clouds | ||
let date: Int | ||
let sys: Sys | ||
let timezone, id: Int | ||
let name: String | ||
let cod: Int | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case coord, weather, base, main, visibility, wind, clouds | ||
case date = "dt" | ||
case sys, timezone, id, name, cod | ||
} | ||
} | ||
|
||
struct Coord: Decodable { | ||
let longitude: Double | ||
let latitude: Double | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case longitude = "lon" | ||
case latitude = "lat" | ||
} | ||
} | ||
|
||
struct Weather: Decodable { | ||
let id: Int | ||
let main: String | ||
let description: String | ||
let icon: String | ||
} | ||
|
||
struct Main: Decodable { | ||
let temp, feelsLike, tempMin, tempMax: Double | ||
let pressure, humidity, seaLevel, groundLevel: Int? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case temp | ||
case feelsLike = "feels_like" | ||
case tempMin = "temp_min" | ||
case tempMax = "temp_max" | ||
case pressure, humidity | ||
case seaLevel = "sea_level" | ||
case groundLevel = "grnd_level" | ||
} | ||
} | ||
|
||
struct Sys: Decodable { | ||
let type, id: Int | ||
let country: String | ||
let sunrise, sunset: Int | ||
} | ||
|
||
struct Clouds: Decodable { | ||
let all: Int | ||
} | ||
|
||
struct Wind: Decodable { | ||
let speed: Double | ||
let deg: Int | ||
let gust: Double? | ||
} |