From dc4e4e996da425e06c9be7fab3f880dbd07107a8 Mon Sep 17 00:00:00 2001 From: GeonWoo <56182112+lgvv@users.noreply.github.com> Date: Tue, 30 Apr 2024 20:51:55 +0900 Subject: [PATCH] =?UTF-8?q?[2.0.0]=20=ED=9A=8C=EC=9B=90=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20api=20=EC=B6=94=EA=B0=80=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EB=8C=80=EC=9D=91=20(#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcshareddata/swiftpm/Package.resolved | 2 +- package-kuring/Sources/Models/AuthRequest.swift | 15 +++++++++++++++ .../Depdencies/KuringLink.Dependency.swift | 14 ++++++++++++++ .../Sources/Networks/KuringLink/API.Path.swift | 3 +++ .../Sources/Networks/KuringLink/KuringLink.swift | 2 ++ .../Notifications.MessagingDelegate.swift | 13 ++++++++++++- 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 package-kuring/Sources/Models/AuthRequest.swift diff --git a/KuringApp/KuringApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/KuringApp/KuringApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 77f7c9c7..bb07abe0 100644 --- a/KuringApp/KuringApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/KuringApp/KuringApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "7f5095b25e2d0a629176f0ebc41ee16d8e7d8c6c0e326ede18f4df4abbe75d63", + "originHash" : "a70bf5bcda18b73a91398005590ea6f3e124d517cc68deffb3c56506da7c3f07", "pins" : [ { "identity" : "abseil-cpp-binary", diff --git a/package-kuring/Sources/Models/AuthRequest.swift b/package-kuring/Sources/Models/AuthRequest.swift new file mode 100644 index 00000000..2b6d3871 --- /dev/null +++ b/package-kuring/Sources/Models/AuthRequest.swift @@ -0,0 +1,15 @@ +// +// Copyright (c) 2024 쿠링 +// See the 'License.txt' file for licensing information. +// + +import Foundation + +/// 계정 정보 요청 Request 모델 +public struct AuthRequest: Encodable { + public let token: String + + public init(token: String) { + self.token = token + } +} diff --git a/package-kuring/Sources/Networks/Depdencies/KuringLink.Dependency.swift b/package-kuring/Sources/Networks/Depdencies/KuringLink.Dependency.swift index 55eea933..0b7ef3c7 100644 --- a/package-kuring/Sources/Networks/Depdencies/KuringLink.Dependency.swift +++ b/package-kuring/Sources/Networks/Depdencies/KuringLink.Dependency.swift @@ -204,6 +204,18 @@ extension KuringLink: DependencyKey { ) } return NoticeProvider.departments + }, registerAuthorization: { + let response: EmptyResponse = try await satellite + .response( + for: Path.registerAuthorization.path, + httpMethod: .post, + httpHeaders: [ + "Content-Type": "application/json", + ], + httpBody: AuthRequest(token: fcmToken) + ) + let isSucceed = (200 ..< 300) ~= response.code + return isSucceed } ) } @@ -289,6 +301,8 @@ extension KuringLink { category: .학과 ) ] + }, registerAuthorization: { + return true } ) } diff --git a/package-kuring/Sources/Networks/KuringLink/API.Path.swift b/package-kuring/Sources/Networks/KuringLink/API.Path.swift index 47a05148..e75a43ff 100644 --- a/package-kuring/Sources/Networks/KuringLink/API.Path.swift +++ b/package-kuring/Sources/Networks/KuringLink/API.Path.swift @@ -16,6 +16,7 @@ enum Path { case searchNotices case searchStaffs case sendFeedback + case registerAuthorization var path: String { switch self { @@ -39,6 +40,8 @@ enum Path { return "api/v2/staffs/search" case .sendFeedback: return "api/v2/users/feedbacks" + case .registerAuthorization: + return "api/v2/users" } } } diff --git a/package-kuring/Sources/Networks/KuringLink/KuringLink.swift b/package-kuring/Sources/Networks/KuringLink/KuringLink.swift index 69c431d9..8be97a76 100644 --- a/package-kuring/Sources/Networks/KuringLink/KuringLink.swift +++ b/package-kuring/Sources/Networks/KuringLink/KuringLink.swift @@ -73,4 +73,6 @@ public struct KuringLink { public var getAllUnivNoticeType: () async throws -> [NoticeProvider] /// 모든 학과 공지 카테고리 가져오기 public var getAllDepartments: () async throws -> [NoticeProvider] + /// 계정 정보 등록 + public var registerAuthorization: () async throws -> Bool } diff --git a/package-kuring/Sources/PushNotifications/Notifications/Notifications.MessagingDelegate.swift b/package-kuring/Sources/PushNotifications/Notifications/Notifications.MessagingDelegate.swift index bb9112eb..8b6053f2 100644 --- a/package-kuring/Sources/PushNotifications/Notifications/Notifications.MessagingDelegate.swift +++ b/package-kuring/Sources/PushNotifications/Notifications/Notifications.MessagingDelegate.swift @@ -4,6 +4,8 @@ // import Firebase +import Networks +import Dependencies extension Notifications: MessagingDelegate { func configureFirebase() { @@ -14,6 +16,15 @@ extension Notifications: MessagingDelegate { /// FCM 등록 토큰을 받았을 때 호출되는 이벤트 public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { guard let fcmToken else { return } - self.fcmToken = fcmToken + + if self.fcmToken != fcmToken { + self.fcmToken = fcmToken + + // 토큰 값이 다른 경우에만 해당 API 호출 + @Dependency(\.kuringLink) var kuringLink + Task(priority: .background) { + try? await kuringLink.registerAuthorization() + } + } } }