Skip to content

Commit

Permalink
Merge pull request #79 from boostcampwm-2022/feature/EnrollViewModel
Browse files Browse the repository at this point in the history
Feature/enroll view model
  • Loading branch information
jinwoong16 committed Dec 6, 2022
2 parents 45ecf32 + 8760332 commit 9469d49
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 60 deletions.
12 changes: 12 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
3449AD5B2922164B00B87619 /* Quest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5A2922164B00B87619 /* Quest.swift */; };
3449AD5D2922197000B87619 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5C2922197000B87619 /* User.swift */; };
3449AD6029222B3900B87619 /* UserInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5F29222B3900B87619 /* UserInfoCell.swift */; };
344A459A293DC495007A3D37 /* EnrollUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 344A4599293DC495007A3D37 /* EnrollUseCase.swift */; };
345687F42937329E00CA51E3 /* EnrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F32937329E00CA51E3 /* EnrollViewController.swift */; };
345687F62937430200CA51E3 /* PlanDatePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F52937430200CA51E3 /* PlanDatePickerView.swift */; };
345687F829374D2500CA51E3 /* DayNamePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F729374D2500CA51E3 /* DayNamePickerView.swift */; };
345687FA2937815900CA51E3 /* QuantityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F92937815900CA51E3 /* QuantityView.swift */; };
345687FE29378AB900CA51E3 /* EnrollViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687FD29378AB900CA51E3 /* EnrollViewModel.swift */; };
34642AB62925D9E40052FA0E /* UserInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34642AB52925D9E40052FA0E /* UserInfoView.swift */; };
347D258B292C60F40038FCA2 /* StatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347D258A292C60F40038FCA2 /* StatusView.swift */; };
347D258D292C6E220038FCA2 /* MessageBubble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347D258C292C6E220038FCA2 /* MessageBubble.swift */; };
Expand Down Expand Up @@ -103,6 +105,7 @@
34EE0C662935FD7D002BEC23 /* BrowseItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3499552629235D1E007AB99E /* BrowseItemViewModel.swift */; };
34EE6EB72924C674005AF583 /* QuestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE6EB62924C674005AF583 /* QuestView.swift */; };
34EE6EB92924CAA1005AF583 /* QuestViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE6EB82924CAA1005AF583 /* QuestViewModel.swift */; };
34FCD366293DE62700E0DC8A /* DefaultEnrollUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34FCD365293DE62700E0DC8A /* DefaultEnrollUseCase.swift */; };
34FEFB992935EA6D00954A40 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 34FEFB982935EA6D00954A40 /* Kingfisher */; };
34FF6C5A292B86F8002AFD4D /* SnapKit-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 34FF6C46292B8014002AFD4D /* SnapKit-Dynamic */; };
34FF6C5D292B8B27002AFD4D /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 34FF6C5C292B8B27002AFD4D /* RxCocoa */; };
Expand Down Expand Up @@ -211,10 +214,12 @@
3449AD5A2922164B00B87619 /* Quest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Quest.swift; sourceTree = "<group>"; };
3449AD5C2922197000B87619 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
3449AD5F29222B3900B87619 /* UserInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoCell.swift; sourceTree = "<group>"; };
344A4599293DC495007A3D37 /* EnrollUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnrollUseCase.swift; sourceTree = "<group>"; };
345687F32937329E00CA51E3 /* EnrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnrollViewController.swift; sourceTree = "<group>"; };
345687F52937430200CA51E3 /* PlanDatePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanDatePickerView.swift; sourceTree = "<group>"; };
345687F729374D2500CA51E3 /* DayNamePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayNamePickerView.swift; sourceTree = "<group>"; };
345687F92937815900CA51E3 /* QuantityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuantityView.swift; sourceTree = "<group>"; };
345687FD29378AB900CA51E3 /* EnrollViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnrollViewModel.swift; sourceTree = "<group>"; };
34642AB52925D9E40052FA0E /* UserInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserInfoView.swift; sourceTree = "<group>"; };
347D258A292C60F40038FCA2 /* StatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusView.swift; sourceTree = "<group>"; };
347D258C292C6E220038FCA2 /* MessageBubble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBubble.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -260,6 +265,7 @@
34EE0C632935FD6B002BEC23 /* BrowseViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewModelTests.swift; sourceTree = "<group>"; };
34EE6EB62924C674005AF583 /* QuestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestView.swift; sourceTree = "<group>"; };
34EE6EB82924CAA1005AF583 /* QuestViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestViewModel.swift; sourceTree = "<group>"; };
34FCD365293DE62700E0DC8A /* DefaultEnrollUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultEnrollUseCase.swift; sourceTree = "<group>"; };
9B1CFB3E292B585700CCE97A /* QuestDTO+Mapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "QuestDTO+Mapping.swift"; sourceTree = "<group>"; };
9BD8CCF22935BC0D00E6EA2F /* DefaultBrowseRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBrowseRepository.swift; sourceTree = "<group>"; };
9BD8CCF42935C38300E6EA2F /* UserDTO+Mapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDTO+Mapping.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -376,6 +382,7 @@
children = (
3416FC86292B54BF00B504C5 /* Protocols */,
3416FC89292B560800B504C5 /* DefaultQuestUseCase.swift */,
34FCD365293DE62700E0DC8A /* DefaultEnrollUseCase.swift */,
);
path = Home;
sourceTree = "<group>";
Expand All @@ -384,6 +391,7 @@
isa = PBXGroup;
children = (
3416FC87292B54DB00B504C5 /* QuestUseCase.swift */,
344A4599293DC495007A3D37 /* EnrollUseCase.swift */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -690,6 +698,7 @@
isa = PBXGroup;
children = (
34EE6EB82924CAA1005AF583 /* QuestViewModel.swift */,
345687FD29378AB900CA51E3 /* EnrollViewModel.swift */,
B5115452292CD07100FDBD22 /* CalendarViewModel.swift */,
);
path = ViewModel;
Expand Down Expand Up @@ -1147,6 +1156,7 @@
34D8360129359C8A001DE9DF /* BrowseRepository.swift in Sources */,
34091552292DE9D1007873A8 /* QuestEntity.swift in Sources */,
342830F6292E1ACA00AE811B /* PlainItemViewModel.swift in Sources */,
345687FE29378AB900CA51E3 /* EnrollViewModel.swift in Sources */,
34A529D129247880001BAD34 /* Coordinator.swift in Sources */,
34113BEB2934A3B200AB4919 /* LoginViewController.swift in Sources */,
340A724929348B1B00B26AA6 /* AuthUseCase.swift in Sources */,
Expand Down Expand Up @@ -1228,8 +1238,10 @@
A51F01D029233C510031ECA2 /* UserInfoEntity+Mapping.swift in Sources */,
3499552B29236041007AB99E /* BrowseViewModel.swift in Sources */,
34113BED2934BD3D00AB4919 /* TextFieldForm.swift in Sources */,
344A459A293DC495007A3D37 /* EnrollUseCase.swift in Sources */,
3449AD5B2922164B00B87619 /* Quest.swift in Sources */,
34283101292E2D7A00AE811B /* ToggleItemViewModel.swift in Sources */,
34FCD366293DE62700E0DC8A /* DefaultEnrollUseCase.swift in Sources */,
A5AC96E829223F27003B7637 /* RealmQuestsStorage.swift in Sources */,
345687F829374D2500CA51E3 /* DayNamePickerView.swift in Sources */,
349955122923220E007AB99E /* SwiftUIPreview.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,28 @@ final class HomeSceneDIContainer {
return DefaultQuestUseCase(questsRepository: makeQuestsRepository())
}

func makeEnrollUseCase() -> EnrollUseCase {
return DefaultEnrollUseCase(questsRepository: makeQuestsRepository())
}

// MARK: - View Models
func makeQuestViewModel() -> QuestViewModel {
return QuestViewModel(questUseCase: makeQuestUseCase())
}

func makeEnrollViewModel() -> EnrollViewModel {
return EnrollViewModel(enrollUseCase: makeEnrollUseCase())
}

// MARK: - View Controller
func makeHomeViewController() -> HomeViewController {
return HomeViewController.create(with: makeQuestViewModel())
}

func makeEnrollViewController() -> EnrollViewController {
return EnrollViewController.create(with: makeEnrollViewModel())
}

// MARK: - Flow
func makeHomeCoordinator(navigationController: UINavigationController,
homeSceneDIContainer: HomeSceneDIContainer) -> HomeCoordinator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DefaultEnrollUseCase.swift
// DailyQuest
//
// Created by jinwoong Kim on 2022/12/05.
//

import Foundation

import RxSwift

final class DefaultEnrollUseCase {
private let questsRepository: QuestsRepository

init(questsRepository: QuestsRepository) {
self.questsRepository = questsRepository
}
}

extension DefaultEnrollUseCase: EnrollUseCase {
func save(with quests: [Quest]) -> Observable<Bool> {
return questsRepository
.save(with: quests)
.map { _ in
true
}
.catchAndReturn(false)
.asObservable()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// EnrollUseCase.swift
// DailyQuest
//
// Created by jinwoong Kim on 2022/12/05.
//

import Foundation

import RxSwift

protocol EnrollUseCase {
func save(with quests: [Quest]) -> Observable<Bool>
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ final class DefaultHomeCoordinator: HomeCoordinator {
}

func showAddQuestFlow() {
let addQuestsViewController = EnrollViewController()
navigationController.present(addQuestsViewController, animated: true)
let enrollViewController = homeSceneDIContainer.makeEnrollViewController()
navigationController.present(enrollViewController, animated: true)
}

func showAddFriendsFlow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import RxSwift
import RxCocoa

final class DayNamePickerView: UIStackView {
private var selectedDay = [0: false, 1: false, 2: false, 3: false, 4: false, 5: false, 6: false]
private(set) var selectedDayObservable = BehaviorRelay<[Int: Bool]>(value: [0: false, 1: false, 2: false, 3: false, 4: false, 5: false, 6: false])

private var disposableBag = DisposeBag()

private lazy var buttons: [UIButton] = {
private(set) lazy var buttons: [UIButton] = {
let days = ["S", "M", "T", "W", "T", "F", "S"]

return days.map { day in
Expand All @@ -35,8 +30,6 @@ final class DayNamePickerView: UIStackView {
super.init(frame: frame)

configureUI()

bind()
}

required init(coder: NSCoder) {
Expand All @@ -52,26 +45,5 @@ final class DayNamePickerView: UIStackView {
self.addArrangedSubview(button)
}
}

private func bind() {
let taps = buttons.enumerated().map { index, button in
button.rx.tap.map { _ in index }
}

Observable.from(taps).merge()
.withUnretained(self)
.subscribe(onNext: { (owner, value) in
owner.selectedDay[value]?.toggle()
owner.selectedDayObservable.accept(owner.selectedDay)

guard let isSelected = owner.selectedDay[value] else { return }
if isSelected {
owner.buttons[value].configuration?.baseBackgroundColor = .maxYellow
} else {
owner.buttons[value].configuration?.baseBackgroundColor = .maxLightYellow
}
})
.disposed(by: disposableBag)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import RxSwift
import SnapKit

final class PlanDatePickerView: UIView {
private(set) var date = PublishSubject<Date>()
private var disposableBag = DisposeBag()

private lazy var titleLabel: UILabel = {
Expand All @@ -22,7 +21,7 @@ final class PlanDatePickerView: UIView {
return titleLabel
}()

private lazy var datePicker: UIDatePicker = {
private(set) lazy var datePicker: UIDatePicker = {
let datePicker = UIDatePicker()
datePicker.datePickerMode = .date

Expand All @@ -33,8 +32,6 @@ final class PlanDatePickerView: UIView {
super.init(frame: frame)

configureUI()

bind()
}

required init?(coder: NSCoder) {
Expand All @@ -56,13 +53,4 @@ final class PlanDatePickerView: UIView {
make.edges.equalToSuperview().inset(15)
}
}

private func bind() {
datePicker
.rx
.controlEvent(.valueChanged)
.withLatestFrom(datePicker.rx.date)
.bind(to: date)
.disposed(by: disposableBag)
}
}
12 changes: 5 additions & 7 deletions DailyQuest/DailyQuest/Presentation/Home/View/QuantityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import UIKit

import RxSwift
import RxCocoa

final class QuantityView: UIView {

private lazy var titleLabel: UILabel = {
Expand All @@ -17,10 +20,11 @@ final class QuantityView: UIView {
return titleLabel
}()

private lazy var quantityField: UITextField = {
private(set) lazy var quantityField: UITextField = {
let quantityField = UITextField()
quantityField.textAlignment = .right
quantityField.placeholder = "0"
quantityField.keyboardType = .numberPad

return quantityField
}()
Expand All @@ -29,8 +33,6 @@ final class QuantityView: UIView {
super.init(frame: frame)

configureUI()

bind()
}

required init?(coder: NSCoder) {
Expand All @@ -53,8 +55,4 @@ final class QuantityView: UIView {
make.width.equalToSuperview().multipliedBy(0.3)
}
}

private func bind() {

}
}
Loading

0 comments on commit 9469d49

Please sign in to comment.