Skip to content
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

Feature/enroll view model #79

Merged
merged 26 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
14b2a3f
[feat] DayNamePickerView의 viewmodel 작성
jinwoong16 Nov 30, 2022
3a78b81
[feat] EnrollViewController의 서브뷰들을 관장하는 viewmodel 작성
jinwoong16 Nov 30, 2022
f93ef4f
[feat] DayNamePickerView 로직 변경
jinwoong16 Nov 30, 2022
5b38afb
[feat] EnrollViewController 로직 변경
jinwoong16 Nov 30, 2022
8836add
Merge branch 'develop' into feature/EnrollViewModel
jinwoong16 Dec 5, 2022
5f9a456
[refactor] index 로직 변경
jinwoong16 Dec 5, 2022
064dfa9
[refactor] PlanDatePickerView의 bind 메서드 제거
jinwoong16 Dec 5, 2022
a247094
[refactor] QuantityView의 bind 메서드 제거
jinwoong16 Dec 5, 2022
1a4420b
[refactor] ViewModel의 로직 변경 (삭제예정)
jinwoong16 Dec 5, 2022
3587b28
[feat] EnrollViewModel transform 메서드 작성
jinwoong16 Dec 5, 2022
e40e374
[feat] EnrollViewController bind메서드 구현
jinwoong16 Dec 5, 2022
42c7092
[chore] pbx
jinwoong16 Dec 5, 2022
03d0474
[refactor] DayNamePickerView bind 메서드와 viewmodel 삭제
jinwoong16 Dec 5, 2022
83ba2d7
[refactor] ViewModel 통합
jinwoong16 Dec 5, 2022
aa29c19
[refactor] EnrollViewController bind메서드 추가 작성
jinwoong16 Dec 5, 2022
a38eed5
[chore] pbx
jinwoong16 Dec 5, 2022
f8c4e1e
[feat] EnrollUseCase protocol 정의
jinwoong16 Dec 5, 2022
8bf4c22
[feat] Enroll use case 구현체 작성
jinwoong16 Dec 5, 2022
c8eabd1
[feat] DI 생성
jinwoong16 Dec 5, 2022
500324d
[refactor] EnrollViewController를 DIContainer를 통하여 생성
jinwoong16 Dec 5, 2022
edf891d
[feat] EnrollViewModel 동작 구현
jinwoong16 Dec 5, 2022
a81e49a
[feat] 퀘스트 등록 액션의 결과 확인
jinwoong16 Dec 5, 2022
259f54e
[refactor] bind메서드에서 output을 계산하는 부분 리팩터
jinwoong16 Dec 5, 2022
a4860be
[refactor] bind메서드에서 output을 계산하는 부분 리팩터
jinwoong16 Dec 5, 2022
b6c348b
Merge branch 'feature/EnrollViewModel' of https://github.com/boostcam…
jinwoong16 Dec 5, 2022
8760332
Merge branch 'develop' into feature/EnrollViewModel
jinwoong16 Dec 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {
Copy link
Member

Choose a reason for hiding this comment

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

아까 말씀하신 방법으로 바꾸신 거 확인했습니다!

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