Skip to content
Merged
13 changes: 13 additions & 0 deletions RecorDream-iOS/Projects/Core/Sources/Protocols/Cancellable.swift
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
}
Comment on lines +12 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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,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
}
16 changes: 16 additions & 0 deletions RecorDream-iOS/Projects/Domain/Sources/UseCases/UseCase.swift
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start 메서드가 서버통신을 위한 UseCase에만 특별하게 사용 될 수 있을 것 같은데, 네이밍이 조금 넓은 범위를 포함하게 되는 것 같아요... 그리고 start 메서드는 하나의 기능만 가지고 있는 UseCase에 사용될 수 있을 것 같은데 어떤 식으로 사용하실 예정인가요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유즈케이스에서 필요한 레포지터리 내의 데이터를 패치해올 때(동그라미 부분을 구현할 때) 사용할 예정입니다!
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하! 레포지토리 인터페이스만으로는 부족한 걸까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import Alamofire

enum RecordRouter {
case writeRecord(title: String, date: String, content: String, emotion: Int, genre: [Int], note: String?, voice: URL?)
case searchRecord(keyword: String)
}

extension RecordRouter: BaseRouter {
var method: HTTPMethod {
switch self {
case .writeRecord:
return .post
case .searchRecord:
return .get
default: return .get
}
}
Expand All @@ -27,6 +30,8 @@ extension RecordRouter: BaseRouter {
switch self {
case .writeRecord:
return "/record"
case .searchRecord:
return "/record/storage/search"
default: return ""
}
}
Expand All @@ -42,6 +47,11 @@ extension RecordRouter: BaseRouter {
"genre": genre
]
return .requestBody(requestBody)
case .searchRecord(let keyword):
let query: [String: Any] = [
"keyword": keyword
]
return .query(query)
default: return .requestPlain
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import RxSwift

public protocol RecordService {
func writeDreamRecord(title: String, date: String, content: String, emotion: Int, genre: [Int], note: String?, voice: URL?) -> Observable<DreamWriteResponse?>
func searchDreamRecord(query: String) -> Observable<DreamSearchResponse?>
}

public class DefaultRecordService: BaseService {
Expand All @@ -21,8 +22,11 @@ public class DefaultRecordService: BaseService {
private override init() {}
}

extension DefaultRecordService: RecordService {
public func writeDreamRecord(title: String, date: String, content: String, emotion: Int, genre: [Int], note: String?, voice: URL?) -> RxSwift.Observable<DreamWriteResponse?> {
requestObjectInRx(RecordRouter.writeRecord(title: title, date: date, content: content, emotion: emotion, genre: genre, note: note, voice: voice))
}
}
//extension DefaultRecordService: RecordService {
// public func writeDreamRecord(title: String, date: String, content: String, emotion: Int, genre: [Int], note: String?, voice: URL?) -> RxSwift.Observable<DreamWriteResponse?> {
// requestObjectInRx(RecordRouter.writeRecord(title: title, date: date, content: content, emotion: emotion, genre: genre, note: note, voice: voice))
// }
// public func searchDreamRecord(query: String) -> Observable<DreamSearchResponse?> {
// requestObject(RecordRouter.searchRecord(keyword: query), type: DreamSearchResponse.self, decodingMode: .general, completion: <#T##(NetworkResult<Any>) -> Void#>)
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import HeeKit

public protocol DreamSearhControllable: Presentable, Reusable { }

public class DreamSearchCollectionViewCell: UICollectionReusableView, DreamSearhControllable {
public class DreamSearchCollectionViewCell: UICollectionViewCell, DreamSearhControllable {
// MARK: - View Life Cycle
override init(frame: CGRect) {
super.init(frame: frame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

import RD_DSKit

final class DreamSearchBottomCVC: DreamSearchCollectionViewCell {
final class DreamSearchBottomCVC: UICollectionReusableView {
private lazy var rogoImageView: UIImageView = {
let iv = UIImageView()
iv.image = RDDSKitAsset.Images.rdHomeLogo.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import UIKit

import RD_DSKit

final class DreamSearchCountCVC: DreamSearchCollectionViewCell {
final class DreamSearchCountCVC: UICollectionReusableView {
private lazy var countLabel: UILabel = {
let lb = UILabel()
lb.text = "4개의 기록" // ✅
lb.textColor = RDDSKitColors.Color.white
lb.font = RDDSKitFontFamily.Pretendard.semiBold.font(size: 12)
return lb
Expand Down Expand Up @@ -41,3 +40,9 @@ final class DreamSearchCountCVC: DreamSearchCollectionViewCell {
}
}
}

extension DreamSearchCountCVC {
func configureCell(viewModel: DreamSearchResultViewModel) {
self.countLabel.text = "\(viewModel.recordsCount)개의 기록"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ final class DreamSearchExistCVC: DreamSearchCollectionViewCell {
}
}
}

extension DreamSearchExistCVC {
func configureCell(viewModel: DreamSearchResultViewModel) {
// self.backgroundImageView
// self.genreView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit


@available(iOS 16.0, *)
extension DreamSearchVC {
func layout() -> UICollectionViewLayout {
return UICollectionViewCompositionalLayout { [weak self] sectionNumber, environment -> NSCollectionLayoutSection? in
Expand All @@ -36,7 +35,7 @@ extension DreamSearchVC {
heightDimension: .estimated(88.adjustedHeight)
)
let group = NSCollectionLayoutGroup.vertical(
layoutSize: groupSize, repeatingSubitem: item, count: 1)
layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
let sectionFooter = self.createSectionFooter()
section.orthogonalScrollingBehavior = .continuous
Expand All @@ -57,7 +56,7 @@ extension DreamSearchVC {
heightDimension: .fractionalHeight(1.0)
)
let group = NSCollectionLayoutGroup.vertical(
layoutSize: groupSize, repeatingSubitem: item, count: 1
layoutSize: groupSize, subitems: [item]
)
let sectionFooter = self.createSectionFooter()
let section = NSCollectionLayoutSection(group: group)
Expand All @@ -66,7 +65,6 @@ extension DreamSearchVC {
section.contentInsets = .init(
top: 208, leading: 113, bottom: 282, trailing: 113
)

return section
}
private func createSectionFooter() -> NSCollectionLayoutBoundarySupplementaryItem {
Expand Down
Loading