-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Convert to TCA * Add test * Add ._printChanges() on reducer * Revise RepositoryModel
- Loading branch information
Showing
16 changed files
with
889 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
final/GitHubSearch-final.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
final/GitHubSearch-final.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
77 changes: 77 additions & 0 deletions
77
final/GitHubSearch-final.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "combine-schedulers", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/combine-schedulers", | ||
"state" : { | ||
"revision" : "882ac01eb7ef9e36d4467eb4b1151e74fcef85ab", | ||
"version" : "0.9.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-case-paths", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-case-paths", | ||
"state" : { | ||
"revision" : "bb436421f57269fbcfe7360735985321585a86e5", | ||
"version" : "0.10.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-clocks", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-clocks", | ||
"state" : { | ||
"revision" : "20b25ca0dd88ebfb9111ec937814ddc5a8880172", | ||
"version" : "0.2.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections", | ||
"state" : { | ||
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729", | ||
"version" : "1.0.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-composable-architecture", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-composable-architecture", | ||
"state" : { | ||
"revision" : "52dca7e5edd6ec9e0b529380843a8cb13f57d7d7", | ||
"version" : "0.46.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-custom-dump", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-custom-dump", | ||
"state" : { | ||
"revision" : "ead7d30cc224c3642c150b546f4f1080d1c411a8", | ||
"version" : "0.6.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-identified-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-identified-collections", | ||
"state" : { | ||
"revision" : "a08887de589e3829d488e0b4b707b2ca804b1060", | ||
"version" : "0.5.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "xctest-dynamic-overlay", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", | ||
"state" : { | ||
"revision" : "5a5457a744239896e9b0b03a8e1a5069c3e7b91f", | ||
"version" : "0.6.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
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,5 @@ | ||
import Foundation | ||
|
||
enum APIError: Error { | ||
case invalidURL | ||
} |
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 @@ | ||
import SwiftUI | ||
|
||
import ComposableArchitecture | ||
|
||
@main | ||
struct GitHubSearchApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
RepoSearchView( | ||
store: Store( | ||
initialState: RepoSearch.State(), | ||
reducer: RepoSearch()._printChanges() | ||
) | ||
) | ||
} | ||
} | ||
} |
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,34 @@ | ||
import ComposableArchitecture | ||
|
||
struct RepoSearch: ReducerProtocol { | ||
struct State: Equatable { | ||
var keyword = "" | ||
var searchResults = [String]() | ||
} | ||
|
||
enum Action: Equatable { | ||
case keywordChanged(String) | ||
case search | ||
} | ||
|
||
func reduce(into state: inout State, action: Action) -> EffectTask<Action> { | ||
switch action { | ||
case let .keywordChanged(keyword): | ||
state.keyword = keyword | ||
return .none | ||
|
||
case .search: | ||
state.searchResults = self.sampleRepoLists.filter { | ||
$0.contains(state.keyword) | ||
} | ||
return .none | ||
} | ||
} | ||
|
||
private let sampleRepoLists = [ | ||
"Swift", | ||
"SwiftyJSON", | ||
"SwiftGuide", | ||
"SwiftterSwift", | ||
] | ||
} |
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,52 @@ | ||
import Foundation | ||
|
||
import ComposableArchitecture | ||
import XCTestDynamicOverlay | ||
|
||
struct RepoSearchClient { | ||
var search: @Sendable (String) async throws -> RepositoryModel | ||
} | ||
|
||
extension DependencyValues { | ||
var repoSearchClient: RepoSearchClient { | ||
get { self[RepoSearchClient.self] } | ||
set { self[RepoSearchClient.self] = newValue } | ||
} | ||
} | ||
|
||
// MARK: - Live API implementation | ||
|
||
extension RepoSearchClient: DependencyKey { | ||
static let liveValue = RepoSearchClient( | ||
search: { keyword in | ||
guard let url = URL(string: "https://api.github.com/search/repositories?q=\(keyword)") else { | ||
throw APIError.invalidURL | ||
} | ||
let (data, _) = try await URLSession.shared.data(from: url) | ||
return try JSONDecoder().decode(RepositoryModel.self, from: data) | ||
} | ||
) | ||
} | ||
|
||
extension RepoSearchClient: TestDependencyKey { | ||
static let previewValue = Self( | ||
search: { _ in .mock } | ||
) | ||
|
||
static let testValue = Self( | ||
search: unimplemented("\(Self.self).search") | ||
) | ||
} | ||
|
||
// Workshop 진행 중에 임시로 활용할 코드 | ||
// | ||
//func sampleSearchRequest(keyword: String, send: Send<RepoSearch.Action>) async throws { | ||
// guard let url = URL(string: "https://api.github.com/search/repositories?q=\(keyword)") else { | ||
// await send(RepoSearch.Action.dataLoaded(.failure(APIError.invalidUrlError))) | ||
// return | ||
// } | ||
// let (data, _) = try await URLSession.shared.data(from: url) | ||
// let result = await TaskResult { try JSONDecoder().decode(RepositoryModel.self, from: data) } | ||
// | ||
// await send(RepoSearch.Action.dataLoaded(result)) | ||
//} |
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,50 @@ | ||
import SwiftUI | ||
|
||
import ComposableArchitecture | ||
|
||
struct RepoSearchView: View { | ||
let store: StoreOf<RepoSearch> | ||
|
||
var body: some View { | ||
WithViewStore(self.store) { viewStore in | ||
NavigationView { | ||
VStack { | ||
HStack { | ||
TextField( | ||
"Search repo", | ||
text: Binding( | ||
get: { viewStore.keyword }, | ||
set: { viewStore.send(.keywordChanged($0)) } | ||
) | ||
) | ||
.textFieldStyle(.roundedBorder) | ||
|
||
Button("Search") { | ||
viewStore.send(.search) | ||
} | ||
.buttonStyle(.borderedProminent) | ||
} | ||
.padding() | ||
|
||
List { | ||
ForEach(viewStore.searchResults, id: \.self) { | ||
Text($0) | ||
} | ||
} | ||
} | ||
.navigationTitle("Github Search") | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct RepoSearchView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
RepoSearchView( | ||
store: Store( | ||
initialState: RepoSearch.State(), | ||
reducer: RepoSearch() | ||
) | ||
) | ||
} | ||
} |
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,23 @@ | ||
struct RepositoryModel: Decodable, Equatable, Sendable { | ||
var items: [Result] | ||
|
||
struct Result: Decodable, Equatable, Sendable { | ||
var name: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case name = "full_name" | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Mock data | ||
|
||
extension RepositoryModel { | ||
static let mock = Self( | ||
items: [ | ||
RepositoryModel.Result(name: "Swift"), | ||
RepositoryModel.Result(name: "SwiftLint"), | ||
RepositoryModel.Result(name: "SwiftAlgorithm") | ||
] | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
final/GitHubSearch/Resources/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
final/GitHubSearch/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json
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 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
final/GitHubSearch/Resources/Preview Content/Preview Assets.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,28 @@ | ||
import XCTest | ||
|
||
import ComposableArchitecture | ||
|
||
@testable import GitHubSearch_final | ||
|
||
@MainActor | ||
final class RepositoryTests: XCTestCase { | ||
func test_user_get_repoSearchResults_when_search() async { | ||
let store = TestStore( | ||
initialState: RepoSearch.State(), | ||
reducer: RepoSearch() | ||
) | ||
|
||
await store.send(.keywordChanged("Swift")) { | ||
$0.keyword = "Swift" | ||
} | ||
|
||
await store.send(.search) { | ||
$0.searchResults = [ | ||
"Swift", | ||
"SwiftyJSON", | ||
"SwiftGuide", | ||
"SwiftterSwift", | ||
] | ||
} | ||
} | ||
} |
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