-
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.
[Feat/#118] ChallengeServiceTest 데모앱 기능 개발
- Loading branch information
Showing
8 changed files
with
558 additions
and
73 deletions.
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
...OS/Projects/Modules/Networks/Demo/Sources/ChallengeServiceTest/ChallengeServiceView.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,165 @@ | ||
// | ||
// ChallengeServiceTestView.swift | ||
// NetworksDemo | ||
// | ||
// Created by 류희재 on 11/23/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import Networks | ||
import Core | ||
import Combine | ||
|
||
struct ChallengeServiceView: View { | ||
|
||
@StateObject var viewModel: ChallengeServiceViewModel | ||
|
||
var body: some View { | ||
VStack { | ||
HStack { | ||
Button { | ||
print("뒤로 가기") | ||
} label: { | ||
Image(systemName: "chevron.backward") | ||
.resizable() | ||
.foregroundColor(.white) | ||
.frame(width: 12, height: 24) | ||
} | ||
.padding(.leading, 14) | ||
|
||
Spacer() | ||
|
||
Text("ChallengeService") | ||
.foregroundStyle(Color( | ||
red: 165 / 255.0, | ||
green: 165 / 255.0, | ||
blue: 187 / 255.0 | ||
)) | ||
.font(.title) | ||
.bold() | ||
.multilineTextAlignment(.center) | ||
|
||
Spacer() | ||
} | ||
.padding(.vertical, 18) | ||
|
||
ServiceListView(viewModel: viewModel) | ||
.padding(.horizontal, 20) | ||
.padding(.bottom, 25) | ||
.frame(height: 360) | ||
|
||
Rectangle() | ||
.foregroundColor(.white) | ||
.frame(width: .infinity, height: 3) | ||
.padding(.horizontal, 20) | ||
.padding(.bottom, 25) | ||
|
||
Text(viewModel.state.networkLoggingText) | ||
.padding(.top, 25) | ||
.padding(.horizontal, 20) | ||
.frame(width: 335, height: 240) | ||
.background(.gray) | ||
|
||
Spacer() | ||
} | ||
.background(Color(asset: NetworksDemoAsset.blackground)) | ||
} | ||
} | ||
|
||
fileprivate struct ServiceListView: View { | ||
private let viewModel: ChallengeServiceViewModel | ||
|
||
init(viewModel: ChallengeServiceViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
let apiList: [String] = [ | ||
"GetDailyChallenge", | ||
"GetSuccesChallenge", | ||
"CreateChallenge", | ||
"PostLockChallenge", | ||
"DeleteApp", | ||
"AddApp", | ||
"GetChallenge" | ||
] | ||
var body: some View { | ||
VStack { | ||
Spacer() | ||
.frame(height: 24) | ||
|
||
ScrollView(.vertical, showsIndicators: true) { | ||
ForEach(Array(apiList.enumerated()), id: \.element) { index, api in | ||
ServiceCellView(apiTitle: api, index: index, viewModel: viewModel) | ||
Rectangle() | ||
.foregroundColor(.gray) | ||
.frame(width: .infinity, height: 1) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fileprivate struct ServiceCellView: View { | ||
private let apiTitle: String | ||
private let index: Int | ||
@ObservedObject private var viewModel: ChallengeServiceViewModel | ||
|
||
init(apiTitle: String, index: Int, viewModel: ChallengeServiceViewModel) { | ||
self.apiTitle = apiTitle | ||
self.index = index | ||
self.viewModel = viewModel | ||
} | ||
|
||
|
||
var body: some View { | ||
HStack { | ||
VStack(alignment: .leading) { | ||
Text(apiTitle) | ||
.foregroundStyle(Color( | ||
red: 219 / 255.0, | ||
green: 218 / 255.0, | ||
blue: 231 / 255.0 | ||
)) | ||
.font(.title2) | ||
.bold() | ||
.frame(height: 2) | ||
.padding(.bottom, 10) | ||
|
||
Text("테스트 결과: \(viewModel.state.resultText[index])") | ||
.foregroundColor(.white) | ||
.font(.body) | ||
.bold() | ||
} | ||
.padding(.vertical, 18) | ||
|
||
Spacer() | ||
|
||
Button { | ||
viewModel.send(action: .serviceButtonDidTap(index)) | ||
} label: | ||
Text("Test") | ||
.foregroundColor(.white) | ||
.font(.title) | ||
.bold() | ||
.padding(.horizontal, 16) | ||
.padding(.vertical, 8) | ||
.background(Color( | ||
red: 70 / 255.0, | ||
green: 30 / 255.0, | ||
blue: 229 / 255.0 | ||
)) | ||
.clipShape(RoundedRectangle(cornerRadius: 4)) | ||
} | ||
} | ||
.frame(height: 80) | ||
} | ||
} | ||
|
||
#Preview { | ||
return ChallengeServiceView( | ||
viewModel: ChallengeServiceViewModel( | ||
service: ChallengeService() | ||
) | ||
) | ||
} |
142 changes: 142 additions & 0 deletions
142
...ojects/Modules/Networks/Demo/Sources/ChallengeServiceTest/ChallengeServiceViewModel.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,142 @@ | ||
// | ||
// ChallengeServiceViewModel.swift | ||
// NetworksDemo | ||
// | ||
// Created by 류희재 on 11/23/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import Core | ||
import Networks | ||
|
||
class ChallengeServiceViewModel: ObservableObject { | ||
|
||
//MARK: Action, State | ||
|
||
enum Action { | ||
case serviceButtonDidTap(Int) | ||
} | ||
|
||
struct State { | ||
var resultText: [String] = Array(repeating: "", count: 7) | ||
var networkLoggingText: String = "네트워크 결과창입니다!" | ||
} | ||
|
||
//MARK: Dependency | ||
|
||
let service: ChallengeServiceType | ||
|
||
// MARK: - Init | ||
init(service: ChallengeServiceType) { | ||
self.service = service | ||
self.state = State() | ||
} | ||
|
||
//MARK: Properties | ||
|
||
@Published private(set) var state: State | ||
private let cancelBag = CancelBag() | ||
|
||
//MARK: Methods | ||
|
||
func send(action: Action) { | ||
switch action { | ||
case .serviceButtonDidTap(let index): | ||
switch index { | ||
case 0: | ||
service.getDailyChallenge() | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
case 1: | ||
service.getSuccesChallenge() | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
case 2: | ||
service.createChallenge(request: .stub) | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
case 3: | ||
service.postLockChallenge() | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
case 4: | ||
service.deleteApp(request: .stub) | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
|
||
case 5: | ||
service.addApp(request: .stub) | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
|
||
case 6: | ||
service.getChallenge() | ||
.sink(receiveCompletion: { [weak self] completion in | ||
if case let .failure(error) = completion { | ||
self?.state.networkLoggingText = error.description | ||
self?.state.resultText[index] = "❌ 실패" | ||
} | ||
}) { [weak self] result in | ||
self?.state.networkLoggingText = "\(result)" | ||
self?.state.resultText[index] = "✅ 성공" | ||
} | ||
.store(in: cancelBag) | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
19 changes: 19 additions & 0 deletions
19
HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationDestination.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,19 @@ | ||
// | ||
// NavigationDestination.swift | ||
// NetworksDemo | ||
// | ||
// Created by 류희재 on 11/23/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NavigationDestination: Hashable { | ||
|
||
case auth | ||
case challenge | ||
case point | ||
case user | ||
|
||
} | ||
|
46 changes: 46 additions & 0 deletions
46
HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRouter.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,46 @@ | ||
//// | ||
//// NavigationRouter.swift | ||
//// NetworksDemo | ||
//// | ||
//// Created by 류희재 on 11/23/24. | ||
//// Copyright © 2024 HMH-iOS. All rights reserved. | ||
//// | ||
// | ||
//import Foundation | ||
//import Combine | ||
// | ||
//protocol NavigationRoutable { | ||
// var destinations: [NavigationDestination] { get set } | ||
// | ||
// func push(to view: NavigationDestination) | ||
// func pop() | ||
// func popToRootView() | ||
//} | ||
// | ||
// | ||
//class NavigationRouter: NavigationRoutable, ObservableObjectSettable { | ||
// | ||
// var objectWillChange: ObservableObjectPublisher? | ||
// | ||
// var destinations: [NavigationDestination] = [] { | ||
// didSet { | ||
// objectWillChange?.send() | ||
// } | ||
// } | ||
// | ||
// func push(to view: NavigationDestination) { | ||
// destinations.append(view) | ||
// } | ||
// | ||
// func pop() { | ||
// _ = destinations.popLast() | ||
// } | ||
// | ||
// func popToRootView() { | ||
// destinations = [] | ||
// } | ||
// | ||
// | ||
//} | ||
// | ||
// |
Oops, something went wrong.