Skip to content

Commit

Permalink
[refactor] #331 첫번째, 두번째 감정 남길 때 공통 코드 정리 및 상속
Browse files Browse the repository at this point in the history
  • Loading branch information
gom1n committed Jun 6, 2023
1 parent 0dc59f8 commit 7f11a77
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 187 deletions.
6 changes: 3 additions & 3 deletions POME/Data/Repository/RecordRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class RecordRepository: RecordRepositoryInterface{
return observable
}

func generateRecord(requestValue: GenerateRecordRequestModel) -> Observable<Int>{
let observable = Observable<Int>.create { observer -> Disposable in
func generateRecord(requestValue: GenerateRecordRequestModel) -> Observable<BaseResponseStatus>{
let observable = Observable<BaseResponseStatus>.create { observer -> Disposable in
let requestReference: () = RecordService.shared.generateRecord(request: requestValue){ response in
switch response {
case .success:
observer.onNext(200)
observer.onNext(.success)
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RxSwift
protocol RecordRepositoryInterface{
func getRecordInReview(goalId: Int, requestValue: GetRecordInReviewRequestModel) -> Observable<PageableResponseModel<RecordResponseModel>>
func modifyRecord(id: Int, requestValue: RecordDTO) -> Observable<RecordResponseModel>
func generateRecord(requestValue: GenerateRecordRequestModel) -> Observable<Int>
func generateRecord(requestValue: GenerateRecordRequestModel) -> Observable<BaseResponseStatus>
func deleteRecord(requestValue: DeleteRecordRequestModel) -> Observable<BaseResponseStatus>
func getRecordsOfGoalInRecordTab(id: Int, pageable: PageableModel) -> Observable<PageableResponseModel<RecordResponseModel>>
func getNoSecondEmotionRecords(id: Int) -> Observable<PageableResponseModel<RecordResponseModel>>
Expand Down
4 changes: 2 additions & 2 deletions POME/Domain/UseCase/Record/GenerateRecordUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct GenerateRecordRequestModel: Encodable{
}

protocol GenerateRecordUseCaseInterface {
func execute(requestValue: GenerateRecordRequestModel) -> Observable<Int>
func execute(requestValue: GenerateRecordRequestModel) -> Observable<BaseResponseStatus>
}

final class GenerateRecordUseCase: GenerateRecordUseCaseInterface {
Expand All @@ -28,7 +28,7 @@ final class GenerateRecordUseCase: GenerateRecordUseCaseInterface {
self.recordRepository = recordRepository
}

func execute(requestValue: GenerateRecordRequestModel) -> Observable<Int> {
func execute(requestValue: GenerateRecordRequestModel) -> Observable<BaseResponseStatus> {
return recordRepository.generateRecord(requestValue: requestValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ final class GenerateRecordViewController: Recordable{
viewModel.controlEvent(mainView.completeButton.rx.tap)
.drive(onNext: { [weak self] record in
if let record = record {
self?.navigationController?.pushViewController(RecordFirstEmotionViewController(record: record), animated: true)
let vc = SelectEmotionViewController(type: .First, record: record)
self?.navigationController?.pushViewController(vc, animated: true)
}
}).disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
////
//// RegisterFirstEmotionViewController.swift
//// POME
////
//// Created by 박소윤 on 2023/03/30.
////
//
// RegisterFirstEmotionViewController.swift
// POME
//import Foundation
//import RxSwift
//import RxCocoa
//
// Created by 박소윤 on 2023/03/30.
//final class RecordFirstEmotionViewController: BaseViewController{
//
// private let record: RecordDTO
//
// init(record: RecordDTO){
// self.record = record
// super.init(nibName: nil, bundle: nil)
// }
//
// private typealias emotionViewType = SelectEmotionView.EmotionElementView
//
// private let mainView = SelectEmotionView(type: .First)
// private let viewModel = RecordFirstEmotionViewModel()
//
//
// required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
// override func style(){
// super.style()
// setEtcButton(title: "닫기")
// }
//
// override func layout(){
// super.layout()
// view.addSubview(mainView)
// mainView.snp.makeConstraints{
// $0.top.equalTo(navigationView.snp.bottom)
// $0.leading.trailing.bottom.equalToSuperview()
// }
// }
//
// override func bind(){
//
// let input = RecordFirstEmotionViewModel.Input(record: record,
// happyEmotionSelect: mainView.happyEmotionView.rx.tapGesture().asObservable(),
// whatEmotionSelect: mainView.whatEmotionView.rx.tapGesture().asObservable(),
// sadEmotionSelect: mainView.sadEmotionView.rx.tapGesture().asObservable(),
// ctaButtonTap: mainView.completeButton.rx.tap)
//
// let output = viewModel.transform(input: input)
//
// output.deselectEmotion
// .drive(onNext: { [weak self] emotionTag in
// if let emotion = EmotionTag(tagValue: emotionTag), let emotionView = self?.mainView.emotionStackView.viewWithTag(emotion.tagBinding) as? emotionViewType{
// emotionView.changeDeselectState()
// }
// }).disposed(by: disposeBag)
//
// output.selectEmotion
// .drive(onNext: { [weak self] emotionTag in
// if let emotion = EmotionTag(tagValue: emotionTag), let emotionView = self?.mainView.emotionStackView.viewWithTag(emotion.tagBinding) as? emotionViewType{
// emotionView.changeSelectState()
// }
// }).disposed(by: disposeBag)
//

import Foundation
import RxSwift
import RxCocoa

final class RecordFirstEmotionViewController: BaseViewController{

private let record: RecordDTO

init(record: RecordDTO){
self.record = record
super.init(nibName: nil, bundle: nil)
}

private typealias emotionViewType = SelectEmotionView.EmotionElementView

private let mainView = SelectEmotionView(type: .First)
private let viewModel = RecordFirstEmotionViewModel()


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func style(){
super.style()
setEtcButton(title: "닫기")
}

override func layout(){
super.layout()
view.addSubview(mainView)
mainView.snp.makeConstraints{
$0.top.equalTo(navigationView.snp.bottom)
$0.leading.trailing.bottom.equalToSuperview()
}
}

override func bind(){

let input = RecordFirstEmotionViewModel.Input(record: record,
happyEmotionSelect: mainView.happyEmotionView.rx.tapGesture().asObservable(),
whatEmotionSelect: mainView.whatEmotionView.rx.tapGesture().asObservable(),
sadEmotionSelect: mainView.sadEmotionView.rx.tapGesture().asObservable(),
ctaButtonTap: mainView.completeButton.rx.tap)

let output = viewModel.transform(input: input)

output.deselectEmotion
.drive(onNext: { [weak self] emotionTag in
if let emotion = EmotionTag(tagValue: emotionTag), let emotionView = self?.mainView.emotionStackView.viewWithTag(emotion.tagBinding) as? emotionViewType{
emotionView.changeDeselectState()
}
}).disposed(by: disposeBag)

output.selectEmotion
.drive(onNext: { [weak self] emotionTag in
if let emotion = EmotionTag(tagValue: emotionTag), let emotionView = self?.mainView.emotionStackView.viewWithTag(emotion.tagBinding) as? emotionViewType{
emotionView.changeSelectState()
}
}).disposed(by: disposeBag)

output.ctaButtonActivate
.drive(mainView.completeButton.rx.isActivate)
.disposed(by: disposeBag)

output.registerStatusCode
.drive(onNext: { [weak self] statusCode in
if(statusCode == 200){
self?.navigationController?.pushViewController(RegisterSuccessViewController(type: .consume), animated: true)
}
}).disposed(by: disposeBag)

etcButton.rx.tap
.bind{ [weak self] in
self?.closeButtonDidClicked()
}.disposed(by: disposeBag)
}

private func closeButtonDidClicked(){
ImageAlert.quitRecord.generateAndShow(in: self).do{
$0.completion = { [weak self] in
self?.navigationController?.popToRootViewController(animated: true)
}
}
}
}
// output.ctaButtonActivate
// .drive(mainView.completeButton.rx.isActivate)
// .disposed(by: disposeBag)
//
// output.registerStatusCode
// .drive(onNext: { [weak self] statusCode in
// if(statusCode == 200){
// self?.navigationController?.pushViewController(RegisterSuccessViewController(type: .consume), animated: true)
// }
// }).disposed(by: disposeBag)
//
// etcButton.rx.tap
// .bind{ [weak self] in
// self?.closeButtonDidClicked()
// }.disposed(by: disposeBag)
// }
//
// private func closeButtonDidClicked(){
// ImageAlert.quitRecord.generateAndShow(in: self).do{
// $0.completion = { [weak self] in
// self?.navigationController?.popToRootViewController(animated: true)
// }
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,27 @@ class SelectEmotionViewController: BaseViewController{

private typealias emotionViewType = SelectEmotionView.EmotionElementView

init(type: SelectEmotionType, recordId: Int){
// First Emotion -> recordDTO
init(type: SelectEmotionType, record: RecordDTO){
self.type = type
self.recordId = recordId
self.record = RecordDTO(goalId: DEFAULT_INT, useComment: DEFAULT_STRING, useDate: DEFAULT_STRING, usePrice: DEFAULT_INT)
self.recordId = DEFAULT_INT
self.record = record

mainView = SelectEmotionView(type: type)
viewModel = PostSecondEmotionViewModel()
viewModel.recordId = recordId
viewModel = RecordFirstEmotionViewModel()
viewModel.record = record

super.init(nibName: nil, bundle: nil)
}
init(type: SelectEmotionType, record: RecordDTO){
// Second Emotion -> recordId
init(type: SelectEmotionType, recordId: Int){
self.type = type
self.recordId = DEFAULT_INT
self.record = record
self.recordId = recordId
self.record = RecordDTO(goalId: DEFAULT_INT, useComment: DEFAULT_STRING, useDate: DEFAULT_STRING, usePrice: DEFAULT_INT)

mainView = SelectEmotionView(type: type)
viewModel = SelectEmotionViewModel()
viewModel.record = record
viewModel = PostSecondEmotionViewModel()
viewModel.recordId = recordId

super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -90,6 +92,13 @@ class SelectEmotionViewController: BaseViewController{
.drive(mainView.completeButton.rx.isActivate)
.disposed(by: disposeBag)

registerCompletion(output)

}

// 첫 번째 감정을 남긴 이후 -> generateRecord 완료
// 두 번째 감정을 남긴 이후 -> registerSecondEmotion 완료
private func registerCompletion(_ output: SelectEmotionViewModel.Output) {
switch type {
case .First:
output.registerStatusCode.drive(onNext: { [weak self] status in
Expand All @@ -111,9 +120,8 @@ class SelectEmotionViewController: BaseViewController{
}
}).disposed(by: disposeBag)
}


}

private func closeButtonDidClicked(){
if type == .First {
ImageAlert.quitRecord.generateAndShow(in: self).do{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import RxSwift
import RxCocoa
import RxGesture

/*
SelectEmotionViewModel + recordId
*/

final class PostSecondEmotionViewModel: SelectEmotionViewModel {

Expand Down
Loading

0 comments on commit 7f11a77

Please sign in to comment.