diff --git a/Hankkijogbo/Hankkijogbo.xcodeproj/project.pbxproj b/Hankkijogbo/Hankkijogbo.xcodeproj/project.pbxproj index 0f711693..2375ae61 100644 --- a/Hankkijogbo/Hankkijogbo.xcodeproj/project.pbxproj +++ b/Hankkijogbo/Hankkijogbo.xcodeproj/project.pbxproj @@ -153,6 +153,9 @@ A23D11972C47FFB90023480C /* SearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23D11962C47FFB90023480C /* SearchViewModel.swift */; }; A23D119A2C4811790023480C /* HankkiDebouncer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23D11992C4811790023480C /* HankkiDebouncer.swift */; }; A23D119C2C4844AE0023480C /* PostHankkiValidateRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23D119B2C4844AE0023480C /* PostHankkiValidateRequestDTO.swift */; }; + A23F354F2D2211B200B6F8C8 /* NaverMapAPIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23F354E2D2211B200B6F8C8 /* NaverMapAPIService.swift */; }; + A23F35512D2211BF00B6F8C8 /* NaverMapTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23F35502D2211BF00B6F8C8 /* NaverMapTargetType.swift */; }; + A23F35552D22135200B6F8C8 /* GetHankkiAddressResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A23F35542D22135200B6F8C8 /* GetHankkiAddressResponseDTO.swift */; }; A240EA082C3EF6E0000FF458 /* BufferView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A240EA072C3EF6E0000FF458 /* BufferView.swift */; }; A240EA0C2C3EFD77000FF458 /* CompositionalLayoutFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A240EA0B2C3EFD77000FF458 /* CompositionalLayoutFactory.swift */; }; A240EA192C3F35BC000FF458 /* SearchBarCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A240EA182C3F35BC000FF458 /* SearchBarCollectionViewCell.swift */; }; @@ -384,6 +387,9 @@ A23D11962C47FFB90023480C /* SearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewModel.swift; sourceTree = ""; }; A23D11992C4811790023480C /* HankkiDebouncer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HankkiDebouncer.swift; sourceTree = ""; }; A23D119B2C4844AE0023480C /* PostHankkiValidateRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHankkiValidateRequestDTO.swift; sourceTree = ""; }; + A23F354E2D2211B200B6F8C8 /* NaverMapAPIService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NaverMapAPIService.swift; sourceTree = ""; }; + A23F35502D2211BF00B6F8C8 /* NaverMapTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NaverMapTargetType.swift; sourceTree = ""; }; + A23F35542D22135200B6F8C8 /* GetHankkiAddressResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetHankkiAddressResponseDTO.swift; sourceTree = ""; }; A240EA072C3EF6E0000FF458 /* BufferView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BufferView.swift; sourceTree = ""; }; A240EA0B2C3EFD77000FF458 /* CompositionalLayoutFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositionalLayoutFactory.swift; sourceTree = ""; }; A240EA182C3F35BC000FF458 /* SearchBarCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarCollectionViewCell.swift; sourceTree = ""; }; @@ -698,6 +704,7 @@ A2EC33A92C4711A000809840 /* Report */, A24A78792CB44E110049B031 /* Menu */, A2EC33AA2C4711A600809840 /* Location */, + A23F354D2D2211A000B6F8C8 /* NaverMap */, ); path = Network; sourceTree = ""; @@ -1361,6 +1368,32 @@ name = ViewModel; sourceTree = ""; }; + A23F354D2D2211A000B6F8C8 /* NaverMap */ = { + isa = PBXGroup; + children = ( + A23F35522D22134300B6F8C8 /* DTO */, + A23F35502D2211BF00B6F8C8 /* NaverMapTargetType.swift */, + A23F354E2D2211B200B6F8C8 /* NaverMapAPIService.swift */, + ); + path = NaverMap; + sourceTree = ""; + }; + A23F35522D22134300B6F8C8 /* DTO */ = { + isa = PBXGroup; + children = ( + A23F35532D22134900B6F8C8 /* Response */, + ); + path = DTO; + sourceTree = ""; + }; + A23F35532D22134900B6F8C8 /* Response */ = { + isa = PBXGroup; + children = ( + A23F35542D22135200B6F8C8 /* GetHankkiAddressResponseDTO.swift */, + ); + path = Response; + sourceTree = ""; + }; A240EA092C3EF712000FF458 /* HankkiReusableView */ = { isa = PBXGroup; children = ( @@ -1976,6 +2009,7 @@ 86880C2A2C47F2DF00CAEF58 /* HankkiListViewModel.swift in Sources */, 8641516B2C67B9AE00E2FD44 /* MyZipListCollectionViewCell.swift in Sources */, A2C9FCB12C49985800868DF7 /* GetZipListResponseDTO.swift in Sources */, + A23F35552D22135200B6F8C8 /* GetHankkiAddressResponseDTO.swift in Sources */, A240EA442C446AB6000FF458 /* HankkiDetailButton.swift in Sources */, A2AF6FDB2CE61AA000F5271D /* MenuResponseDTO.swift in Sources */, 839138DF2C4962E500611D5C /* GetHankkiThumbnailResponseDTO.swift in Sources */, @@ -2008,10 +2042,12 @@ 86880C0F2C47116900CAEF58 /* DeleteZipToHankkRequestiDTO.swift in Sources */, 83DBED942C2564A20042BA48 /* HomeView.swift in Sources */, 86880BF42C46E89C00CAEF58 /* GetMeUniversityResponseDTO.swift in Sources */, + A23F354F2D2211B200B6F8C8 /* NaverMapAPIService.swift in Sources */, A2FF94112C31660E001ADA03 /* BaseDTO.swift in Sources */, A200C66F2D19EA0D0065C749 /* DetailMapView.swift in Sources */, 837F10DC2C4A851A00E3CCE6 /* ReportCompleteViewController.swift in Sources */, 865D59C62C7B72C9004CC517 /* FullLoadingView.swift in Sources */, + A23F35512D2211BF00B6F8C8 /* NaverMapTargetType.swift in Sources */, 86B761232C3EC87A00413059 /* ZipListCollectionViewCellModel.swift in Sources */, 83DBEDCA2C256AE70042BA48 /* UIViewController+.swift in Sources */, A23D11972C47FFB90023480C /* SearchViewModel.swift in Sources */, diff --git a/Hankkijogbo/Hankkijogbo/Network/Base/NetworkService.swift b/Hankkijogbo/Hankkijogbo/Network/Base/NetworkService.swift index ac1df0ae..bf011d4e 100644 --- a/Hankkijogbo/Hankkijogbo/Network/Base/NetworkService.swift +++ b/Hankkijogbo/Hankkijogbo/Network/Base/NetworkService.swift @@ -21,6 +21,7 @@ final class NetworkService { let locationService: LocationAPIServiceProtocol = LocationAPIService() let zipService: ZipAPIServiceProtocol = ZipAPIService() let reportService: ReportAPIServiceProtocol = ReportAPIService() + let naverMapService: NaverMapAPIServiceProtocol = NaverMapAPIService() } extension NetworkService { diff --git a/Hankkijogbo/Hankkijogbo/Network/NaverMap/DTO/Response/GetHankkiAddressResponseDTO.swift b/Hankkijogbo/Hankkijogbo/Network/NaverMap/DTO/Response/GetHankkiAddressResponseDTO.swift new file mode 100644 index 00000000..a4ad2f4a --- /dev/null +++ b/Hankkijogbo/Hankkijogbo/Network/NaverMap/DTO/Response/GetHankkiAddressResponseDTO.swift @@ -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? +} diff --git a/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapAPIService.swift b/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapAPIService.swift new file mode 100644 index 00000000..67efc618 --- /dev/null +++ b/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapAPIService.swift @@ -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) -> Void) +} + +final class NaverMapAPIService: BaseAPIService, NaverMapAPIServiceProtocol { + + private let provider = MoyaProvider(plugins: [MoyaPlugin.shared]) + + func getHankkiAddress( + latitude: Double, + longitude: Double, + completion: @escaping (NetworkResult) -> Void) { + provider.request(.getHankkiAddress(latitude: latitude, longitude: longitude)) { result in + switch result { + case .success(let response): + let networkResult: NetworkResult = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data) + print(networkResult) + completion(networkResult) + case .failure(let error): + if let response = error.response { + let networkResult: NetworkResult = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data) + completion(networkResult) + } + } + } + } +} diff --git a/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapTargetType.swift b/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapTargetType.swift new file mode 100644 index 00000000..b7787840 --- /dev/null +++ b/Hankkijogbo/Hankkijogbo/Network/NaverMap/NaverMapTargetType.swift @@ -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 + } + } +}