-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feat/#25-MainApp
- Loading branch information
Showing
32 changed files
with
1,122 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
HMH_iOS/HMH_iOS.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains 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 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,65 @@ | ||
// | ||
// AuthInterceptor.swift | ||
// HMH_iOS | ||
// | ||
// Created by 이지희 on 5/12/24. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
import Alamofire | ||
import Moya | ||
|
||
///// 토큰 만료 시 자동으로 refresh를 위한 서버 통신 | ||
final class AuthInterceptor: RequestInterceptor { | ||
|
||
private var retryLimit = 2 | ||
static let shared = AuthInterceptor() | ||
|
||
private init() {} | ||
|
||
func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) { | ||
print("---adater 진입----") | ||
completion(.success(urlRequest)) | ||
} | ||
|
||
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { | ||
print("-------🔧retry 시작🔧-------") | ||
guard | ||
let statusCode = request.response?.statusCode, | ||
request.retryCount < retryLimit | ||
else { | ||
print("🚨재시도 횟수가 너무 많습니다🚨") | ||
return completion(.doNotRetry) | ||
} | ||
|
||
if let statusCode = request.response?.statusCode, | ||
request.retryCount < retryLimit { | ||
if statusCode == 401 { | ||
let provider = Providers.AuthProvider | ||
provider.request(target: .tokenRefresh, instance: BaseResponse<RefreshTokebResponseDTO>.self) { result in | ||
if result.status == 200 { | ||
if let data = result.data { | ||
// UserManager.shared.updateToken(data.token.accessToken, data.token.refreshToken) | ||
} | ||
print("🪄토큰 재발급에 성공했습니다🪄") | ||
completion(.retry) | ||
} else if statusCode == 401 { | ||
/// 리프레쉬 토큰도 만료된 상황 | ||
} | ||
} | ||
} | ||
} else if statusCode == 404 { | ||
/// 유저를 찾을 수 없는 상태 | ||
} else { | ||
if request.retryCount > retryLimit { | ||
print("🚨재시도 횟수가 너무 많습니다🚨") | ||
} | ||
completion(.doNotRetryWithError(error)) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
This file contains 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 @@ | ||
// | ||
// BaseModel.swift | ||
// HMH_iOS | ||
// | ||
// Created by 이지희 on 5/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct BaseResponse<T: Decodable>: Decodable { | ||
var status: Int | ||
var message: String? | ||
var data: T? | ||
} |
This file contains 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,32 @@ | ||
// | ||
// BaseTargetType.swift | ||
// HMH_iOS | ||
// | ||
// Created by 이지희 on 5/12/24. | ||
// | ||
|
||
|
||
import Foundation | ||
import Moya | ||
|
||
protocol BaseTargetType: TargetType {} | ||
|
||
|
||
extension BaseTargetType { | ||
typealias Parameters = [String: String] | ||
var baseURL: URL { | ||
guard let baseURL = URL(string: Config.baseURL) else { | ||
print("🚨🚨BASEURL ERROR🚨🚨") | ||
fatalError() | ||
} | ||
return baseURL | ||
} | ||
|
||
var sampleData: Data { | ||
return Data() | ||
} | ||
|
||
var validationType: ValidationType { | ||
return .successCodes | ||
} | ||
} |
This file contains 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,71 @@ | ||
// | ||
// NetworkProvider.swift | ||
// HMH_iOS | ||
// | ||
// Created by 이지희 on 5/12/24. | ||
// | ||
// | ||
|
||
import SwiftUI | ||
import Moya | ||
|
||
class NetworkProvider<Provider : TargetType> : MoyaProvider<Provider> { | ||
func request<Model : Codable>(target : Provider, instance : BaseResponse<Model>.Type , viewController: UIViewController, completion : @escaping(BaseResponse<Model>) -> ()){ | ||
self.request(target) { result in | ||
switch result { | ||
/// 서버 통신 성공 | ||
case .success(let response): | ||
if (200..<300).contains(response.statusCode) || | ||
response.statusCode == 403 { | ||
if let decodeData = try? JSONDecoder().decode(instance, from: response.data) { | ||
completion(decodeData) | ||
} else{ | ||
print("🚨 decoding Error 발생") | ||
} | ||
} else { | ||
print("🚨 Client Error") | ||
} | ||
/// 서버 통신 실패 | ||
case .failure(let error): | ||
if let response = error.response { | ||
if let responseData = String(data: response.data, encoding: .utf8) { | ||
print(responseData) | ||
} else { | ||
print(error.localizedDescription) | ||
} | ||
} else { | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func request<Model : Codable>(target : Provider, instance : BaseResponse<Model>.Type , completion : @escaping(BaseResponse<Model>) -> ()){ | ||
self.request(target) { result in | ||
switch result { | ||
/// 서버 통신 성공 | ||
case .success(let response): | ||
if (200..<300).contains(response.statusCode) { | ||
if let decodeData = try? JSONDecoder().decode(instance, from: response.data) { | ||
completion(decodeData) | ||
} else{ | ||
print("🚨 decoding Error 발생") | ||
} | ||
} else { | ||
print("🚨 Client Error") | ||
} | ||
/// 서버 통신 실패 | ||
case .failure(let error): | ||
if let response = error.response { | ||
if let responseData = String(data: response.data, encoding: .utf8) { | ||
print(responseData) | ||
} else { | ||
print(error.localizedDescription) | ||
} | ||
} else { | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Auth/RefreshTokenResponseDTO.swift
This file contains 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 @@ | ||
// | ||
// RefreshTokenResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/15/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RefreshTokebResponseDTO: Codable { | ||
let token: Token | ||
} |
This file contains 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,31 @@ | ||
// | ||
// #RequestDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/14/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct #RequestDTO: Codable { | ||
let socialPlatform: String | ||
let name: String | ||
let onboarding: Onboarding | ||
let challenge: Challenge | ||
} | ||
|
||
struct Onboarding: Codable { | ||
let averageUseTime: String | ||
let problem: [String] | ||
} | ||
|
||
struct Challenge: Codable { | ||
let period: Int | ||
let goalTime: Int | ||
let apps: [Apps] | ||
} | ||
|
||
struct Apps: Codable { | ||
let appCode: String | ||
let goalTime: Int | ||
} |
This file contains 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 @@ | ||
// | ||
// #ResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/14/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct #ResponseDTO: Codable { | ||
let userId: Int | ||
let token: Token | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Auth/SocialLoginRequestDTO.swift
This file contains 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 @@ | ||
// | ||
// SocialLoginRequestDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/14/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SocialLoginRequestDTO: Codable { | ||
let socialPlatform: String | ||
} |
18 changes: 18 additions & 0 deletions
18
HMH_iOS/HMH_iOS/Network/DTO/Auth/SocialLoginResponseDTO.swift
This file contains 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,18 @@ | ||
// | ||
// SocialLoginResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/14/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SocialLogineResponseDTO: Codable { | ||
let userId: Int | ||
let token: Token | ||
} | ||
|
||
struct Token: Codable { | ||
let accessToken: String | ||
let refreshToken: String | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Challenge/AddAppRequestDTO.swift
This file contains 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 @@ | ||
// | ||
// AddAppRequestDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/16/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AddAppRequestDTO: Codable { | ||
let apps: [Apps] | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Challenge/AddAppResponseDTO.swift
This file contains 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 @@ | ||
// | ||
// AddAppResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/16/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AddAppResponseDTO: Codable { | ||
let apps: [Apps] | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Challenge/CreateChallengeRequestDTO.swift
This file contains 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 @@ | ||
// | ||
// CreateChallengeRequestDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CreateChallengeRequestDTO: Codable { | ||
let period, goalTime: Int | ||
} |
16 changes: 16 additions & 0 deletions
16
HMH_iOS/HMH_iOS/Network/DTO/Challenge/CreateChallengeResponseDTO.swift
This file contains 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 @@ | ||
// | ||
// CreateChallengeResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CreateChallengeResponseDTO: Codable { | ||
let challengeID: Int | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case challengeID = "challengeId" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
HMH_iOS/HMH_iOS/Network/DTO/Challenge/DeleteAppRequestDTO.swift
This file contains 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 @@ | ||
// | ||
// DeleteAppRequestDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/16/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct DeleteAppRequestDTO: Codable { | ||
let appCode: String | ||
} |
10 changes: 10 additions & 0 deletions
10
HMH_iOS/HMH_iOS/Network/DTO/Challenge/EmptyResponseDTO.swift
This file contains 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,10 @@ | ||
// | ||
// EmptyResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/16/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct EmptyResponseDTO: Codable { } |
16 changes: 16 additions & 0 deletions
16
HMH_iOS/HMH_iOS/Network/DTO/Challenge/GetChallengeResponseDTO.swift
This file contains 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 @@ | ||
// | ||
// getChallengeResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 지희의 MAC on 1/16/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GetChallengeResponseDTO: Codable { | ||
let period: Int | ||
let statuses: [String] | ||
let todayIndex: Int | ||
let goalTime: Int | ||
let apps: [Apps] | ||
} |
14 changes: 14 additions & 0 deletions
14
HMH_iOS/HMH_iOS/Network/DTO/Challenge/GetHomeChallengeResponseDTO.swift
This file contains 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 @@ | ||
// | ||
// GetHomeChallengeResponseDTO.swift | ||
// HMH_iOS | ||
// | ||
// Created by 김보연 on 1/18/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GetHomeChallengeResponseDTO: Codable { | ||
let status: String | ||
let goalTime: Int | ||
let apps: [Apps] | ||
} |
Oops, something went wrong.