-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] 검색 뷰 기능 구현 및 아키텍처 적용 #39
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
Changes from all commits
19ca603
6f95e5d
4e9f8ea
cd1a41a
1545878
dc530dd
fea5412
26b0f6c
94ad43b
4ab4eab
27ccb89
d896d95
04fc6a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // | ||
| // Cancellable.swift | ||
| // RD-Core | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public protocol Cancellable { | ||
| func cancel() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // | ||
| // DreamSearchResuest.swift | ||
| // Data | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct DreamSearchResuest: Encodable { | ||
| let query: String | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // | ||
| // DreamSearchEntity.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public struct Records: Equatable, Identifiable { | ||
| public enum Genre: Int { | ||
| case comedy | ||
| case romance | ||
| case action | ||
| case thriller | ||
| case mystery | ||
| case fear | ||
| case sf | ||
| case fantasy | ||
| case family | ||
| case etc | ||
| case none | ||
| } | ||
|
|
||
| public let id: String | ||
| public let dreamColor: Int? | ||
| public let emotion: Int? | ||
| public let date: String? | ||
| public let title: String? | ||
| public let genre: Genre? | ||
| } | ||
|
|
||
| public struct DreamSearchEntity: Equatable { | ||
| public let recordsCount: Int | ||
| public let records: [Records] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // | ||
| // DreamSearchQuery.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public struct DreamSearchQuery: Equatable { | ||
| public let query: String | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // DreamSearchRepository.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import RxSwift | ||
| import RD_Core | ||
|
|
||
| public protocol DreamSearchRepository { | ||
| @discardableResult | ||
| func fetchDreamSearchList(query: DreamSearchQuery, | ||
| completion: @escaping(Result<DreamSearchEntity, Error>) -> Void) -> Cancellable? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // | ||
| // DreamSearchUseCase.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import RD_Core | ||
|
|
||
| public protocol DreamSearchUseCase { | ||
| func execute(requestValue: DreamSearchUseCaseRequestValue, | ||
| completion: @escaping (Result<DreamSearchEntity, Error>) -> Void) -> Cancellable? | ||
| } | ||
|
|
||
| public final class DefaultDreamSearchUseCase: DreamSearchUseCase { | ||
|
|
||
| private let dreamSearchRepository: DreamSearchRepository | ||
|
|
||
| init(dreamSearchRepository: DreamSearchRepository) { | ||
| self.dreamSearchRepository = dreamSearchRepository | ||
| } | ||
|
|
||
| public func execute(requestValue: DreamSearchUseCaseRequestValue, | ||
| completion: @escaping (Result<DreamSearchEntity, Error>) -> Void) -> Cancellable? { | ||
| return dreamSearchRepository.fetchDreamSearchList(query: requestValue.query) { result in | ||
| completion(result) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public struct DreamSearchUseCaseRequestValue { | ||
| let query: DreamSearchQuery | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // UseCase.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import RD_Core | ||
|
|
||
| public protocol UseCase { | ||
| @discardableResult | ||
| func start() -> Cancellable? | ||
| } | ||
|
Comment on lines
+13
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. start 메서드가 서버통신을 위한 UseCase에만 특별하게 사용 될 수 있을 것 같은데, 네이밍이 조금 넓은 범위를 포함하게 되는 것 같아요... 그리고 start 메서드는 하나의 기능만 가지고 있는 UseCase에 사용될 수 있을 것 같은데 어떤 식으로 사용하실 예정인가요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하! 레포지토리 인터페이스만으로는 부족한 걸까요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저 부분에서만 의존성 역전이 일어나는 것이기 때문에 따로 만들었던 것인데요...! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // | ||
| // DreamSearchResponse.swift | ||
| // RD-Network | ||
| // | ||
| // Created by 정은희 on 2022/11/08. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public struct DreamSearchResponse: Decodable { | ||
| public let query: String | ||
| public let results: [DreamSearchResult] | ||
| } | ||
|
|
||
| public extension DreamSearchResponse { | ||
| struct DreamSearchResult: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case recordsCount = "records_count" | ||
| case records | ||
| } | ||
|
|
||
| public let recordsCount: Int | ||
| public let records: [Records] | ||
| } | ||
|
|
||
| struct Records: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case id = "_id" | ||
| case dreamColor = "dream_color" | ||
| case emotion, date, title, genre | ||
| } | ||
| public enum Genre: Int, Decodable { | ||
| case comedy | ||
| case romance | ||
| case action | ||
| case thriller | ||
| case mystery | ||
| case fear | ||
| case sf | ||
| case fantasy | ||
| case family | ||
| case etc | ||
| case none | ||
| } | ||
|
|
||
| public let id: String? | ||
| public let dreamColor: Int? | ||
| public let emotion: Int? | ||
| public let date: String? | ||
| public let title: String? | ||
| public let genre: Genre? | ||
| } | ||
| } |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍