diff --git a/.swiftlint.yml b/.swiftlint.yml index ffd35e67..28bdb142 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -5,7 +5,10 @@ disabled_rules: - function_parameter_count - function_body_length - cyclomatic_complexity -- force_cast +- type_body_length +- file_length +- identifier_name +- large_tuple excluded: - Pods - NADA-iOS-forRelease/Sources/AppDelegate.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index 14eb1141..314955f5 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -82,12 +82,16 @@ 77703157275005AA002CBD19 /* CardResultBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77703156275005AA002CBD19 /* CardResultBottomSheetViewController.swift */; }; 7770315927500C49002CBD19 /* QRScan.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7770315827500C49002CBD19 /* QRScan.storyboard */; }; 7770315B27500C7B002CBD19 /* QRScanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7770315A27500C7B002CBD19 /* QRScanViewController.swift */; }; + 777B2C222A00E15000A6AB27 /* NearByRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777B2C212A00E15000A6AB27 /* NearByRequest.swift */; }; + 777B2C242A00E7C700A6AB27 /* NearByUUIDResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */; }; 777FF89B27359B7800BF69D3 /* Groups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89A27359B7800BF69D3 /* Groups.swift */; }; 777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */; }; 777FF89F27364B7B00BF69D3 /* GroupEditRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */; }; 77812947275F6EA3004B34F4 /* CardDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77812946275F6EA3004B34F4 /* CardDetailViewController.swift */; }; 7781294A275F6ED7004B34F4 /* CardDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77812949275F6ED7004B34F4 /* CardDetail.storyboard */; }; 77A196C429F4DB2E000DEF49 /* GroupEditViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A196C329F4DB2E000DEF49 /* GroupEditViewModel.swift */; }; + 77A196C729F661DC000DEF49 /* NearbyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A196C629F661DC000DEF49 /* NearbyAPI.swift */; }; + 77A196C929F661E3000DEF49 /* NearbyService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A196C829F661E3000DEF49 /* NearbyService.swift */; }; 77A4D5EB29AE20CB00367B7C /* makeVibrate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */; }; 77A4D5EF29AE269B00367B7C /* AroundMeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5EE29AE269B00367B7C /* AroundMeViewController.swift */; }; 77A4D5F429AE291F00367B7C /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5F329AE291F00367B7C /* CustomNavigationBar.swift */; }; @@ -98,6 +102,7 @@ 77A4D60429BD743600367B7C /* ModuleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60329BD743600367B7C /* ModuleFactory.swift */; }; 77A4D60629BD747300367B7C /* controllerFromStoryBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */; }; 77A4D60829BD74BC00367B7C /* getClassName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60729BD74BC00367B7C /* getClassName.swift */; }; + 77A4D60A29C09D2900367B7C /* calculateTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60929C09D2900367B7C /* calculateTime.swift */; }; 77AA68EA273E0EC4009C89B0 /* CardAddInGroupRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */; }; 77B4E7482990E420006098DC /* Home.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77B4E7472990E420006098DC /* Home.storyboard */; }; 77B4E74B2990E50E006098DC /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B4E74A2990E50E006098DC /* HomeViewController.swift */; }; @@ -333,12 +338,16 @@ 7770315827500C49002CBD19 /* QRScan.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = QRScan.storyboard; sourceTree = ""; }; 7770315A27500C7B002CBD19 /* QRScanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScanViewController.swift; sourceTree = ""; }; 777B2C202A00BEB300A6AB27 /* IntentsExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = IntentsExtension.entitlements; sourceTree = ""; }; + 777B2C212A00E15000A6AB27 /* NearByRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearByRequest.swift; sourceTree = ""; }; + 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearByUUIDResponse.swift; sourceTree = ""; }; 777FF89A27359B7800BF69D3 /* Groups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Groups.swift; sourceTree = ""; }; 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAddRequest.swift; sourceTree = ""; }; 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupEditRequest.swift; sourceTree = ""; }; 77812946275F6EA3004B34F4 /* CardDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDetailViewController.swift; sourceTree = ""; }; 77812949275F6ED7004B34F4 /* CardDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardDetail.storyboard; sourceTree = ""; }; 77A196C329F4DB2E000DEF49 /* GroupEditViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupEditViewModel.swift; sourceTree = ""; }; + 77A196C629F661DC000DEF49 /* NearbyAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyAPI.swift; sourceTree = ""; }; + 77A196C829F661E3000DEF49 /* NearbyService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyService.swift; sourceTree = ""; }; 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = makeVibrate.swift; sourceTree = ""; }; 77A4D5EE29AE269B00367B7C /* AroundMeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeViewController.swift; sourceTree = ""; }; 77A4D5F329AE291F00367B7C /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; @@ -349,6 +358,7 @@ 77A4D60329BD743600367B7C /* ModuleFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleFactory.swift; sourceTree = ""; }; 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = controllerFromStoryBoard.swift; sourceTree = ""; }; 77A4D60729BD74BC00367B7C /* getClassName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = getClassName.swift; sourceTree = ""; }; + 77A4D60929C09D2900367B7C /* calculateTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = calculateTime.swift; sourceTree = ""; }; 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAddInGroupRequest.swift; sourceTree = ""; }; 77B4E7422990E00B006098DC /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 77B4E7432990E015006098DC /* Beta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Beta.xcconfig; sourceTree = ""; }; @@ -810,11 +820,21 @@ path = VC; sourceTree = ""; }; + 77A196C529F661C4000DEF49 /* Nearby */ = { + isa = PBXGroup; + children = ( + 77A196C629F661DC000DEF49 /* NearbyAPI.swift */, + 77A196C829F661E3000DEF49 /* NearbyService.swift */, + ); + path = Nearby; + sourceTree = ""; + }; 77A4D5E929AE20A600367B7C /* Utils */ = { isa = PBXGroup; children = ( 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */, 77A4D60729BD74BC00367B7C /* getClassName.swift */, + 77A4D60929C09D2900367B7C /* calculateTime.swift */, ); path = Utils; sourceTree = ""; @@ -874,6 +894,8 @@ isa = PBXGroup; children = ( 77A4D60029BD708C00367B7C /* AroundMeResponse.swift */, + 777B2C212A00E15000A6AB27 /* NearByRequest.swift */, + 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */, ); path = AroundMe; sourceTree = ""; @@ -1334,6 +1356,7 @@ F8C83FB0272F9CB10009DF0D /* Card */, F8C83FB3272F9CF30009DF0D /* Group */, F8C83FB4272F9E250009DF0D /* Util */, + 77A196C529F661C4000DEF49 /* Nearby */, F8F00C3C29DD487E00A15377 /* Update */, ); path = NetworkService; @@ -1753,6 +1776,7 @@ F8C83FCB272FA32C0009DF0D /* GroupService.swift in Sources */, F88C8DE929B8919700196A33 /* ViewModelType.swift in Sources */, F858079E2700354E00872484 /* BackgroundCollectionViewCell.swift in Sources */, + 77A196C929F661E3000DEF49 /* NearbyService.swift in Sources */, F8C83FBD272F9F430009DF0D /* GenericResponse.swift in Sources */, 77A4D5F629BC304C00367B7C /* UIStackView+Extension.swift in Sources */, F835EF6F29800F51001ABAAF /* UIApplication+Extension.swift in Sources */, @@ -1761,6 +1785,7 @@ 7713E8482752E2A900724C8B /* SelectGroupBottomSheetViewController.swift in Sources */, 39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */, F8C83FB6272F9E380009DF0D /* UtilService.swift in Sources */, + 77A4D60A29C09D2900367B7C /* calculateTime.swift in Sources */, 3958F239270FFBBF00B100B2 /* GroupViewController.swift in Sources */, 3909242F26FA15E800236C51 /* UIView+Extension.swift in Sources */, 39523E09270184A700536900 /* CardListViewController.swift in Sources */, @@ -1852,6 +1877,7 @@ F84BAFAD26FDB543004CA335 /* FrontCardCreationCollectionViewCell.swift in Sources */, F8518054275D040C006BD5ED /* OnboardingCollectionViewCell.swift in Sources */, 77703157275005AA002CBD19 /* CardResultBottomSheetViewController.swift in Sources */, + 777B2C222A00E15000A6AB27 /* NearByRequest.swift in Sources */, F8D74DD8276C7FB60071E5FC /* UIImageView+Extension.swift in Sources */, F8F00C3929DD474700A15377 /* UpdateNote.swift in Sources */, 39D13565273FDB9C00B1A148 /* User.swift in Sources */, @@ -1865,11 +1891,13 @@ F8915A23275728F20013D609 /* SelectMBTIBottomViewController.swift in Sources */, 393E3345275F69EE00965BBF /* SplashViewController.swift in Sources */, F8C83FB8272F9E3F0009DF0D /* UtilAPI.swift in Sources */, + 77A196C729F661DC000DEF49 /* NearbyAPI.swift in Sources */, F8FC438826C01CDD0033E151 /* SceneDelegate.swift in Sources */, 77A4D5F929BC320600367B7C /* AroundMeCollectionViewCell.swift in Sources */, 39C394D4277CD33500DBA566 /* EmptyCardListTableViewCell.swift in Sources */, 77B4E74B2990E50E006098DC /* HomeViewController.swift in Sources */, 7734D5B427778EFB004360E4 /* HarmonyResponse.swift in Sources */, + 777B2C242A00E7C700A6AB27 /* NearByUUIDResponse.swift in Sources */, 397B75132763A916004AEB03 /* OpenSourceTableViewCell.swift in Sources */, F811720027383097002742CF /* ChangeGroupRequest.swift in Sources */, ); diff --git a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift new file mode 100644 index 00000000..7a4c6c6a --- /dev/null +++ b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift @@ -0,0 +1,57 @@ +// +// calculateTime.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/03/14. +// + +import Foundation + +func calculateTime(sec: Int) -> String { + let hour = sec / 3600 + let minute = (sec % 3600) / 60 + let second = (sec % 3600) % 60 + return "\(String(format: "%02d", hour)):\(String(format: "%02d", minute)):\(String(format: "%02d", second))" +} + +func calculateMinuteTime(sec: Int) -> String { + let minute = (sec % 3600) / 60 + let second = (sec % 3600) % 60 + return "\(String(format: "%02d", minute)):\(String(format: "%02d", second))" +} + +func calculateMinuteTimeToInt(time: String) -> Int { + let components = time.split { $0 == ":" } .map { (x) -> Int in return Int(String(x))! } + + let minutes = components[0] + let seconds = components[1] + let secondsCaculated = minutes*60 + seconds + return secondsCaculated +} + +extension Date { + + static func - (recent: Date, previous: Date) -> (month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?) { + let day = Calendar.current.dateComponents([.day], from: previous, to: recent).day + let month = Calendar.current.dateComponents([.month], from: previous, to: recent).month + let hour = Calendar.current.dateComponents([.hour], from: previous, to: recent).hour + let minute = Calendar.current.dateComponents([.minute], from: previous, to: recent).minute + let second = Calendar.current.dateComponents([.second], from: previous, to: recent).second + + return (month: month, day: day, hour: hour, minute: minute, second: second) + } + +} + +extension String { + func toDate() -> Date? { // "yyyy-MM-dd HH:mm:ss" + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" + dateFormatter.timeZone = TimeZone(identifier: "UTC") + if let date = dateFormatter.date(from: self) { + return date + } else { + return nil + } + } +} diff --git a/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift b/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift index d26128e9..c7b94bf7 100644 --- a/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift +++ b/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift @@ -9,7 +9,7 @@ import Foundation import UIKit extension UIViewController { - public func makeVibrate(degree: UIImpactFeedbackGenerator.FeedbackStyle = .medium) { + public func makeVibrate(degree: UIImpactFeedbackGenerator.FeedbackStyle = .medium) { let generator = UIImpactFeedbackGenerator(style: degree) generator.impactOccurred() } diff --git a/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift index 9c851992..4fbcfc0a 100644 --- a/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift +++ b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift @@ -25,7 +25,8 @@ import UIKit extension UIViewController { private class func instantiateControllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> T { - return storyboard.instantiateViewController(withIdentifier: identifier) as! T + guard let viewcontroller = storyboard.instantiateViewController(withIdentifier: identifier) as? T else { return T() } + return viewcontroller } class func controllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> Self { diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift index 2ea90a86..e50c5470 100644 --- a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift @@ -7,8 +7,14 @@ import Foundation -struct AroundMeResponse { - let profileImage: String - let myName: String - let cardName: String +struct AroundMeResponse: Codable { + let name, cardName: String + let imageURL: String + let cardUUID: String + + enum CodingKeys: String, CodingKey { + case name, cardName + case imageURL = "imageUrl" + case cardUUID = "cardUuid" + } } diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift new file mode 100644 index 00000000..cd5843ae --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift @@ -0,0 +1,20 @@ +// +// NearByRequest.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/05/02. +// + +import Foundation + +// MARK: - NearByRequest +struct NearByRequest: Codable { + let cardUUID: String + let isActive: Bool + let latitude, longitude: Double + + enum CodingKeys: String, CodingKey { + case cardUUID = "cardUuid" + case isActive, latitude, longitude + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift new file mode 100644 index 00000000..2244c5a9 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift @@ -0,0 +1,14 @@ +// +// NearByUUIDResponse.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/05/02. +// + +import Foundation + +// MARK: - NearByUUIDResponse +struct NearByUUIDResponse: Codable { + let activeTime, inactiveTime: String + let isActive: Bool +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift index 052f8040..9b9f8688 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Group/GroupService.swift @@ -15,7 +15,7 @@ enum GroupService { case groupEdit(groupRequest: GroupEditRequest) case cardAddInGroup(cardRequest: CardAddInGroupRequest) case cardListFetchInGroup(cardListInGroupRequest: CardListInGroupRequest) - case cardDeleteInGroup(cardUuid: String, cardGroupName: String) + case cardDeleteInGroup(cardUUID: String, cardGroupName: String) case groupReset } diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift new file mode 100644 index 00000000..2a553b29 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift @@ -0,0 +1,80 @@ +// +// NearbyAPI.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/04/24. +// + +import Foundation +import Moya + +public final class NearbyAPI { + static let shared = NearbyAPI() + private var nearbyProvider = MoyaProvider(plugins: [MoyaLoggerPlugin()]) + + private init() { } + + func cardNearByFetch(longitde: Double, latitude: Double, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.cardNearByFetch(longitude: longitde, latitude: latitude)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data: data, type: [AroundMeResponse].self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + + func postNearByCard(nearByRequest: NearByRequest, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.postNearByCard(nearByRequest: nearByRequest)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + + func nearByUUIDFetch(cardUUID: String, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.nearByUUIDFetch(cardUUID: cardUUID)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data: data, type: NearByUUIDResponse.self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + + // MARK: - judgeStatus methods + + private func judgeStatus(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult { + let decoder = JSONDecoder() + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) + else { return .pathErr } + + switch statusCode { + case 200: + return .success(decodedData.data ?? "None-Data") + case 400..<500: + return .requestErr(decodedData.message ?? "error message") + case 500: + return .serverErr + default: + return .networkFail + } + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift new file mode 100644 index 00000000..106973ec --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift @@ -0,0 +1,65 @@ +// +// NearbyService.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/04/24. +// + +import Foundation +import Moya + +enum NearbyService { + case cardNearByFetch(longitude: Double, latitude: Double) + case postNearByCard(nearByRequest: NearByRequest) + case nearByUUIDFetch(cardUUID: String) +} + +extension NearbyService: TargetType { + var baseURL: URL { + return URL(string: Const.URL.baseURL)! + } + + var authorizationType: AuthorizationType? { + return .bearer + } + + var path: String { + switch self { + case .cardNearByFetch(let longitude, let latitude): + return "/card/nearby/point/longitude/\(longitude)/latitude/\(latitude)" + case .postNearByCard: + return "/card/nearby" + case .nearByUUIDFetch(let cardUUID): + return "/card/nearby/\(cardUUID)" + } + } + + var method: Moya.Method { + switch self { + case .cardNearByFetch, .nearByUUIDFetch: + return .get + case .postNearByCard: + return .post + } + } + + var task: Moya.Task { + switch self { + case .cardNearByFetch, .nearByUUIDFetch: + return .requestPlain + case .postNearByCard(let nearByRequest): + return .requestParameters(parameters: ["cardUuid": nearByRequest.cardUUID, + "isActive": nearByRequest.isActive, + "latitude": nearByRequest.latitude, + "longitude": nearByRequest.longitude], + encoding: JSONEncoding.default) + } + } + + var headers: [String: String]? { + switch self { + case .cardNearByFetch, .postNearByCard, .nearByUUIDFetch: + return Const.Header.bearerHeader() + } + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 8649ec37..8cdcf6b9 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -4,6 +4,8 @@ // // Created by Yi Joon Choi on 2023/02/28. // +import UIKit +import CoreLocation import UIKit @@ -15,11 +17,16 @@ import SnapKit import Then final class AroundMeViewController: UIViewController { - + // MARK: - Properties var viewModel: AroundMeViewModel! private let disposeBag = DisposeBag() + var cardsNearBy: [AroundMeResponse] = [] + var locationManager = CLLocationManager() + + private var latitude: CLLocationDegrees = 0 + private var longitude: CLLocationDegrees = 0 // MARK: - UI Components @@ -40,7 +47,7 @@ final class AroundMeViewController: UIViewController { $0.textAlignment = .center } private let emptyStackView = UIStackView().then { - $0.spacing = 9 + $0.spacing = 10 $0.axis = .vertical $0.alignment = .center } @@ -57,13 +64,15 @@ final class AroundMeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + setLocationManager() setUI() setLayout() setDelegate() setRegister() + bindActions() bindViewModels() } - + } extension AroundMeViewController { @@ -75,10 +84,10 @@ extension AroundMeViewController { self.navigationController?.navigationBar.isHidden = true navigationBar.setUI("내 근처의 명함", leftImage: UIImage(named: "iconClear"), rightImage: UIImage(named: "iconRefreshLocation")) navigationBar.leftButtonAction = { - self.dismiss(animated: true) + self.dismiss(animated: true) } navigationBar.rightButtonAction = { - print("리프레시") + print("리프레시") } } @@ -103,25 +112,52 @@ extension AroundMeViewController { // MARK: - Methods + private func setLocationManager() { + locationManager.delegate = self + locationManager.desiredAccuracy = kCLLocationAccuracyBest + locationManager.requestWhenInUseAuthorization() + + DispatchQueue.global().async { + if CLLocationManager.locationServicesEnabled() { + print("location on") + self.locationManager.startUpdatingLocation() + print(self.locationManager.location?.coordinate) + } else { + print("location off") + } + } + } + private func setDelegate() { aroundMeCollectionView.dataSource = self -// aroundMeCollectionView.delegate = self + aroundMeCollectionView.delegate = self } private func setRegister() { aroundMeCollectionView.register(AroundMeCollectionViewCell.self, forCellWithReuseIdentifier: AroundMeCollectionViewCell.className) } + func setData(cardList: [AroundMeResponse]) { + self.cardsNearBy = cardList + self.aroundMeCollectionView.reloadData() + } + + private func bindActions() { + navigationBar.rightButton.rx.tap + .withUnretained(self) + .subscribe { owner, _ in + owner.makeVibrate(degree: .medium) + owner.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) + }.disposed(by: self.disposeBag) + } + private func bindViewModels() { let input = AroundMeViewModel.Input( - viewDidLoadEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, - refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }) - // let output = self.viewModel.transform(from: input, disposeBag: self.disposeBag) - - //TODO: 서버 연결 뒤 rx binding - - aroundMeCollectionView.rx.setDelegate(self) - .disposed(by: disposeBag) + viewWillAppearEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in + self.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) + }, + refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in}) + let output = self.viewModel.transform(input: input) } } @@ -149,13 +185,103 @@ extension AroundMeViewController: UICollectionViewDelegateFlowLayout { extension AroundMeViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 6 + return cardsNearBy.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let model = viewModel.dummyList - guard let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: AroundMeCollectionViewCell.className, for: indexPath) as? AroundMeCollectionViewCell else { return UICollectionViewCell()} - cardCell.setData(model[indexPath.row]) + guard let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: AroundMeCollectionViewCell.className, for: indexPath) as? AroundMeCollectionViewCell else { + return UICollectionViewCell() + } + cardCell.setData(cardsNearBy[indexPath.row]) + cardCell.addCardMethod = { [weak self] in + let index = indexPath.row + print("\(index) Call Back Method") + // 여기서 카드 추가 API + self?.cardDetailFetchWithAPI(cardUUID: self?.cardsNearBy[indexPath.row].cardUUID ?? "") + } return cardCell } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + print("selected") + } +} + +// MARK: - CLLocationManagerDelegate + +extension AroundMeViewController: CLLocationManagerDelegate { + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + if let location = locations.first { + print("✅ 위도: ", location.coordinate.latitude) + print("✅ 경도: ", location.coordinate.longitude) + + latitude = location.coordinate.latitude + longitude = location.coordinate.longitude + + cardNearByFetchWithAPI(longitude: longitude, latitude: latitude) + } + } + + func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + print(error) + } +} + +// MARK: - Network + +extension AroundMeViewController { + func cardNearByFetchWithAPI(longitude: Double, latitude: Double) { + NearbyAPI.shared.cardNearByFetch(longitde: longitude, latitude: latitude) { response in + switch response { + case .success(let data): + if let cards = data as? [AroundMeResponse] { + self.cardsNearBy = cards + print(cards) + if cards.isEmpty { + self.aroundMeCollectionView.isHidden = true + } + self.aroundMeCollectionView.reloadData() + } + print("cardNearByFetchWithAPI - success") + case .requestErr(let message): + print("cardNearByFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("cardNearByFetchWithAPI - pathErr") + case .serverErr: + print("cardNearByFetchWithAPI - serverErr") + case .networkFail: + print("cardNearByFetchWithAPI - networkFail") + } + } + } + + func cardDetailFetchWithAPI(cardUUID: String) { + CardAPI.shared.cardDetailFetch(cardUUID: cardUUID) { response in + switch response { + case .success(let data): + if let card = data as? Card { + // TODO: - 자신의 명함 추가하는 경우 예외처리. + // if UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) == card.author { + // self.errorImageView.isHidden = false + // self.explainLabel.isHidden = false + // self.explainLabel.text = "자신의 명함은 추가할 수 없습니다." + // } else { + let nextVC = CardResultBottomSheetViewController() + .setTitle(card.userName) + .setHeight(574) + nextVC.cardDataModel = card + nextVC.modalPresentationStyle = .overFullScreen + self.present(nextVC, animated: false, completion: nil) + } + case .requestErr(let message): + print("cardDetailFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("cardDetailFetchWithAPI - pathErr") + case .serverErr: + print("cardDetailFetchWithAPI - serverErr") + case .networkFail: + print("cardDetailFetchWithAPI - networkFail") + } + } + } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index 150b2bd3..373a7362 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -13,14 +13,20 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Properties + var cardUUID: String = "" + var addCardMethod: (() -> Void)? + // MARK: - UI Components private let plusButton = UIButton().then { $0.setImage(UIImage(named: "icnPlusCircle"), for: .normal) + $0.addTarget(self, action: #selector(touchPlusButton), for: .touchUpInside) } private var profileImageView = UIImageView().then { $0.image = UIImage(named: "imgProfileSmall") + $0.layer.cornerRadius = 33 + $0.clipsToBounds = true } private var myNameLabel = UILabel().then { @@ -32,6 +38,7 @@ class AroundMeCollectionViewCell: UICollectionViewCell { } private var cardNameLabel = UILabel().then { + $0.textColor = .tertiary $0.font = .textBold02 } @@ -53,12 +60,11 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Methods - //TODO: 나중에 model 나오면 재정의 public func setData(_ model: AroundMeResponse) { -// profileImageView.updateServerImage(model.profileImage) - profileImageView.image = UIImage(named: model.profileImage) - myNameLabel.text = model.myName + profileImageView.updateServerImage(model.imageURL) + myNameLabel.text = model.name cardNameLabel.text = model.cardName + cardUUID = model.cardUUID } // MARK: - UI & Layout @@ -78,6 +84,7 @@ class AroundMeCollectionViewCell: UICollectionViewCell { profileImageView.snp.makeConstraints { make in make.top.equalToSuperview().inset(20) make.leading.equalToSuperview().inset(12) + make.width.height.equalTo(66) } myNameLabel.snp.makeConstraints { make in make.centerY.equalTo(profileImageView.snp.centerY) @@ -88,8 +95,18 @@ class AroundMeCollectionViewCell: UICollectionViewCell { make.leading.equalToSuperview().inset(20) } dividerLine.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.leading.equalToSuperview() make.bottom.equalTo(cardNameLabel.snp.top).offset(-11) - make.height.equalTo(0.5) + make.height.equalTo(1) } } + + // MARK: - @objc + + @objc + private func touchPlusButton() { + addCardMethod?() + } + } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift index 4222f067..651935bc 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift @@ -12,32 +12,13 @@ final class AroundMeViewModel: ViewModelType { // MARK: - Properties -// private let useCase: StadiumUseCase - let dummyList = [AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름")] - + private var cardList: [AroundMeResponse] = [] private let disposeBag = DisposeBag() // MARK: - Inputs struct Input { - let viewDidLoadEvent: Observable + let viewWillAppearEvent: Observable let refreshButtonTapEvent: Observable } @@ -58,33 +39,24 @@ final class AroundMeViewModel: ViewModelType { extension AroundMeViewModel { func transform(input: Input) -> Output { let output = Output() - self.bindOutput(output: output, disposeBag: disposeBag) - input.viewDidLoadEvent + input.viewWillAppearEvent .withUnretained(self) .subscribe { owner, _ in // self.useCase.getStadiumList() + // get 서버통신 + output.cardList.accept(owner.cardList) }.disposed(by: self.disposeBag) input.refreshButtonTapEvent .withUnretained(self) .subscribe { owner, _ in // self.useCase.getStadiumList() + // get 서버통신 + + output.cardList.accept(owner.cardList) }.disposed(by: self.disposeBag) return output } - - private func bindOutput(output: Output, disposeBag: DisposeBag) { -// let stadiumListRelay = useCase.stadiumList -// let ingStadiumRelay = useCase.ingStadium -// -// stadiumListRelay.subscribe { model in -// output.stadiumLists.accept(model) -// }.disposed(by: self.disposeBag) -// -// ingStadiumRelay.subscribe { model in -// output.ingStadium.accept(model) -// }.disposed(by: self.disposeBag) - } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index e9367b82..dc461672 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -19,6 +19,11 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { public var isShareable = false public var cardDataModel: Card? public var isActivate: Bool? + private weak var timer: Timer? + private var seconds = 0 + private var savedTime = "10:00" + private var timesLeft = 600 + private var appDidEnterBackgroundDate: Date? var locationManager = CLLocationManager() private var latitude: CLLocationDegrees = 0 @@ -60,6 +65,16 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { return label }() + private let nearByTimeLabel: UILabel = { + let label = UILabel() + label.font = .button02 + label.textColor = .mainColorNadaMain + label.text = "10:00" + label.sizeToFit() + + return label + }() + lazy private var nearBySwitch: UISwitch = { let nearBySwitch = UISwitch() @@ -134,6 +149,11 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { setLocationManager() } + override func viewWillAppear(_ animated: Bool) { + setNotification() + nearByUUIDFetchWithAPI(cardUUID: cardDataModel?.cardUUID ?? "") + } + // MARK: - @Functions private func setupUI() { @@ -145,23 +165,24 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { cardBackgroundView.addSubviews([nadaLogoImage, qrImage, idStackView, saveAsImageButton]) - nearByBackgroundView.addSubviews([nearByImage, nearByLabel, nearBySwitch, lottieImage]) + nearByBackgroundView.addSubviews([nearByImage, nearByLabel, nearByTimeLabel, nearBySwitch, lottieImage]) idLabel.text = cardDataModel?.cardUUID ?? "" - setCardActivationUI(with: isActivate ?? false) + setCardActivationUI(with: isActivate ?? false, secondsLeft: 0) setupLayout() setQRImage() } - private func setCardActivationUI(with isActivate: Bool) { + private func setCardActivationUIWithAPI(with isActivate: Bool) { nearByBackgroundView.backgroundColor = isActivate ? .mainColorNadaMain.withAlphaComponent(0.15) : .card nearByImage.image = isActivate ? UIImage(named: "icnNearbyOn") : UIImage(named: "icnNearbyOff") nearByLabel.text = isActivate ? "내 근처의 명함 ON" : "내 근처의 명함 OFF" nearByLabel.textColor = isActivate ? .mainColorNadaMain : .tertiary + nearByTimeLabel.isHidden = !isActivate nearBySwitch.setOn(isActivate, animated: false) @@ -169,19 +190,93 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { _ = isActivate ? lottieImage.play() : lottieImage.stop() // TODO: 여기서 스위치 키면 위치정보 받아오기, 끄면 위치 정보 노출하지 않기 + locationManager.startUpdatingLocation() + latitude = locationManager.location?.coordinate.latitude ?? 0 + longitude = locationManager.location?.coordinate.longitude ?? 0 + if isActivate { //TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기 - locationManager.startUpdatingLocation() - latitude = locationManager.location?.coordinate.latitude ?? 0 - longitude = locationManager.location?.coordinate.longitude ?? 0 + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) print("✅ activated") print("✅ latitude: ", latitude) print("✅ longitude: ", longitude) + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: true, latitude: latitude, longitude: longitude)) } else { // TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기 + timer?.invalidate() + seconds = 0 + nearByTimeLabel.text = "10:00" + print("✅✅ deactivated") + print("✅ latitude: ", latitude) + print("✅ longitude: ", longitude) + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + } + } + + private func setCardActivationUI(with isActivate: Bool, secondsLeft: Int) { + nearByBackgroundView.backgroundColor = isActivate ? .mainColorNadaMain.withAlphaComponent(0.15) : .card + + nearByImage.image = isActivate ? UIImage(named: "icnNearbyOn") : UIImage(named: "icnNearbyOff") + + nearByLabel.text = isActivate ? "내 근처의 명함 ON" : "내 근처의 명함 OFF" + nearByLabel.textColor = isActivate ? .mainColorNadaMain : .tertiary + nearByTimeLabel.isHidden = !isActivate + + nearBySwitch.setOn(isActivate, animated: false) + + lottieImage.isHidden = isActivate ? false : true + _ = isActivate ? lottieImage.play() : lottieImage.stop() + + if isActivate { + //TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기 + print(calculateMinuteTime(sec: calculateMinuteTimeToInt(time: savedTime) - secondsLeft)) + print(secondsLeft) + + if secondsLeft >= 600 { + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + } + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) + print("✅ activated") + print("✅ latitude: ", latitude) + print("✅ longitude: ", longitude) + } else { + // TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기 + timer?.invalidate() + seconds = 0 + nearByTimeLabel.text = "10:00" + print("✅✅ deactivated") + } + } + + func setNotification() { + NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) + } + + @objc func applicationDidEnterBackground(_ notification: NotificationCenter) { + appDidEnterBackgroundDate = Date() + savedTime = nearByTimeLabel.text ?? "00:00" + print(savedTime) + } + + @objc func applicationWillEnterForeground(_ notification: NotificationCenter) { + guard let previousDate = appDidEnterBackgroundDate else { return } + let calendar = Calendar.current + let difference = calendar.dateComponents([.second], from: previousDate, to: Date()) + let seconds = difference.second! + print(savedTime) + print(calculateMinuteTime(sec: calculateMinuteTimeToInt(time: savedTime) - seconds)) + print(seconds) + + if seconds >= 600 { + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + } else { + DispatchQueue.main.async { + self.nearByTimeLabel.text = calculateMinuteTime(sec: calculateMinuteTimeToInt(time: self.savedTime) - seconds) + } } } @@ -242,7 +337,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { nearByLabel.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), nearByLabel.leadingAnchor.constraint(equalTo: nearByImage.trailingAnchor) ]) - + nearBySwitch.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ nearBySwitch.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), @@ -251,6 +346,12 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { nearBySwitch.widthAnchor.constraint(equalToConstant: 51.0) ]) + nearByTimeLabel.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + nearByTimeLabel.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), + nearByTimeLabel.trailingAnchor.constraint(equalTo: nearBySwitch.leadingAnchor, constant: -5.0) + ]) + lottieImage.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ lottieImage.centerXAnchor.constraint(equalTo: nearByImage.centerXAnchor), @@ -399,13 +500,18 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } @objc func touchSwitch(_ sender: UISwitch) { - setCardActivationUI(with: sender.isOn) + setCardActivationUIWithAPI(with: sender.isOn) + } + + @objc + func processTimer() { + seconds += 1 + nearByTimeLabel.text = calculateMinuteTime(sec: timesLeft - seconds) } } extension CardShareBottomSheetViewController: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { - print("Location Here") if let location = locations.first { print("✅ 위도: ", location.coordinate.latitude) print("✅ 경도: ", location.coordinate.longitude) @@ -419,3 +525,47 @@ extension CardShareBottomSheetViewController: CLLocationManagerDelegate { print(error) } } + +// MARK: - Network + +extension CardShareBottomSheetViewController { + func postNearByCardWithAPI(nearByRequest: NearByRequest) { + NearbyAPI.shared.postNearByCard(nearByRequest: nearByRequest) { response in + switch response { + case .success: + print("postNearByCardWithAPI - success") + case .requestErr(let message): + print("postNearByCardWithAPI - requestErr: \(message)") + case .pathErr: + print("postNearByCardWithAPI - pathErr") + case .serverErr: + print("postNearByCardWithAPI - serverErr") + case .networkFail: + print("postNearByCardWithAPI - networkFail") + } + } + } + + func nearByUUIDFetchWithAPI(cardUUID: String) { + NearbyAPI.shared.nearByUUIDFetch(cardUUID: cardUUID) { response in + switch response { + case .success(let data): + if let nearByUUIDResponse = data as? NearByUUIDResponse { + print("✅✅✅") + let interval = Date() - (nearByUUIDResponse.activeTime.toDate() ?? Date()) + self.setCardActivationUI(with: nearByUUIDResponse.isActive, secondsLeft: interval.second ?? 0) + self.timesLeft = interval.second ?? 600 + } + print("nearByUUIDFetchWithAPI - success") + case .requestErr(let message): + print("nearByUUIDFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("nearByUUIDFetchWithAPI - pathErr") + case .serverErr: + print("nearByUUIDFetchWithAPI - serverErr") + case .networkFail: + print("nearByUUIDFetchWithAPI - networkFail") + } + } + } +} diff --git a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift index 0f248605..0e0bcee5 100644 --- a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift +++ b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift @@ -38,7 +38,7 @@ class CustomNavigationBar: UIView { private lazy var leftButton = UIButton().then { $0.addTarget(self, action: #selector(touchLeftButton(_:)), for: .touchUpInside) } - private lazy var rightButton = UIButton().then { + lazy var rightButton = UIButton().then { $0.addTarget(self, action: #selector(touchRightButton(_:)), for: .touchUpInside) }