Skip to content
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

코드 정리 #80

Merged
merged 40 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4e184ed
fix #78: 스토리지에 유저 레이어 추가
enebin Aug 21, 2023
4887f25
refactor #78: 로그인 관련 로직 정리
enebin Aug 23, 2023
2e9fa58
refactor #78: 로그인 관련 API 정리
enebin Aug 23, 2023
1b7f270
refactor #78: 네트워크를 디펜던시로 분리
enebin Aug 23, 2023
1babe51
refactor #78: 엑세스 토큰 등록 로직 연결
enebin Aug 23, 2023
b8c6943
Merge pull request #81 from Nexters/refactor/user-related(#78)
enebin Aug 25, 2023
02f75ec
feature #20: 개인 정보 관련 뷰 구현
k906506 Aug 12, 2023
687f81b
feature #20: TextField가 좌, 우로 떨리는 애니메이션 구현
k906506 Aug 12, 2023
2fcf739
feature #20: 프로필 이미지 등록 구현
k906506 Aug 12, 2023
60d6ea0
style #20: 프로퍼티 관련 주석 수정
k906506 Aug 12, 2023
06da3b0
feat #20: 개인정보 등록 feature 추가
enebin Aug 23, 2023
2db6242
feat #20: 이미지, 프로필 API 추가
enebin Aug 23, 2023
d2ce761
feat #20: 프로필 등록 API 연결
enebin Aug 23, 2023
9bb2359
feat #20: 개인정보 등록 뷰 합침
enebin Aug 23, 2023
befae92
feat #20: 닉네임 텍스트박스 디바운싱
enebin Aug 24, 2023
1f96650
feat #20: 닉네임 텍스트박스 API 연결
enebin Aug 24, 2023
6b18378
feat #20: 제출, 이미지 등록 API 연결
enebin Aug 24, 2023
23e8a82
feat #20: 개인정보 등록 화면 루트에 연결
enebin Aug 24, 2023
f967694
feat #20: 개인정보 등록 API 연결
enebin Aug 24, 2023
1e7586d
refactor #82: 공유자원 관리 클래스 리팩토링
enebin Aug 25, 2023
1981337
refactor #82: root feature에 업데이트 코드 연결
enebin Aug 25, 2023
ab3967f
refactor #82: 의존성 개선
enebin Aug 25, 2023
62fd070
Merge branch 'refactor/common-user-data-management(#82)' into feature…
enebin Aug 25, 2023
3e8698f
Merge pull request #83 from Nexters/feature/add-registration(#20)
enebin Aug 29, 2023
b54f6a5
refactor #82: API들 각 파일로 분리
enebin Aug 25, 2023
e52e817
refactor #82: 푸시토큰 등록 로직 변경
enebin Aug 25, 2023
a7a859b
refactor #82: 테스트 클라이언트 단순화 및 수정
enebin Aug 25, 2023
1d038e8
refactor #82: 네트워크 폴더 정리
enebin Aug 25, 2023
3e1a997
fix #82: 웹뷰 결과 파싱 실패 버그 수정
enebin Aug 28, 2023
933bfdb
feat #82: 사용자 정보 추가 저장
enebin Aug 28, 2023
e6f8c3a
feat #84: 스코어 리스트 로직 추가
enebin Aug 29, 2023
3e818e0
feat #84: 스코어 리스트 API 추가
enebin Aug 29, 2023
3dc9559
fix #84: 스코어 리스트 API 디버그 및 수정
enebin Aug 29, 2023
41d4ef8
fix #84: 닉네임 관련 하드코딩 제거 및 구조변경
enebin Aug 30, 2023
20ef761
refactor #84: 마이페이지 스토어 공개범위 수정
enebin Aug 30, 2023
d1aad3b
refactor #84: 테스트 뷰(홈) 로직 수정
enebin Aug 30, 2023
7949bfe
refactor #84: 테스트 뷰(홈) API 수정
enebin Aug 31, 2023
9a8c18a
Merge pull request #86 from Nexters/refactor/mypage-score-list(#84)
enebin Sep 3, 2023
dad5a33
chore #82: 푸시토큰 API 이름 변경
enebin Sep 3, 2023
ee8d21f
Merge pull request #85 from Nexters/refactor/network-manager
enebin Sep 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Encrypted/Secrets/GoogleService-Info.plist.encrypted
Binary file not shown.
41 changes: 41 additions & 0 deletions Projects/Domain/Sources/Client/CoreLocalStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// LocalStorageClient.swift
// Domain
//
// Created by Young Bin on 2023/08/10.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import ComposableArchitecture
import Foundation

struct CoreLocalStorage {
private let storage: UserDefaults

init(storage: UserDefaults = .standard) {
self.storage = storage
}

/// 알아서 파싱해서 쓰시길.. 더 빡세게 잡으려면 우리가 귀찮아짐
public func get(_ key: some StorageKeyType) -> Any? {
storage.object(forKey: key.name)
}

public func set(_ value: Any?, forKey key: some StorageKeyType) {
storage.set(value, forKey: key.name)
}
}

extension CoreLocalStorage: DependencyKey {
static var liveValue = CoreLocalStorage()
static func testValue(storage: UserDefaults) -> CoreLocalStorage {
CoreLocalStorage(storage: storage)
}
}

extension DependencyValues {
var localStorage: CoreLocalStorage {
get { self[CoreLocalStorage.self] }
set { self[CoreLocalStorage.self] = newValue }
}
}
69 changes: 0 additions & 69 deletions Projects/Domain/Sources/Client/LocalStorage.swift

This file was deleted.

72 changes: 72 additions & 0 deletions Projects/Domain/Sources/User/KeymeUserStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// KeymeUserStorage.swift
// Domain
//
// Created by 이영빈 on 2023/08/21.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import ComposableArchitecture
import Foundation
protocol StorageKeyType {
var name: String { get }
}

public final class KeymeUserStorage {
@Dependency(\.localStorage) private var localStorage

var nickname: String?
var acesssToken: String?

public init() {
self.nickname = self.get(.nickname)
self.acesssToken = self.get(.acesssToken)
}

public func get<T>(_ key: UserStorageKey) -> T? {
return localStorage.get(key) as? T
}

public func set<T>(_ value: T?, forKey key: UserStorageKey) {
switch key {
case .acesssToken:
guard let flag = value as? String else { return }
self.acesssToken = flag
case .nickname:
guard let name = value as? String else { return }
self.nickname = name
}

localStorage.set(value, forKey: key)
}
}

public extension KeymeUserStorage {
enum UserStorageKey: StorageKeyType {
case acesssToken
case nickname

var name: String {
switch self {
case .acesssToken:
return "UserStorageKey_isLoggedIn"
case .nickname:
return "UserStorageKey_nickname"
}
}
}
}

extension KeymeUserStorage: DependencyKey {
public static var liveValue = KeymeUserStorage()
public static var testValue: KeymeUserStorage {
KeymeUserStorage() // FIXME:
}
}

extension DependencyValues {
public var userStorage: KeymeUserStorage {
get { self[KeymeUserStorage.self] }
set { self[KeymeUserStorage.self] = newValue }
}
}
75 changes: 40 additions & 35 deletions Projects/Features/Sources/Root/RootFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Network
import ComposableArchitecture

public struct RootFeature: Reducer {
@Dependency(\.localStorage) private var localStorage
@Dependency(\.userStorage) private var userStorage
@Dependency(\.keymeAPIManager) private var network

public init() {}

Expand Down Expand Up @@ -55,47 +56,34 @@ public struct RootFeature: Reducer {
public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .login(.presented(let result)):
// switch result {
// case .succeeded:
// localStorage.set(true, forKey: .isLoggedIn)
// state.logInStatus = .loggedIn
// case .failed:
// localStorage.set(false, forKey: .isLoggedIn)
// state.logInStatus = .loggedOut
return .none

case .onboarding(.presented(let result)):
switch result {
case .succeeded:
state.onboardingStatus?.status = .completed
case .failed:
state.onboardingStatus?.status = .needsOnboarding
default:
break
case .login(.presented(.signInWithAppleResponse(let response))):
let token: String?
switch response {
case .success(let body):
token = body.data.token.accessToken
case .failure:
token = nil
}
return .none

case .logInChecked(let result):
switch result {
case true:
state.logInStatus = .loggedIn
case false:
state.logInStatus = .loggedOut
}
userStorage.set(token, forKey: .acesssToken)
network.registerAuthorizationToken(token)
return .none

case .onboardingChecked(.success(let result)):
switch result {
case true:
state.onboardingStatus?.status = .completed
case false:
state.onboardingStatus?.status = .needsOnboarding
case .login(.presented(.signInWithKakaoResponse(let response))):
let token: String?
switch response {
case .success(let body):
token = body.data.token.accessToken
case .failure:
token = nil
}

userStorage.set(token, forKey: .acesssToken)
network.registerAuthorizationToken(token)
return .none

case .checkLoginStatus:
let isLoggedIn = localStorage.get(.isLoggedIn) as? Bool ?? false
let isLoggedIn: Bool = userStorage.get(.acesssToken) == nil ? false : true
return .run { send in
await send(.logInChecked(isLoggedIn))
}
Expand All @@ -106,12 +94,29 @@ public struct RootFeature: Reducer {
TaskResult {
// TODO: API 갈아끼우기
// try await Task.sleep(until: .now + .seconds(0.1), clock: .continuous)

return false
}
))
}

case .logInChecked(let result):
switch result {
case true:
state.logInStatus = .loggedIn
case false:
state.logInStatus = .loggedOut
}
return .none

case .onboardingChecked(.success(let result)):
switch result {
case true:
state.onboardingStatus?.status = .completed
case false:
state.onboardingStatus?.status = .needsOnboarding
}
return .none

default:
return .none
}
Expand Down
Loading