Skip to content

Commit

Permalink
[refactor] 기록탭 & 회고탭 상속 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
gom1n committed May 30, 2023
1 parent d996a44 commit 9b8a502
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 327 deletions.
4 changes: 4 additions & 0 deletions POME.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
23431C322A24293500571286 /* DeleteGoalUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23431C312A24293500571286 /* DeleteGoalUseCase.swift */; };
23431C342A242B1D00571286 /* GetRecordsOfGoalInRecordTabUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23431C332A242B1D00571286 /* GetRecordsOfGoalInRecordTabUseCase.swift */; };
23431C362A242C8B00571286 /* GetNoSecondEmotionRecordsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23431C352A242C8B00571286 /* GetNoSecondEmotionRecordsUseCase.swift */; };
2343FB032A269F7600820625 /* GoalWithRecordViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2343FB022A269F7600820625 /* GoalWithRecordViewModel.swift */; };
2345E1C429818848003185E0 /* BaseResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2345E1C329818848003185E0 /* BaseResponseModel.swift */; };
2345E1C829819471003185E0 /* UserRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2345E1C729819471003185E0 /* UserRequestModel.swift */; };
2345E1CA2981947A003185E0 /* UserResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2345E1C92981947A003185E0 /* UserResponseModel.swift */; };
Expand Down Expand Up @@ -327,6 +328,7 @@
23431C312A24293500571286 /* DeleteGoalUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteGoalUseCase.swift; sourceTree = "<group>"; };
23431C332A242B1D00571286 /* GetRecordsOfGoalInRecordTabUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetRecordsOfGoalInRecordTabUseCase.swift; sourceTree = "<group>"; };
23431C352A242C8B00571286 /* GetNoSecondEmotionRecordsUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetNoSecondEmotionRecordsUseCase.swift; sourceTree = "<group>"; };
2343FB022A269F7600820625 /* GoalWithRecordViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalWithRecordViewModel.swift; sourceTree = "<group>"; };
2345E1C329818848003185E0 /* BaseResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseResponseModel.swift; sourceTree = "<group>"; };
2345E1C729819471003185E0 /* UserRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRequestModel.swift; sourceTree = "<group>"; };
2345E1C92981947A003185E0 /* UserResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserResponseModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1586,6 +1588,7 @@
EE7D35DC29D5A16300D2AD60 /* Authentication */,
EE7D35DE29D5A16300D2AD60 /* Review */,
EE7D35E029D5A16300D2AD60 /* Goal */,
2343FB022A269F7600820625 /* GoalWithRecordViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -2278,6 +2281,7 @@
2375E4892A20397400843056 /* MyPageViewModel.swift in Sources */,
5724EC84291B29A700DC529B /* EmojiFloatingCollectionViewCell.swift in Sources */,
EE38758029D917B900A26AD5 /* TextConverter.swift in Sources */,
2343FB032A269F7600820625 /* GoalWithRecordViewModel.swift in Sources */,
EE7D35EC29D5A16300D2AD60 /* GenerateGoalDateViewModel.swift in Sources */,
57543B7C2951BF5300A409E3 /* CalendarSheetCollectionViewCell.swift in Sources */,
23F57834292D5460002DD28E /* SettingViewController.swift in Sources */,
Expand Down
145 changes: 10 additions & 135 deletions POME/Presentation/ViewControllers/Record/RecordViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class RecordViewController: BaseTabViewController {
goalRelay.value
}

private let INFO_SECTION = 0
private let COUNT_OF_NOT_RECORD_CELL = 3 //record 이외 UI 구성하는 cell 3개 존재

private var goalCategoryTableViewCell: GoalCategoryTableViewCell?{
recordView.recordTableView.cellForRow(at: [INFO_SECTION,0], cellType: GoalCategoryTableViewCell.self)
}
Expand All @@ -29,22 +26,23 @@ class RecordViewController: BaseTabViewController {
return indexPath.row - 3
}

// Properties

private let INFO_SECTION = 0
private let COUNT_OF_NOT_RECORD_CELL = 3 //record 이외 UI 구성하는 cell 3개 존재

// GetGoal control
private var isFirstLoad = true
// Goal Content
var goalContent: [GoalResponseModel] = []
// var categorySelectedIdx = 0
// Records
var recordsOfGoal: [RecordResponseModel] = []
var noSecondEmotionRecords: [RecordResponseModel] = []

// Page
var recordPage: Int?
// Cell Height
var expendingCellContent = ExpandingTableViewCellContent()
// Refresh Control
var refreshControl = UIRefreshControl()


// Life Cycles
override func viewDidLoad() {
super.viewDidLoad()
viewModel.refreshData()
Expand All @@ -57,6 +55,7 @@ class RecordViewController: BaseTabViewController {
recordView.recordTableView.delegate = self
recordView.recordTableView.dataSource = self
}

override func layout() {
super.layout()

Expand All @@ -75,6 +74,7 @@ class RecordViewController: BaseTabViewController {
make.top.equalTo(super.navigationView.snp.bottom)
}
}

override func initialize() {
super.initialize()

Expand Down Expand Up @@ -258,23 +258,6 @@ extension RecordViewController: UICollectionViewDelegate, UICollectionViewDataSo
return cell
}

// func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
// goalRelay.accept(indexPath.row)

// 기간이 지난 목표
// if isGoalDateEnd(goalContent[itemIdx]) || self.noSecondEmotionRecords.count != 0 {self.showNoSecondEmotionWarning()}

// 목표에 저장된 씀씀이 조회
// self.recordPage = 0
// self.recordsOfGoal.removeAll()
// getRecordsOfGoal(id: goalContent[itemIdx].id)
// getNoSecondEmotionRecords(id: goalContent[itemIdx].id)
//
// self.recordView.recordTableView.reloadData()

// return true
// }

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.cellForItem(at: indexPath, cellType: GoalTagCollectionViewCell.self)?.do{
$0.setSelectState()
Expand Down Expand Up @@ -406,7 +389,7 @@ extension RecordViewController: UITableViewDelegate, UITableViewDataSource {
// MARK: - Record Cell delegate
extension RecordViewController: RecordCellDelegate{
func presentReactionSheet(indexPath: IndexPath) {
let data = recordsOfGoal[dataIndexBy(indexPath)].friendReactions
let data = viewModel.records[dataIndexBy(indexPath)].friendReactions
FriendReactionSheetViewController(reactions: data).show(in: self)
}

Expand Down Expand Up @@ -460,111 +443,3 @@ extension RecordViewController {
}
}
}
////MARK: - API
//extension RecordViewController {
// // MARK: 목표 리스트 조회 API
// func requestGetGoals(){
// // api 호출할 때마다 Goal 배열 초기화
// self.goalContent.removeAll()
// GoalService.shared.getUserGoals{ result in
// defer{
// self.isFirstLoad = false
// }
// switch result{
// case .success(let data):
// print("success goal:", data.content)
// for x in data.content {
// if !x.isEnd {
// self.goalContent.append(x)
// }
// }
// // 목표에 맞는 기록들 조회
// if !self.goalContent.isEmpty {
// // 기록 초기화 후 다시 호출
// self.recordPage = 0
// self.recordsOfGoal.removeAll()
// self.getRecordsOfGoal(id: self.goalContent[self.selectedGoalIndex].id)
// }
//
// if let cell = self.recordView.recordTableView.cellForRow(at: [0,0]) as? GoalCategoryTableViewCell {
// cell.goalCollectionView.reloadData()
// self.recordView.recordTableView.reloadData()
// }
// self.refreshControl.endRefreshing()
// break
// default:
// print(result)
// NetworkAlert.show(in: self){ [weak self] in
// self?.requestGetGoals()
// }
// break
// }
// }
// }
// // MARK: 목표 삭제 API
// private func deleteGoal(id: Int){
// GoalService.shared.deleteGoal(id: id) { result in
// switch result{
// case .success(let data):
// if data.success {
// print("목표 삭제 성공")
// self.selectedGoalIndex = 0
// self.requestGetGoals()
// GoalObserver.shared.deleteGoal.onNext(Void())
// }
// break
// default:
// print(result)
// break
// }
// }
// }
// // MARK: 목표에 해당하는 기록 조회 API
// private func getRecordsOfGoal(id: Int) {
// let pageModel = PageableModel(page: self.recordPage ?? 0)
// RecordService.shared.getRecordsOfGoalAtRecordTab(id: id, pageable: pageModel) { result in
// switch result{
// case .success(let data):
//// print("LOG: 씀씀이 조회", data)
// // Paging 때문에 append하는 방식으로 작업
// for recordData in data.content {
// self.recordsOfGoal.append(recordData)
// }
// self.getNoSecondEmotionRecords(id: id)
//
// break
// default:
// print(result)
// NetworkAlert.show(in: self){ [weak self] in
// self?.getRecordsOfGoal(id: id)
// }
// break
// }
//
// }
// }
// // MARK: 기록 삭제 API
// private func deleteRecord(id: Int) {
// RecordService.shared.deleteRecord(id: id) { result in
// print("기록 삭제 성공")
// self.requestGetGoals()
// }
// }
// // MARK: 일주일이 지났고, 두 번째 감정이 없는 기록 조회 API
// private func getNoSecondEmotionRecords(id: Int) {
// RecordService.shared.getNoSecondEmotionRecords(id: id) { result in
// switch result{
// case .success(let data):
//// print("LOG: 일주일이 지났고, 두 번째 감정이 없는 기록 조회", data)
//
// self.noSecondEmotionRecords = data.content
// self.recordView.recordTableView.reloadData()
//
// break
// default:
// print(result)
// break
// }
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ final class ModifyRecordViewController: Recordable{
var completion: ((RecordResponseModel) -> Void)? //ViewModel 활용안하는 VC에게 데이터 전달 용도

private let record: RecordResponseModel
private var modifyViewModel: (any ReviewViewModelInterface)?
private var modifyViewModel: (any GoalWithRecordViewModelInterface)?
private var index: Int!
private var tableViewIndexPath: IndexPath!

init(modifyViewModel: any ReviewViewModelInterface, index: Int, goal: GoalResponseModel){
init(modifyViewModel: any GoalWithRecordViewModelInterface, index: Int, goal: GoalResponseModel){
self.modifyViewModel = modifyViewModel
self.index = index
self.record = modifyViewModel.records[index]
Expand Down
Loading

0 comments on commit 9b8a502

Please sign in to comment.