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

네트워크 매니저 리팩토링 #85

Merged
merged 15 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.
Binary file modified Encrypted/XCConfig/App/DEV.xcconfig.encrypted
Binary file not shown.
2 changes: 1 addition & 1 deletion Encrypted/XCConfig/App/PROD.xcconfig.encrypted
Original file line number Diff line number Diff line change
@@ -1 +1 @@
�d��BJؠ���LH�8�v2c�����mH �"?^F1Xn�o^� |�т�2x>�SFgtmz \���Ԍ����uQ&uD�0�p>y�����|/�N&UcŞ�;RV��$�H�K����X6W]�nu.����i}�D�ş?��~Jod >�w���R
�d��BJؠ���LH�8�v2c�����mH �"?^F1Xn�o^� |�т�2x>�SFgtmz \���Ԍ����uQ&=O��pV��fa�zuc)�!����wW�0+SXl>7{�mD@���Z�]��增�o�_{�Z���Ex�6 l}�5`������W����.?��h��o>Hˈ4��: SѢ����C^7L�
Expand Down
31 changes: 16 additions & 15 deletions Projects/Domain/Sources/Client/KeymeTestsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,30 @@ extension DependencyValues {
}

extension KeymeTestsClient: DependencyKey {
public static var liveValue = KeymeTestsClient(
public static var liveValue = getClient(with: KeymeAPIManager.liveValue)
public static var testValue = getClient(with: KeymeAPIManager.testValue)
}

private func getClient(with network: KeymeAPIManager) -> KeymeTestsClient {
KeymeTestsClient(
fetchOnboardingTests: {
let api = KeymeTestsAPI.onboarding
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: KeymeTestsDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: KeymeTestsDTO.self)
let api = KeymeAPI.test(.onboarding)
let response = try await network.request(api, object: KeymeTestsDTO.self)

return response.toIconModel()
return response.toKeymeTestsModel()
}, fetchDailyTests: {
let api = KeymeTestsAPI.daily
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: KeymeTestsDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: KeymeTestsDTO.self)
let api = KeymeAPI.test(.daily)
let response = try await network.request(api, object: KeymeTestsDTO.self)

return response.toIconModel()
return response.toKeymeTestsModel()
}, fetchTestResult: { testResultId in
let api = KeymeTestsAPI.result(testResultId)
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: TestResultDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: TestResultDTO.self)
let api = KeymeAPI.test(.result(testResultId))
let response = try await network.request(api, object: TestResultDTO.self)

return response.data.results.map { $0.toModel() }
}, postTestResult: { resultCode in
let api = KeymeTestsAPI.register(resultCode)
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: BaseDTO<String>.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: BaseDTO<String>.self)
let api = KeymeAPI.test(.register(resultCode))
let response = try await network.request(api, object: BaseDTO<String>.self)

return response.message
}
Expand Down
35 changes: 0 additions & 35 deletions Projects/Domain/Sources/Client/TestClient.swift

This file was deleted.

9 changes: 9 additions & 0 deletions Projects/Domain/Sources/Model/CirclePack/CharacterScore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2023 team.humanwave. All rights reserved.
//

import Network
import Foundation

public struct CharacterScore: Identifiable, Equatable {
Expand All @@ -18,3 +19,11 @@ public struct CharacterScore: Identifiable, Equatable {
self.date = date
}
}

public extension QuestionResultScoresDTO {
func toCharacterScores() -> [CharacterScore] {
return self.data.results.map { resultItem in
CharacterScore(score: resultItem.score, date: resultItem.createdAt)
}
}
}
9 changes: 3 additions & 6 deletions Projects/Domain/Sources/Model/KeymeTestsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Network
import Kingfisher

public struct KeymeTestsModel: Equatable {
public let nickname: String
public let testId: Int
public let icons: [IconModel]
}
Expand All @@ -26,14 +25,12 @@ public struct IconModel: Equatable, Hashable {
}

public extension KeymeTestsDTO {
func toIconModel() -> KeymeTestsModel {
let nickname = data.owner.nickname
func toKeymeTestsModel() -> KeymeTestsModel {
let icons = data.questions.map {
IconModel(imageURL: $0.category.iconUrl,
color: Color.hex($0.category.color))
}
return KeymeTestsModel(nickname: nickname ?? "키미",
testId: data.testId,
icons: icons)

return KeymeTestsModel(testId: data.testId, icons: icons)
}
}
2 changes: 1 addition & 1 deletion Projects/Domain/Sources/Model/KeymeWebModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

public struct KeymeWebViewModel: Codable, Equatable {
public let matchRate: Int
public let matchRate: Float
public let resultCode: String
public let testResultId: Int
}
21 changes: 0 additions & 21 deletions Projects/Domain/Sources/Model/TestModel.swift

This file was deleted.

16 changes: 14 additions & 2 deletions Projects/Domain/Sources/User/KeymeUserStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public final class KeymeUserStorage {

private enum UserStorageKey: String, StorageKeyType {
case accessToken
case userId
case friendCode
case nickname
case profileImageURL
case profileThumbnailURL
Expand All @@ -45,19 +47,29 @@ public extension KeymeUserStorage {
set { set(newValue, forKey: .accessToken) }
}

var userId: Int? {
get { get(.userId) as? Int }
set { set(newValue, forKey: .userId) }
}

var friendCode: String? {
get { get(.friendCode) as? String }
set { set(newValue, forKey: .friendCode) }
}

var nickname: String? {
get { get(.nickname) as? String }
set { set(newValue, forKey: .nickname) }
}

var profileImageURL: URL? {
get { get(.profileImageURL) as? URL }
set { set(newValue, forKey: .profileImageURL) }
set { set(newValue?.absoluteString, forKey: .profileImageURL) }
}

var profileThumbnailURL: URL? {
get { get(.profileThumbnailURL) as? URL }
set { set(newValue, forKey: .profileThumbnailURL) }
set { set(newValue?.absoluteString, forKey: .profileThumbnailURL) }
}
}

Expand Down
61 changes: 61 additions & 0 deletions Projects/Features/Sources/Home/KeymeTestHomeFeature.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// KeymeTestHomeFeature.swift
// Features
//
// Created by 이영빈 on 2023/08/30.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import ComposableArchitecture
import Domain
import Network

struct KeymeTestsHomeFeature: Reducer {
@Dependency(\.keymeAPIManager) private var network

// 테스트를 아직 풀지 않았거나, 풀었거나 2가지 케이스만 존재
struct State: Equatable {
@PresentationState var testStartViewState: KeymeTestsStartFeature.State?
var view: View

struct View: Equatable {
let nickname: String
var dailyTestId: Int?
}

init(nickname: String) {
self.view = View(nickname: nickname)
}
}

enum Action {
case fetchDailyTests
case showTestStartView(testData: KeymeTestsModel)
case startTest(PresentationAction<KeymeTestsStartFeature.Action>)

enum View {}
}

var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .fetchDailyTests:
return .run { send in
let fetchedTest = try await network.request(.test(.daily), object: KeymeTestsDTO.self)
let testData = fetchedTest.toKeymeTestsModel()

await send(.showTestStartView(testData: testData))
}

case .showTestStartView(let testData):
state.view.dailyTestId = testData.testId
state.testStartViewState = .init(nickname: state.view.nickname, testData: testData)

default:
break
}

return .none
}
}
}
71 changes: 71 additions & 0 deletions Projects/Features/Sources/Home/KeymeTestHomeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// KeymeTestHomeView.swift
// Features
//
// Created by 이영빈 on 2023/08/30.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import ComposableArchitecture
import DSKit
import SwiftUI

struct KeymeTestsHomeView: View {
var store: StoreOf<KeymeTestsHomeFeature>

init(store: StoreOf<KeymeTestsHomeFeature>) {
self.store = store
store.send(.fetchDailyTests)
}

var body: some View {
WithViewStore(store, observe: { $0.view }) { viewStore in
ZStack(alignment: .center) {
DSKitAsset.Color.keymeBlack.swiftUIColor.ignoresSafeArea()

VStack(alignment: .leading) {
// Filler
Spacer().frame(height: 75)

welcomeText(nickname: viewStore.nickname)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)

Spacer()
}
.fullFrame()
.padding(.horizontal, 16)

// 테스트 뷰
testView

// 결과 화면 표시도 생각

}
}
}
}

extension KeymeTestsHomeView {
var testView: some View {
let startTestStore = store.scope(
state: \.$testStartViewState,
action: KeymeTestsHomeFeature.Action.startTest)

return IfLetStore(startTestStore) { store in
KeymeTestsStartView(store: store)
} else: {
Circle()
.strokeBorder(.white.opacity(0.3), lineWidth: 1)
.background(Circle().foregroundColor(.white.opacity(0.3)))
.frame(width: 280, height: 280)
}
}

func welcomeText(nickname: String) -> some View {
Text.keyme(
"환영해요 \(nickname)님!",
// "환영해요 \(viewStore.nickname)님!\n이제 문제를 풀어볼까요?",
font: .heading1)
}

}
Loading