From 5e650f9f4407a6f279232d7a1ca936b5daef0f24 Mon Sep 17 00:00:00 2001 From: hemg2 Date: Wed, 13 Sep 2023 11:31:16 +0900 Subject: [PATCH] feat: weatherModel --- Diary.xcodeproj/project.pbxproj | 20 +++++++++ Diary/Error/APIError.swift | 35 +++++++++++++++ Diary/Model/WeatherResult.swift | 75 +++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 Diary/Error/APIError.swift create mode 100644 Diary/Model/WeatherResult.swift diff --git a/Diary.xcodeproj/project.pbxproj b/Diary.xcodeproj/project.pbxproj index ce8f289e3..4abbe6fc9 100644 --- a/Diary.xcodeproj/project.pbxproj +++ b/Diary.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 459D493A878338290A3E0AEF /* Pods_Diary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDF8EB908CAD9D062C72898B /* Pods_Diary.framework */; }; + 632F74F02AB14D2C003E1B97 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632F74EF2AB14D2C003E1B97 /* NetworkManager.swift */; }; + 632F74F22AB14D8D003E1B97 /* WeatherResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632F74F12AB14D8D003E1B97 /* WeatherResult.swift */; }; + 632F74F42AB14DBC003E1B97 /* APIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632F74F32AB14DBC003E1B97 /* APIError.swift */; }; 636B19AC2AA6C5E900B5242D /* AlertDisplayble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 636B19AB2AA6C5E900B5242D /* AlertDisplayble.swift */; }; 63B12BAE2AAD9C9000D614A6 /* AlertNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */; }; 63B12BB02AAD9D3400D614A6 /* ButtonNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */; }; @@ -32,6 +35,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 632F74EF2AB14D2C003E1B97 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = ""; }; + 632F74F12AB14D8D003E1B97 /* WeatherResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherResult.swift; sourceTree = ""; }; + 632F74F32AB14DBC003E1B97 /* APIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIError.swift; sourceTree = ""; }; 636B19AB2AA6C5E900B5242D /* AlertDisplayble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertDisplayble.swift; sourceTree = ""; }; 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNamespace.swift; sourceTree = ""; }; 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonNamespace.swift; sourceTree = ""; }; @@ -89,6 +95,14 @@ name = Frameworks; sourceTree = ""; }; + 632F74EE2AB14CF3003E1B97 /* Network */ = { + isa = PBXGroup; + children = ( + 632F74EF2AB14D2C003E1B97 /* NetworkManager.swift */, + ); + path = Network; + sourceTree = ""; + }; 636B19AA2AA6C5C200B5242D /* Protocol */ = { isa = PBXGroup; children = ( @@ -124,6 +138,7 @@ 63BB62812A9F109400524DCB /* DecodingManager.swift */, 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */, 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */, + 632F74F12AB14D8D003E1B97 /* WeatherResult.swift */, ); path = Model; sourceTree = ""; @@ -159,6 +174,7 @@ children = ( BABBDAE42A9F13A200D8D50B /* DecodingError.swift */, BABBDB352AAD904100D8D50B /* CoreDataError.swift */, + 632F74F32AB14DBC003E1B97 /* APIError.swift */, ); path = Error; sourceTree = ""; @@ -185,6 +201,7 @@ C739AE23284DF28600741E8F /* Diary */ = { isa = PBXGroup; children = ( + 632F74EE2AB14CF3003E1B97 /* Network */, 636B19AA2AA6C5C200B5242D /* Protocol */, 63BB62B62AA185E700524DCB /* DataManager */, 63E5273E2A9ECD800000FBA6 /* Extension */, @@ -321,10 +338,12 @@ C739AE27284DF28600741E8F /* SceneDelegate.swift in Sources */, 636B19AC2AA6C5E900B5242D /* AlertDisplayble.swift in Sources */, 63BB62822A9F109400524DCB /* DecodingManager.swift in Sources */, + 632F74F22AB14D8D003E1B97 /* WeatherResult.swift in Sources */, BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */, 63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */, C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */, 63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */, + 632F74F02AB14D2C003E1B97 /* NetworkManager.swift in Sources */, 63E527392A9D97160000FBA6 /* DiaryDetailViewContoller.swift in Sources */, BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */, BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */, @@ -334,6 +353,7 @@ BA1A55EB2A9D84AF0012C89D /* DiaryEntity.swift in Sources */, 63B12BAE2AAD9C9000D614A6 /* AlertNamespace.swift in Sources */, 63BB62B22AA181BE00524DCB /* Diary+CoreDataClass.swift in Sources */, + 632F74F42AB14DBC003E1B97 /* APIError.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Diary/Error/APIError.swift b/Diary/Error/APIError.swift new file mode 100644 index 000000000..48f9374e5 --- /dev/null +++ b/Diary/Error/APIError.swift @@ -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 "요청시간이 초과되었습니다." + } + } +} diff --git a/Diary/Model/WeatherResult.swift b/Diary/Model/WeatherResult.swift new file mode 100644 index 000000000..be2707e9f --- /dev/null +++ b/Diary/Model/WeatherResult.swift @@ -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? +}