-
Notifications
You must be signed in to change notification settings - Fork 0
[#648] HTTPCallable 메서드들을 RESTful API화한다 #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dffe9ba
refactor: Firebase Functions REST API 호출 구조 준비
opficdev 7cca6c2
refactor: REST API 에러 응답 매핑 정리
opficdev 6d5f9e5
fix: WebPage 삭제 요청에 실제 문서 ID 전달
opficdev dc50a8e
fix: Apple refresh token 요청 uid 제거
opficdev 8e5ae28
refactor: Function API 클라이언트 공유 인스턴스 적용
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
Application/DevLogInfra/Sources/Extension/FirebaseFunctions+.swift
This file was deleted.
Oops, something went wrong.
158 changes: 158 additions & 0 deletions
158
Application/DevLogInfra/Sources/Service/FunctionAPIClient.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // | ||
| // FunctionAPIClient.swift | ||
| // DevLogInfra | ||
| // | ||
| // Created by opfic on 6/26/26. | ||
| // | ||
|
|
||
| import FirebaseAuth | ||
| import Foundation | ||
| import DevLogData | ||
| import Nexa | ||
|
|
||
| final class FunctionAPIClient { | ||
| static let shared = FunctionAPIClient() | ||
|
|
||
| private let apiClient: Result<NXAPIClient, Error> | ||
|
|
||
| private init() { | ||
| let authTokenProvider = FirebaseAuthTokenProvider() | ||
| apiClient = Result { | ||
| try NXAPIClient( | ||
| configuration: NXClientConfiguration( | ||
| baseURL: FirebaseConfiguration.functionAPIBaseURL(), | ||
| headers: ["Accept": "application/json"], | ||
| serverErrorDecoder: FunctionAPIServerErrorDecoder(), | ||
| authTokenProvider: authTokenProvider | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| func send( | ||
| _ endpoint: FunctionAPIEndpoint<EmptyAPIResponse>, | ||
| payload: some Encodable, | ||
| requiresAuthentication: Bool = true | ||
| ) async throws { | ||
| var request = try client() | ||
| .request(endpoint) | ||
| .json(payload) | ||
|
|
||
| if requiresAuthentication { | ||
| request = request.authorized() | ||
| } | ||
|
|
||
| _ = try await request.raw() | ||
| } | ||
|
|
||
| func send( | ||
| _ endpoint: FunctionAPIEndpoint<EmptyAPIResponse>, | ||
| requiresAuthentication: Bool = true | ||
| ) async throws { | ||
| var request = try client() | ||
| .request(endpoint) | ||
|
|
||
| if requiresAuthentication { | ||
| request = request.authorized() | ||
| } | ||
|
|
||
| _ = try await request.raw() | ||
| } | ||
|
|
||
| func send<Response: Decodable>( | ||
| _ endpoint: FunctionAPIEndpoint<Response>, | ||
| payload: some Encodable, | ||
| requiresAuthentication: Bool = true | ||
| ) async throws -> Response { | ||
| var request = try client() | ||
| .request(endpoint) | ||
| .json(payload) | ||
|
|
||
| if requiresAuthentication { | ||
| request = request.authorized() | ||
| } | ||
|
|
||
| return try await request.send() | ||
| } | ||
|
|
||
| func send<Response: Decodable>( | ||
| _ endpoint: FunctionAPIEndpoint<Response>, | ||
| requiresAuthentication: Bool = true | ||
| ) async throws -> Response { | ||
| try await send( | ||
| endpoint, | ||
| payload: EmptyPayload(), | ||
| requiresAuthentication: requiresAuthentication | ||
| ) | ||
| } | ||
|
|
||
| private func client() throws -> NXAPIClient { | ||
| try apiClient.get() | ||
| } | ||
| } | ||
|
|
||
| struct FunctionAPIEndpoint<Response: Decodable>: NXEndpoint { | ||
| let method: NXHTTPMethod | ||
| let path: String | ||
| } | ||
|
|
||
| struct FunctionAPIResponse: Decodable { | ||
| let accessToken: String? | ||
| let customToken: String? | ||
| let refreshToken: String? | ||
| let token: String? | ||
| } | ||
|
|
||
| struct EmptyAPIResponse: Decodable {} | ||
|
|
||
| private struct EmptyPayload: Encodable {} | ||
|
|
||
| private struct FunctionAPIErrorBody: Decodable { | ||
| let code: String | ||
| let message: String? | ||
| } | ||
|
|
||
| private struct FunctionAPIServerErrorDecoder: NXServerErrorDecoder { | ||
| func decodeServerError( | ||
| data: Data, | ||
| response: HTTPURLResponse, | ||
| decoder: JSONDecoder | ||
| ) -> (any Error)? { | ||
| guard let body = try? decoder.decode( | ||
| FunctionAPIErrorBody.self, | ||
| from: data | ||
| ) else { return nil } | ||
|
|
||
| switch body.code { | ||
| case EmailFetchError.emailNotFound.code: | ||
| return EmailFetchError.emailNotFound | ||
| case EmailFetchError.emailMismatch.code: | ||
| return EmailFetchError.emailMismatch | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private actor FirebaseAuthTokenProvider: NXAuthTokenProvider { | ||
| func currentAccessToken() async throws -> String? { | ||
| try await Auth.auth().currentUser?.getIDToken() | ||
| } | ||
|
|
||
| func refreshAccessToken() async throws -> String? { | ||
| try await Auth.auth().currentUser?.getIDToken(forcingRefresh: true) | ||
| } | ||
| } | ||
|
|
||
| extension Error { | ||
| var apiEmailFetchError: EmailFetchError? { | ||
| guard let error = self as? NXError, | ||
| case let .server( | ||
| statusCode: _, | ||
| data: _, | ||
| underlying: underlying | ||
| ) = error else { return nil } | ||
|
|
||
| return underlying as? EmailFetchError | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
Application/DevLogInfra/Sources/Service/FunctionAPIEndpoint.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // FunctionAPIEndpoint.swift | ||
| // DevLogInfra | ||
| // | ||
| // Created by opfic on 6/26/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| extension FunctionAPIEndpoint where Response == EmptyAPIResponse { | ||
| static func requestTodoDeletion(_ id: String) -> Self { | ||
| Self(method: .post, path: "/todos/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static func undoTodoDeletion(_ id: String) -> Self { | ||
| Self(method: .delete, path: "/todos/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static func requestWebPageDeletion(_ id: String) -> Self { | ||
| Self(method: .post, path: "/web-pages/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static func undoWebPageDeletion(_ id: String) -> Self { | ||
| Self(method: .delete, path: "/web-pages/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static func requestPushNotificationDeletion(_ id: String) -> Self { | ||
| Self(method: .post, path: "/push-notifications/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static func undoPushNotificationDeletion(_ id: String) -> Self { | ||
| Self(method: .delete, path: "/push-notifications/\(functionAPIPathSegment(id))/deletion-request") | ||
| } | ||
|
|
||
| static let revokeAppleAccessToken = Self(method: .delete, path: "/auth/apple/access-token") | ||
| static let revokeGithubAccessToken = Self(method: .delete, path: "/auth/github/access-token") | ||
| } | ||
|
|
||
| extension FunctionAPIEndpoint where Response == FunctionAPIResponse { | ||
| static let requestAppleCustomToken = Self(method: .post, path: "/auth/apple/custom-token") | ||
| static let refreshAppleAccessToken = Self(method: .post, path: "/auth/apple/access-token") | ||
| static let requestAppleRefreshToken = Self(method: .post, path: "/auth/apple/refresh-token") | ||
| static let requestGithubTokens = Self(method: .post, path: "/auth/github/tokens") | ||
| } | ||
|
|
||
| private func functionAPIPathSegment(_ value: String) -> String { | ||
| var allowed = CharacterSet.alphanumerics | ||
| allowed.insert(charactersIn: "-._~") | ||
| return value.addingPercentEncoding(withAllowedCharacters: allowed) ?? value | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.