-
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 8 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 @@ | ||
| // | ||
| // DreamSearchResuestDTO.swift | ||
| // Data | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct DreamSearchResuestDTO: 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 | ||
| } | ||
|
Comment on lines
+12
to
+24
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. 👍 👍 |
||
|
|
||
| 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,17 @@ | ||
| // | ||
| // DreamSearchRepository.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import RxSwift | ||
|
|
||
| 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,38 @@ | ||
| // | ||
| // DreamSearchUseCase.swift | ||
| // DomainTests | ||
| // | ||
| // Created by 정은희 on 2022/11/09. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import RD_Core | ||
| import Domain | ||
|
|
||
| protocol DreamSearchUseCase { | ||
| func execute(requestValue: DreamSearchUseCaseRequestValue, | ||
| completion: @escaping (Result<DreamSearchQuery, Error>) -> Void) -> Cancellable? | ||
| } | ||
|
|
||
| //final class DefaultDreamSearchUseCase: DreamSearchUseCase { | ||
| // private let dreamSearchRepository: DreamSearchRepository | ||
| // | ||
| // init(dreamSearchRepository: DreamSearchRepository) { | ||
| // self.dreamSearchRepository = dreamSearchRepository | ||
| // } | ||
| // | ||
| // func execute(requestValue: DreamSearchUseCaseRequestValue, | ||
| // completion: @escaping (Result<DreamSearchEntity, Error>) -> Void) -> Cancellable? { | ||
| // | ||
|
||
| // return dreamSearchRepository.fetchDreamSearchList(query: requestValue.query, | ||
| // completion: { result in | ||
| // completion(result) | ||
| // }) | ||
| // } | ||
| //} | ||
|
|
||
| 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 @@ | ||
| // | ||
| // DreamSearchResponseDTO.swift | ||
| // RD-Network | ||
| // | ||
| // Created by 정은희 on 2022/11/08. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct DreamSearchResponseDTO: Decodable { | ||
|
||
| let query: String | ||
| let results: [DreamSearchResultDTO] | ||
| } | ||
|
|
||
| extension DreamSearchResponseDTO { | ||
| struct DreamSearchResultDTO: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case recordsCount = "records_count" | ||
| case records | ||
| } | ||
|
|
||
| let recordsCount: Int | ||
| let records: [Records] | ||
| } | ||
|
|
||
| struct Records: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case id = "_id" | ||
| case dreamColor = "dream_color" | ||
| case emotion, date, title, genre | ||
| } | ||
| enum GenreDTO: Int, Decodable { | ||
| case comedy | ||
| case romance | ||
| case action | ||
| case thriller | ||
| case mystery | ||
| case fear | ||
| case sf | ||
| case fantasy | ||
| case family | ||
| case etc | ||
| case none | ||
| } | ||
|
|
||
| let id: String? | ||
| let dreamColor: Int? | ||
| let emotion: Int? | ||
| let date: String? | ||
| let title: String? | ||
| let genre: GenreDTO? | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // | ||
| // SearchRouter.swift | ||
| // RD-Network | ||
| // | ||
| // Created by 정은희 on 2022/11/08. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import Alamofire | ||
|
|
||
| enum SearchRouter { | ||
| case searchRecord(keyword: String) | ||
| } | ||
|
|
||
| extension SearchRouter: BaseRouter { | ||
| var method: HTTPMethod { | ||
| switch self { | ||
| case .searchRecord: | ||
| return .get | ||
| } | ||
| } | ||
|
|
||
| var path: String { | ||
| switch self { | ||
| case .searchRecord: | ||
| return "/record/storage/search" | ||
| } | ||
| } | ||
|
|
||
| var parameters: RequestParams { | ||
| switch self { | ||
| case .searchRecord(let keyword): | ||
| let query: [String: Any] = [ | ||
| "keyword": keyword | ||
| ] | ||
| return .query(query) | ||
| default: | ||
| return .requestPlain | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // | ||
| // SearchService.swift | ||
| // RD-Network | ||
| // | ||
| // Created by 정은희 on 2022/11/08. | ||
| // Copyright © 2022 RecorDream. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import Alamofire | ||
|
|
||
| public protocol SearchService { | ||
| func searchDreamRecords(keyword: String) throws -> DreamSearchResponse | ||
| } | ||
|
|
||
| public class DefaultSearchService: BaseService { | ||
| public static let shared = DefaultSearchService() | ||
|
|
||
| private override init() { } | ||
| } | ||
|
|
||
| extension DefaultSearchService: SearchService { | ||
| public func searchDreamRecords(keyword: String) throws -> DreamSearchResponse { | ||
| AFManager.request(SearchRouter.searchRecord(keyword: keyword)) | ||
| .responseData { response in | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
||


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.
요부분은 저번에 수연이가 얘기한 것처럼 DTO는 제거해도 될 것 같아요!
@Suyeon9911 그런 의도가 맞을까요?
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.
@L-j-h-c 네엡 ~~!!