Skip to content

Commit 035d2eb

Browse files
committed
Improve UseCase
1 parent 83a99c4 commit 035d2eb

File tree

17 files changed

+53
-120
lines changed

17 files changed

+53
-120
lines changed

CleanArchitectureRxSwift.xcodeproj/project.pbxproj

Lines changed: 18 additions & 32 deletions
Large diffs are not rendered by default.

CleanArchitectureRxSwift/Scenes/AllPosts/PostsNavigator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class DefaultPostsNavigator: PostsNavigator {
2222

2323
func toPosts() {
2424
let vc = storyBoard.instantiateViewController(ofType: PostsViewController.self)
25-
vc.viewModel = PostsViewModel(useCase: services.makeAllPostsUseCase(),
25+
vc.viewModel = PostsViewModel(useCase: services.makePostsUseCase(),
2626
navigator: self)
2727
navigationController.pushViewController(vc, animated: true)
2828
}
2929

3030
func toCreatePost() {
3131
let navigator = DefaultCreatePostNavigator(navigationController: navigationController)
32-
let viewModel = CreatePostViewModel(createPostUseCase: services.makeCreatePostUseCase(),
32+
let viewModel = CreatePostViewModel(createPostUseCase: services.makePostsUseCase(),
3333
navigator: navigator)
3434
let vc = storyBoard.instantiateViewController(ofType: CreatePostViewController.self)
3535
vc.viewModel = viewModel
@@ -39,7 +39,7 @@ class DefaultPostsNavigator: PostsNavigator {
3939

4040
func toPost(_ post: Post) {
4141
let vc = storyBoard.instantiateViewController(ofType: EditPostViewController.self)
42-
let viewModel = EditPostViewModel(post: post, useCase: services.makeCreatePostUseCase())
42+
let viewModel = EditPostViewModel(post: post, useCase: services.makePostsUseCase())
4343
vc.viewModel = viewModel
4444
navigationController.pushViewController(vc, animated: true)
4545
}

CleanArchitectureRxSwift/Scenes/AllPosts/PostsViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ final class PostsViewModel: ViewModelType {
1818
let error: Driver<Error>
1919
}
2020

21-
private let useCase: AllPostsUseCase
21+
private let useCase: PostsUseCase
2222
private let navigator: PostsNavigator
2323

24-
init(useCase: AllPostsUseCase, navigator: PostsNavigator) {
24+
init(useCase: PostsUseCase, navigator: PostsNavigator) {
2525
self.useCase = useCase
2626
self.navigator = navigator
2727
}

CleanArchitectureRxSwift/Scenes/CreatePost/CreatePostViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import RxCocoa
1010
import Domain
1111

1212
final class CreatePostViewModel: ViewModelType {
13-
private let createPostUseCase: SavePostUseCase
13+
private let createPostUseCase: PostsUseCase
1414
private let navigator: CreatePostNavigator
1515

16-
init(createPostUseCase: SavePostUseCase, navigator: CreatePostNavigator) {
16+
init(createPostUseCase: PostsUseCase, navigator: CreatePostNavigator) {
1717
self.createPostUseCase = createPostUseCase
1818
self.navigator = navigator
1919
}

CleanArchitectureRxSwift/Scenes/EditPost/EditPostViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import RxCocoa
44

55
final class EditPostViewModel: ViewModelType {
66
private let post: Post
7-
private let useCase: SavePostUseCase
7+
private let useCase: PostsUseCase
88

9-
init(post: Post, useCase: SavePostUseCase) {
9+
init(post: Post, useCase: PostsUseCase) {
1010
self.post = post
1111
self.useCase = useCase
1212
}

CoreDataPlatform/UseCases/AllPostsUseCase.swift renamed to CoreDataPlatform/UseCases/PostsUseCase.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import Foundation
22
import Domain
33
import RxSwift
44

5-
final class CDAllPostsUseCase: AllPostsUseCase {
5+
final class PostsUseCase: Domain.PostsUseCase {
6+
67
private let repository: AbstractRepository<Post>
78

89
init(repository: AbstractRepository<Post>) {
@@ -12,4 +13,8 @@ final class CDAllPostsUseCase: AllPostsUseCase {
1213
func posts() -> Observable<[Post]> {
1314
return repository.query(sortDescriptors: [Post.CoreDataType.uid.descending()])
1415
}
16+
17+
func save(post: Post) -> Observable<Void> {
18+
return repository.save(entity: post)
19+
}
1520
}

CoreDataPlatform/UseCases/SavePostUseCase.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

CoreDataPlatform/UseCases/UseCaseProvider.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ public final class UseCaseProvider: Domain.UseCaseProvider {
99
postRepository = Repository<Post>(context: coreDataStack.context)
1010
}
1111

12-
public func makeAllPostsUseCase() -> AllPostsUseCase {
13-
return CDAllPostsUseCase(repository: postRepository)
14-
}
15-
16-
public func makeCreatePostUseCase() -> SavePostUseCase {
17-
return CDSavePostUseCase(repository: postRepository)
12+
public func makePostsUseCase() -> Domain.PostsUseCase {
13+
return PostsUseCase(repository: postRepository)
1814
}
1915
}

Domain/UseCases/AllPostsUseCase.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import RxSwift
33

4-
public protocol SavePostUseCase {
4+
public protocol PostsUseCase {
5+
func posts() -> Observable<[Post]>
56
func save(post: Post) -> Observable<Void>
67
}

0 commit comments

Comments
 (0)