-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/#44-homeViewUI
- Loading branch information
Showing
20 changed files
with
327 additions
and
147 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.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,29 @@ | ||
// | ||
// UserDefaultWrapper.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
@propertyWrapper | ||
struct UserDefaultWrapper<T> { | ||
var wrappedValue: T? { | ||
get { | ||
return UserDefaults.standard.object(forKey: self.key) as? T | ||
} | ||
|
||
set { | ||
if newValue == nil { | ||
UserDefaults.standard.removeObject(forKey: key) | ||
} else { UserDefaults.standard.setValue(newValue, forKey: key) } | ||
} | ||
} | ||
|
||
private let key: String | ||
|
||
init(key: String) { | ||
self.key = key | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.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,90 @@ | ||
// | ||
// UserManager.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
final class UserManager { | ||
static let shared = UserManager() | ||
|
||
@UserDefaultWrapper<String>(key: "accessToken") private(set) var accessToken | ||
@UserDefaultWrapper<String>(key: "refreshToken") private(set) var refreshToken | ||
@UserDefaultWrapper<String>(key: "AppleToken") private(set) var appleToken | ||
@UserDefaultWrapper<String>(key: "userIdentifier") private(set) var appleUserIdentifier | ||
@UserDefaultWrapper<String>(key: "familyName") private(set) var familyName | ||
@UserDefaultWrapper<String>(key: "givenName") private(set) var givenName | ||
@UserDefaultWrapper<String>(key: "fullName") private(set) var fullName | ||
@UserDefaultWrapper<Int>(key: "userId") private(set) var userId | ||
|
||
var hasAccessToken: Bool { return self.accessToken != nil } | ||
var getAccessToken: String { return self.accessToken ?? "" } | ||
var getRefreshToken: String { return self.refreshToken ?? "" } | ||
var getAppleToken: String { return self.appleToken ?? "" } | ||
var getUserIdentifier: String { return self.appleUserIdentifier ?? "" } | ||
var getUserName: String { return self.familyName ?? "" } | ||
var getGivenName: String { return self.givenName ?? "" } | ||
var getFullName: String { return self.fullName ?? "" } | ||
var getUserId: Int { return self.userId ?? 0} | ||
|
||
var haveFullName: Bool { | ||
if fullName == "" { | ||
return false | ||
} else if fullName == nil { | ||
return false | ||
} else { | ||
return true | ||
} | ||
} | ||
|
||
private init() {} | ||
} | ||
|
||
extension UserManager { | ||
func updateToken(_ accessToken: String, _ refreshToken: String) { | ||
self.accessToken = accessToken | ||
self.refreshToken = refreshToken | ||
} | ||
|
||
func updateAppleToken(_ appleToken: String) { | ||
self.appleToken = appleToken | ||
} | ||
|
||
func updateUserIdentifier(_ appleUserIdentifier: String) { | ||
self.appleUserIdentifier = appleUserIdentifier | ||
} | ||
|
||
func updateUserName(_ givenName: String, _ familyName: String) { | ||
self.givenName = givenName | ||
self.familyName = familyName | ||
self.fullName = familyName + givenName | ||
} | ||
|
||
func updateUserId(_ userId: Int) { | ||
self.userId = userId | ||
} | ||
|
||
func setUserIdForApple(userId: String) { | ||
self.appleUserIdentifier = appleUserIdentifier | ||
} | ||
|
||
func clearAll() { | ||
self.accessToken = nil | ||
self.refreshToken = nil | ||
self.appleToken = nil | ||
self.appleUserIdentifier = nil | ||
self.familyName = nil | ||
self.givenName = nil | ||
self.fullName = nil | ||
self.userId = nil | ||
} | ||
|
||
func clearData() { | ||
self.accessToken = nil | ||
self.refreshToken = nil | ||
self.appleToken = nil | ||
self.appleUserIdentifier = nil | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -12,4 +12,3 @@ struct BaseResponse<T: Decodable>: Decodable { | |
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
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
17 changes: 17 additions & 0 deletions
17
HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/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,17 @@ | ||
// | ||
// 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" | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -35,4 +35,5 @@ struct NetworkHelper { | |
default: return .networkFail | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.