-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] #319 - TargetType 및 Service 작성
- Loading branch information
1 parent
76feb7a
commit 1aedc2a
Showing
5 changed files
with
184 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
44 changes: 44 additions & 0 deletions
44
Hankkijogbo/Hankkijogbo/Network/NaverMap/DTO/Response/GetHankkiAddressResponseDTO.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,44 @@ | ||
// | ||
// GetHankkiAddressResponseDTO.swift | ||
// Hankkijogbo | ||
// | ||
// Created by 서은수 on 12/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Naver Reverse Geocoding API Res | ||
|
||
struct ReverseGeocodingBaseDTO: Decodable { | ||
let code: Int | ||
let name: String | ||
let message: String | ||
} | ||
|
||
struct GetHankkiAddressResponseDTO: Decodable { | ||
let status: ReverseGeocodingBaseDTO | ||
let results: [GetHankkiAddressResult?] | ||
} | ||
|
||
struct GetHankkiAddressResult: Decodable { | ||
let region: Region? | ||
let land: Land? | ||
} | ||
|
||
struct Region: Decodable { | ||
let area1: Area1? | ||
let area2, area3, area4: Area? | ||
} | ||
|
||
struct Area1: Decodable { | ||
let name, alias: String? | ||
} | ||
|
||
struct Area: Decodable { | ||
let name: String? | ||
} | ||
|
||
struct Land: Decodable { | ||
let name: String? | ||
let number1, number2: String? | ||
} |
38 changes: 38 additions & 0 deletions
38
Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapAPIService.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,38 @@ | ||
// | ||
// NaverMapAPIService.swift | ||
// Hankkijogbo | ||
// | ||
// Created by 서은수 on 12/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
protocol NaverMapAPIServiceProtocol { | ||
func getHankkiAddress(latitude: Double, longitude: Double, completion: @escaping(NetworkResult<GetHankkiAddressResponseDTO>) -> Void) | ||
} | ||
|
||
final class NaverMapAPIService: BaseAPIService, NaverMapAPIServiceProtocol { | ||
|
||
private let provider = MoyaProvider<NaverMapTargetType>(plugins: [MoyaPlugin.shared]) | ||
|
||
func getHankkiAddress( | ||
latitude: Double, | ||
longitude: Double, | ||
completion: @escaping (NetworkResult<GetHankkiAddressResponseDTO>) -> Void) { | ||
provider.request(.getHankkiAddress(latitude: latitude, longitude: longitude)) { result in | ||
switch result { | ||
case .success(let response): | ||
let networkResult: NetworkResult<GetHankkiAddressResponseDTO> = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data) | ||
print(networkResult) | ||
completion(networkResult) | ||
case .failure(let error): | ||
if let response = error.response { | ||
let networkResult: NetworkResult<GetHankkiAddressResponseDTO> = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data) | ||
completion(networkResult) | ||
} | ||
} | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapTargetType.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,65 @@ | ||
// | ||
// NaverMapTargetType.swift | ||
// Hankkijogbo | ||
// | ||
// Created by 서은수 on 12/30/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
enum NaverMapTargetType { | ||
|
||
case getHankkiAddress(latitude: Double, longitude: Double) | ||
} | ||
|
||
extension NaverMapTargetType: BaseTargetType { | ||
|
||
var loadingViewType: LoadingViewType { | ||
switch self { | ||
case .getHankkiAddress: return .fullView | ||
} | ||
} | ||
|
||
var headerType: HeaderType { | ||
return .naverMapHeader(clientId: Config.ReverseGeocodingClientId, clientSecret: Config.ReverseGeocodingClientSecret) | ||
} | ||
|
||
var utilPath: UtilPath { return .naverMap } | ||
|
||
var pathParameter: String? { | ||
switch self { | ||
case .getHankkiAddress: | ||
return .none | ||
} | ||
} | ||
|
||
var queryParameter: [String: Any]? { | ||
switch self { | ||
case .getHankkiAddress(let latitude, let longitude): | ||
return .some([ | ||
"coords": "\(longitude),\(latitude)", | ||
"orders": "roadaddr", // 도로명주소 | ||
"output": "json" | ||
]) | ||
} | ||
} | ||
|
||
var requestBodyParameter: Codable? { | ||
return .none | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .getHankkiAddress: | ||
return utilPath.rawValue | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .getHankkiAddress: .get | ||
} | ||
} | ||
} |