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() + } + } } }