Skip to content

Commit

Permalink
[2.0.0] 회원 등록 api 추가 요청 대응 (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgvv authored Apr 30, 2024
1 parent a07e026 commit dc4e4e9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "7f5095b25e2d0a629176f0ebc41ee16d8e7d8c6c0e326ede18f4df4abbe75d63",
"originHash" : "a70bf5bcda18b73a91398005590ea6f3e124d517cc68deffb3c56506da7c3f07",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down
15 changes: 15 additions & 0 deletions package-kuring/Sources/Models/AuthRequest.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
}
Expand Down Expand Up @@ -289,6 +301,8 @@ extension KuringLink {
category: .학과
)
]
}, registerAuthorization: {
return true
}
)
}
3 changes: 3 additions & 0 deletions package-kuring/Sources/Networks/KuringLink/API.Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum Path {
case searchNotices
case searchStaffs
case sendFeedback
case registerAuthorization

var path: String {
switch self {
Expand All @@ -39,6 +40,8 @@ enum Path {
return "api/v2/staffs/search"
case .sendFeedback:
return "api/v2/users/feedbacks"
case .registerAuthorization:
return "api/v2/users"
}
}
}
2 changes: 2 additions & 0 deletions package-kuring/Sources/Networks/KuringLink/KuringLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//

import Firebase
import Networks
import Dependencies

extension Notifications: MessagingDelegate {
func configureFirebase() {
Expand All @@ -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()
}
}
}
}

0 comments on commit dc4e4e9

Please sign in to comment.