-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 프로젝트내 사용할 Endpoint 정의 및 네트워크 구조 수정 #14
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
12 commits
Select commit
Hold shift + click to select a range
84fecef
[FEAT] 네트워킹을 위한 기반 구조 개선 및 폴더링 변경
dlrjswns 273ca2a
[FEAT] Auth관련 데이터 모델 추가
dlrjswns 873755d
[FEAT] Card관련 모델 추가
dlrjswns 56b96a9
[FEAT] Chat관련 데이터 모델 추가
dlrjswns b269fdb
[MOVE] 공용모델 폴더 위치 변경
dlrjswns 16ff55b
[FEAT] Member관련 데이터 모델 추가
dlrjswns 37978cb
[FEAT] Endpoint변경에 따른 코드 수정 및 API 추가
dlrjswns fd17574
[RENAME] CreateCardsRequestDTO -> CreateCardRequestDTO 네이밍 수정
dlrjswns 420581c
[FEAT] Auth관련 헤더값 적용
dlrjswns 50ee303
[CHORE] case let문으로 코드 통일
dlrjswns e3a698a
[CHORE] 파라미터관련 여러 케이스 query추가 시 생략 문제 해결
dlrjswns a4ac425
[CHORE] HTTPHeader 공용 필드 개선 및 적용
dlrjswns 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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
| // | ||
| // Endpoint.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 7/19/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| protocol Endpoint { | ||
| var baseURLString: String { get } | ||
| var path: String { get } | ||
| var method: HTTPMethod { get } | ||
| var parameters: [RequestParameter] { get } | ||
| var header: HTTPHeader { get } | ||
| } | ||
|
|
||
| extension Endpoint { | ||
| var baseURLString: String { | ||
| return Environment.baseURL | ||
| } | ||
|
|
||
| func asURLRequest() throws -> URLRequest { | ||
| guard var components = URLComponents( | ||
| string: "\(baseURLString)\(path)" | ||
| ) else { | ||
| throw NetworkError.invalidURL | ||
| } | ||
|
|
||
| var httpBody: Data? | ||
|
|
||
| for parameter in parameters { | ||
| switch parameter { | ||
| case let .query(query): | ||
| components.queryItems = (components.queryItems ?? []) + query.map { | ||
| URLQueryItem( | ||
| name: $0.key, | ||
| value: $0.value | ||
| ) | ||
| } | ||
|
|
||
| case let .body(body): | ||
| httpBody = try JSONEncoder().encode(body) | ||
| } | ||
| } | ||
|
|
||
| guard let url = components.url else { | ||
| throw NetworkError.invalidURL | ||
| } | ||
|
|
||
| var request = URLRequest(url: url) | ||
| request.httpMethod = method.rawValue | ||
| request.httpBody = httpBody | ||
|
|
||
| header.fields.forEach { | ||
| request.setValue( | ||
| $1, | ||
| forHTTPHeaderField: $0 | ||
| ) | ||
| } | ||
|
|
||
| return request | ||
| } | ||
| } | ||
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,40 @@ | ||
| // | ||
| // HttpHeader.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum HTTPHeader { | ||
| case `default` | ||
| case authorization | ||
| case custom([String: String]) | ||
|
|
||
| private var commonFields: [String: String] { | ||
| [ | ||
| "Content-Type": "application/json", | ||
| "Accept": "application/json" | ||
| ] | ||
| } | ||
|
|
||
| var fields: [String: String] { | ||
| switch self { | ||
| case .default: | ||
| return commonFields | ||
|
|
||
| case .authorization: | ||
| var fields = commonFields | ||
|
|
||
| if let accessToken = TokenStorage.shared.readToken(.accessToken) { | ||
| fields["Authorization"] = "Bearer \(accessToken)" | ||
| } | ||
|
dlrjswns marked this conversation as resolved.
|
||
|
|
||
| return fields | ||
|
|
||
| case let .custom(headers): | ||
| return headers | ||
| } | ||
| } | ||
| } | ||
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,16 @@ | ||
| // | ||
| // HttpMethod.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum HTTPMethod: String { | ||
| case get = "GET" | ||
| case post = "POST" | ||
| case put = "PUT" | ||
| case patch = "PATCH" | ||
| case delete = "DELETE" | ||
| } |
13 changes: 13 additions & 0 deletions
13
GAMSS/Sources/Core/Network/Foundation/RequestParameter.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,13 @@ | ||
| // | ||
| // RequestParameter.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum RequestParameter { | ||
| case query([String: String]) | ||
| case body(Encodable) | ||
| } |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
GAMSS/Sources/Data/DTO/Auth/Request/ReissueTokenRequestDTO.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,12 @@ | ||
| // | ||
| // ReissueTokenRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct ReissueTokenRequestDTO: Encodable { | ||
| let refreshToken: String | ||
| } |
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
GAMSS/Sources/Data/DTO/Card/Request/CreateCardRequestDTO.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,14 @@ | ||
| // | ||
| // CreateCardsRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct CreateCardRequestDTO: Encodable { | ||
| let conversationId: Int | ||
| let emotion: String | ||
| let summary: String | ||
| } | ||
|
dlrjswns marked this conversation as resolved.
|
||
13 changes: 13 additions & 0 deletions
13
GAMSS/Sources/Data/DTO/Chat/Request/CreateCommentRequestDTO.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,13 @@ | ||
| // | ||
| // CreateCommentRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct CreateCommentRequestDTO: Encodable { | ||
| let messageId: Int | ||
| let currentConversationSummary: String | ||
| } |
16 changes: 16 additions & 0 deletions
16
GAMSS/Sources/Data/DTO/Chat/Request/CreateMessageRequestDTO.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,16 @@ | ||
| // | ||
| // CreateMessageRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct CreateMessageRequestDTO: Encodable { | ||
| let conversationId: Int | ||
| let content: String | ||
| let repliesMessageId: Int | ||
| let currentConversationSummary: String | ||
| let excludeCharacters: [String] | ||
| } |
12 changes: 12 additions & 0 deletions
12
GAMSS/Sources/Data/DTO/Chat/Request/UpdateChatTitleRequestDTO.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,12 @@ | ||
| // | ||
| // UpdateChatTitleRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct UpdateChatTitleRequestDTO: Encodable { | ||
| let title: String | ||
| } |
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
GAMSS/Sources/Data/DTO/Member/Request/UpdateNicknameRequestDTO.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,12 @@ | ||
| // | ||
| // UpdateNicknameRequestDTO.swift | ||
| // GAMSS | ||
| // | ||
| // Created by 이건준 on 8/8/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct UpdateNicknameRequestDTO: Encodable { | ||
| let nickname: String | ||
| } |
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
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.