Skip to content

Commit

Permalink
[refactor] #331 두번째 감정 남기기
Browse files Browse the repository at this point in the history
  • Loading branch information
gom1n committed Jun 5, 2023
1 parent 8dcfceb commit 9a220b1
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 99 deletions.
16 changes: 12 additions & 4 deletions POME.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
230FD70F298626FA0043F6DA /* StatusResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 230FD70E298626FA0043F6DA /* StatusResponseModel.swift */; };
230FD7112986279A0043F6DA /* GoalResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 230FD7102986279A0043F6DA /* GoalResponseModel.swift */; };
23115DD72A2D6F270024D6CF /* SelectEmotionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23115DD62A2D6F270024D6CF /* SelectEmotionView.swift */; };
23115DD92A2D763C0024D6CF /* PostSecondEmotionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23115DD82A2D763C0024D6CF /* PostSecondEmotionViewModel.swift */; };
23115DDB2A2D773F0024D6CF /* SelectSecondEmotionUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23115DDA2A2D773F0024D6CF /* SelectSecondEmotionUseCase.swift */; };
232B2BDF292B80EB00FFDF8B /* UILabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 232B2BDE292B80EB00FFDF8B /* UILabel.swift */; };
232B2BE1292B861F00FFDF8B /* TermDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 232B2BE0292B861F00FFDF8B /* TermDetailViewController.swift */; };
232C1C8A2990CCEA0087B81A /* DeleteUserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 232C1C892990CCEA0087B81A /* DeleteUserViewController.swift */; };
Expand Down Expand Up @@ -78,7 +80,7 @@
23ADE493292D3428003002D9 /* NotiTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ADE492292D3428003002D9 /* NotiTableViewCell.swift */; };
23ADE497292D3F0A003002D9 /* MypageProfileTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ADE496292D3F0A003002D9 /* MypageProfileTableViewCell.swift */; };
23ADE499292D405D003002D9 /* MypageGoalsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ADE498292D405C003002D9 /* MypageGoalsTableViewCell.swift */; };
23B3B7DC29319411008CB960 /* SecondEmotionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23B3B7DB29319411008CB960 /* SecondEmotionViewController.swift */; };
23B3B7DC29319411008CB960 /* PostSecondEmotionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23B3B7DB29319411008CB960 /* PostSecondEmotionViewController.swift */; };
23B3B7DF29319425008CB960 /* SecondEmotionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23B3B7DE29319425008CB960 /* SecondEmotionView.swift */; };
23B4FD4C293863620020AD40 /* AppLoginFlowUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23B4FD4B293863620020AD40 /* AppLoginFlowUITests.swift */; };
23D5107D2A23B32C007330DB /* RegisterProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23D5107C2A23B32C007330DB /* RegisterProfileViewModel.swift */; };
Expand Down Expand Up @@ -310,6 +312,8 @@
230FD70E298626FA0043F6DA /* StatusResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusResponseModel.swift; sourceTree = "<group>"; };
230FD7102986279A0043F6DA /* GoalResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalResponseModel.swift; sourceTree = "<group>"; };
23115DD62A2D6F270024D6CF /* SelectEmotionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectEmotionView.swift; sourceTree = "<group>"; };
23115DD82A2D763C0024D6CF /* PostSecondEmotionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostSecondEmotionViewModel.swift; sourceTree = "<group>"; };
23115DDA2A2D773F0024D6CF /* SelectSecondEmotionUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectSecondEmotionUseCase.swift; sourceTree = "<group>"; };
2323CBC8299E70A7005C177B /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
232B2BDE292B80EB00FFDF8B /* UILabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UILabel.swift; sourceTree = "<group>"; };
232B2BE0292B861F00FFDF8B /* TermDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermDetailViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -369,7 +373,7 @@
23ADE492292D3428003002D9 /* NotiTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotiTableViewCell.swift; sourceTree = "<group>"; };
23ADE496292D3F0A003002D9 /* MypageProfileTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MypageProfileTableViewCell.swift; sourceTree = "<group>"; };
23ADE498292D405C003002D9 /* MypageGoalsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MypageGoalsTableViewCell.swift; sourceTree = "<group>"; };
23B3B7DB29319411008CB960 /* SecondEmotionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondEmotionViewController.swift; sourceTree = "<group>"; };
23B3B7DB29319411008CB960 /* PostSecondEmotionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostSecondEmotionViewController.swift; sourceTree = "<group>"; };
23B3B7DE29319425008CB960 /* SecondEmotionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondEmotionView.swift; sourceTree = "<group>"; };
23B4FD4B293863620020AD40 /* AppLoginFlowUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLoginFlowUITests.swift; sourceTree = "<group>"; };
23D5107C2A23B32C007330DB /* RegisterProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterProfileViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -849,7 +853,7 @@
23B3B7DA29319402008CB960 /* SecondEmotion */ = {
isa = PBXGroup;
children = (
23B3B7DB29319411008CB960 /* SecondEmotionViewController.swift */,
23B3B7DB29319411008CB960 /* PostSecondEmotionViewController.swift */,
);
path = SecondEmotion;
sourceTree = "<group>";
Expand Down Expand Up @@ -1279,6 +1283,7 @@
EEC28CC929D30D440075CD4C /* DeleteRecordUseCase.swift */,
23431C332A242B1D00571286 /* GetRecordsOfGoalInRecordTabUseCase.swift */,
23431C352A242C8B00571286 /* GetNoSecondEmotionRecordsUseCase.swift */,
23115DDA2A2D773F0024D6CF /* SelectSecondEmotionUseCase.swift */,
);
path = Record;
sourceTree = "<group>";
Expand Down Expand Up @@ -1612,6 +1617,7 @@
EE7D35D629D5A16300D2AD60 /* Register */,
23431C2F2A24262B00571286 /* RecordTabViewModel.swift */,
237CDEE02A27604100B3010F /* RecordSecondEmotionViewModel.swift */,
23115DD82A2D763C0024D6CF /* PostSecondEmotionViewModel.swift */,
);
path = Record;
sourceTree = "<group>";
Expand Down Expand Up @@ -2203,7 +2209,7 @@
5724EC6C2918CEE200DC529B /* FriendCollectionViewCell.swift in Sources */,
2308C5BB29B385500046A76C /* LinkToAppStore.swift in Sources */,
23816885292EDE5100579DD4 /* SubmitViewController.swift in Sources */,
23B3B7DC29319411008CB960 /* SecondEmotionViewController.swift in Sources */,
23B3B7DC29319411008CB960 /* PostSecondEmotionViewController.swift in Sources */,
2345E1CA2981947A003185E0 /* UserResponseModel.swift in Sources */,
23A17C51292BC93100426825 /* RecordCardTableViewCell.swift in Sources */,
5724EC722918CFBA00DC529B /* BaseCollectionViewCell.swift in Sources */,
Expand All @@ -2225,10 +2231,12 @@
5724EC5F2917736300DC529B /* MyPageViewController.swift in Sources */,
57CCA7AC292DE83F007E22D1 /* GoalContentView.swift in Sources */,
EEE5F5EB2981270700ECD31B /* FriendEmotionRequestModel.swift in Sources */,
23115DD92A2D763C0024D6CF /* PostSecondEmotionViewModel.swift in Sources */,
57CCA75D2925AEED007E22D1 /* FriendTableEmptyView.swift in Sources */,
EE4CEA522A00AC29002BF87E /* GetAllFriendsRecordsUseCase.swift in Sources */,
EE7D35E929D5A16300D2AD60 /* SignInViewModel.swift in Sources */,
EEC28CC029D30CE20075CD4C /* FriendRepositoryInterface.swift in Sources */,
23115DDB2A2D773F0024D6CF /* SelectSecondEmotionUseCase.swift in Sources */,
57CCA785292B0A37007E22D1 /* ReviewEmptyView.swift in Sources */,
23F14C192990D72600630AB2 /* TextInfoPopUpViewController.swift in Sources */,
EE98F0E82980F043007BFCCD /* FriendService.swift in Sources */,
Expand Down
15 changes: 15 additions & 0 deletions POME/Data/Repository/RecordRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,19 @@ class RecordRepository: RecordRepositoryInterface{
}
return observable
}

func postSecondEmotion(id: Int, requestValue: RecordSecondEmotionRequestModel) -> Observable<BaseResponseStatus> {
let observable = Observable<BaseResponseStatus>.create { observer -> Disposable in
let requestReference: () = RecordService.shared.postSecondEmotion(id: id, param: requestValue) { response in
switch response {
case .success:
observer.onNext(.success)
default:
break
}
}
return Disposables.create(with: { requestReference })
}
return observable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ protocol RecordRepositoryInterface{
func deleteRecord(requestValue: DeleteRecordRequestModel) -> Observable<BaseResponseStatus>
func getRecordsOfGoalInRecordTab(id: Int, pageable: PageableModel) -> Observable<PageableResponseModel<RecordResponseModel>>
func getNoSecondEmotionRecords(id: Int) -> Observable<PageableResponseModel<RecordResponseModel>>
func postSecondEmotion(id: Int, requestValue: RecordSecondEmotionRequestModel) -> Observable<BaseResponseStatus>
}
26 changes: 26 additions & 0 deletions POME/Domain/UseCase/Record/SelectSecondEmotionUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// SelectSecondEmotionUseCase.swift
// POME
//
// Created by gomin on 2023/06/05.
//

import Foundation
import RxSwift

protocol PostSecondEmotionUseCaseInterface {
func execute(recordId: Int, requestValue: RecordSecondEmotionRequestModel) -> Observable<BaseResponseStatus>
}

final class PostSecondEmotionUseCase: PostSecondEmotionUseCaseInterface {

private let recordRepository: RecordRepositoryInterface

init(recordRepository: RecordRepositoryInterface = RecordRepository()) {
self.recordRepository = recordRepository
}

func execute(recordId: Int, requestValue: RecordSecondEmotionRequestModel) -> Observable<BaseResponseStatus>{
return recordRepository.postSecondEmotion(id: recordId, requestValue: requestValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ extension AllRecordsViewController: UITableViewDelegate, UITableViewDataSource {

}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = SecondEmotionViewController()
vc.recordId = self.recordsOfGoal[indexPath.item].id
let vc = PostSecondEmotionViewController(recordId: recordsOfGoal[indexPath.item].id)
self.navigationController?.pushViewController(vc, animated: true)

tableView.deselectRow(at: indexPath, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ extension RecordSecondEmotionViewController: UITableViewDelegate, UITableViewDat
}

private func moveToSelectSecondEmotion(indexPath: IndexPath) {
let vc = SecondEmotionViewController()
vc.recordId = viewModel.records[dataIndexBy(indexPath)].id
let vc = PostSecondEmotionViewController(recordId: viewModel.records[dataIndexBy(indexPath)].id)
self.navigationController?.pushViewController(vc, animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// SecondEmotionViewController.swift
// POME
//
// Created by gomin on 2022/11/26.
//

import Foundation
import RxSwift
import RxCocoa


final class PostSecondEmotionViewController: BaseViewController{

private let recordId: Int

init(recordId: Int){
self.recordId = recordId
super.init(nibName: nil, bundle: nil)
}

private typealias emotionViewType = SelectEmotionView.EmotionElementView

private let mainView = SelectEmotionView(type: .Second)
private let viewModel = PostSecondEmotionViewModel()


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 = PostSecondEmotionViewModel.Input(record: recordId,
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] status in
if status == .success {
RecordObserver.shared.registerSecondEmotion.onNext(Void())
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)
}
}
}
}

This file was deleted.

Loading

0 comments on commit 9a220b1

Please sign in to comment.