Skip to content

Commit

Permalink
feat/#185 홈 화면 다가올 약속 서비스타입 구현 및 뷰모델 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybei committed Jul 16, 2024
1 parent 0cc3bc4 commit 99ba219
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 94 deletions.
26 changes: 6 additions & 20 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
A3DD9C5C2C43F9A800E58A13 /* SetReadyInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C5B2C43F9A800E58A13 /* SetReadyInfoViewController.swift */; };
A3DD9C5F2C441F8E00E58A13 /* SetReadyInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C5E2C441F8E00E58A13 /* SetReadyInfoViewModel.swift */; };
A3DD9C622C455E3300E58A13 /* MeetingListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C612C455E3300E58A13 /* MeetingListService.swift */; };
A3DD9C682C45C78300E58A13 /* HomeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C672C45C78300E58A13 /* HomeService.swift */; };
A3FB184D2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */; };
A3FB184F2C3BF4BC001483E5 /* MakeMeetingsResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */; };
A3FB18512C3BF531001483E5 /* RegisterMeetingsResquestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB18502C3BF531001483E5 /* RegisterMeetingsResquestModel.swift */; };
Expand Down Expand Up @@ -218,6 +219,7 @@
A3DD9C5B2C43F9A800E58A13 /* SetReadyInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetReadyInfoViewController.swift; sourceTree = "<group>"; };
A3DD9C5E2C441F8E00E58A13 /* SetReadyInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetReadyInfoViewModel.swift; sourceTree = "<group>"; };
A3DD9C612C455E3300E58A13 /* MeetingListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingListService.swift; sourceTree = "<group>"; };
A3DD9C672C45C78300E58A13 /* HomeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeService.swift; sourceTree = "<group>"; };
A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsRequestModel.swift; sourceTree = "<group>"; };
A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsResponseModel.swift; sourceTree = "<group>"; };
A3FB18502C3BF531001483E5 /* RegisterMeetingsResquestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterMeetingsResquestModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -548,22 +550,6 @@
path = Bundle;
sourceTree = "<group>";
};
A3DD9C332C41BAD000E58A13 /* Cell */ = {
isa = PBXGroup;
children = (
A3DD9C322C41BAD000E58A13 /* MeetingTableViewCell.swift */,
);
path = Cell;
sourceTree = "<group>";
};
A3DD9C352C41BAD000E58A13 /* Model */ = {
isa = PBXGroup;
children = (
A3DD9C342C41BAD000E58A13 /* MeetingDummyModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
A3DD9C372C41BAD000E58A13 /* View */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -611,6 +597,7 @@
isa = PBXGroup;
children = (
A3DD9C612C455E3300E58A13 /* MeetingListService.swift */,
A3DD9C672C45C78300E58A13 /* HomeService.swift */,
);
path = Service;
sourceTree = "<group>";
Expand Down Expand Up @@ -955,7 +942,6 @@
DD865B662C39210E00C351A2 /* Login */ = {
isa = PBXGroup;
children = (
78BD61212C440AC8005752FD /* Service */,
789873372C3D1B4800435E96 /* ViewController */,
789873362C3D1B3900435E96 /* VIewModel */,
789873352C3D1B3000435E96 /* View */,
Expand Down Expand Up @@ -1464,7 +1450,6 @@
DE6D4D112C3F14D80005584B /* MeetingInfoBannerView.swift in Sources */,
DE6D4D122C3F14D80005584B /* MeetingInfoView.swift in Sources */,
DD30721E2C3C0CC800416D9F /* PromiseInfoResponseModel.swift in Sources */,
78BD61232C440AD5005752FD /* AuthService.swift in Sources */,
DD931B722C3DA92700526452 /* EnterReadyInfoButtonView.swift in Sources */,
DD41BEFF2C41DAA40095A068 /* TardyEmptyView.swift in Sources */,
A3FB18512C3BF531001483E5 /* RegisterMeetingsResquestModel.swift in Sources */,
Expand Down Expand Up @@ -1517,6 +1502,7 @@
DD3976832C41C2AD00E2A4C4 /* HomeViewModel.swift in Sources */,
DD41BF012C41DE4F0095A068 /* TardyCollectionViewCell.swift in Sources */,
DE9E189A2C3BCCBE00DB76B4 /* UtilsTemp.swift in Sources */,
A3DD9C682C45C78300E58A13 /* HomeService.swift in Sources */,
782B407B2C3E395A008B0CA7 /* WelcomeView.swift in Sources */,
DD3072142C3BF87A00416D9F /* NearestPromiseResponseModel.swift in Sources */,
782B407F2C3E44B7008B0CA7 /* WelcomeViewModel.swift in Sources */,
Expand Down Expand Up @@ -1544,9 +1530,9 @@
DD41BEFC2C41D54D0095A068 /* TardyPenaltyView.swift in Sources */,
789873322C3D1A7B00435E96 /* LoginViewController.swift in Sources */,
782B40722C3DBFA3008B0CA7 /* ProfileSetupViewModel.swift in Sources */,
DDAF1C8F2C3D6E3D008A37D3 /* BasePromiseSegmentedControl.swift in Sources */,
DDAF1C8F2C3D6E3D008A37D3 /* PagePromiseSegmentedControl.swift in Sources */,
DD49099C2C441719003ED304 /* TardyService.swift in Sources */,
782B40722C3DBFA3008B0CA7 /* ProfileViewModel.swift in Sources */,
782B40722C3DBFA3008B0CA7 /* ProfileSetupViewModel.swift in Sources */,
DDAF1C8F2C3D6E3D008A37D3 /* PagePromiseSegmentedControl.swift in Sources */,
DE32D1D22C3BF703006848DF /* LoginUserResponseModel.swift in Sources */,
DE9E18892C3BC91000DB76B4 /* ResponseBodyDTO.swift in Sources */,
Expand Down
90 changes: 90 additions & 0 deletions KkuMulKum/Resource/Service/HomeService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// HomeService.swift
// KkuMulKum
//
// Created by 예삐 on 7/16/24.
//

import Foundation

protocol HomeServiceType {
func fetchLoginUser() -> LoginUserModel?
func fetchNearestPromise() -> NearestPromiseModel?
func fetchUpcomingPromise() -> UpcomingPromiseListModel?
}

final class MockHomeService: HomeServiceType {
func fetchLoginUser() -> LoginUserModel? {
let mockData = LoginUserModel(
name: "꾸물리안",
level: 4,
promiseCount: 8,
tardyCount: 2,
tardySum: 72,
profileImageURL: ""
)
return mockData
}

func fetchNearestPromise() -> NearestPromiseModel? {
let mockData = NearestPromiseModel(
id: 1,
dDay: 0,
name: "꾸물이들의 냐미한 밤",
meetingName: "꾸물이들",
dressUpLevel: "냐미",
date: "2024.07.16",
time: "PM 8:00",
placeName: "DMC역"
)
return mockData
}

func fetchUpcomingPromise() -> UpcomingPromiseListModel? {
let mockData = UpcomingPromiseListModel(
promises: [
UpcomingPromise(
id: 1,
dDay: 1,
name: "누가 코코볼 다 먹었어?",
meetingName: "우마우스",
dressUpLevel: "",
date: "2024.07.17",
time: "PM 2:00",
placeName: "가자하우스"
),
UpcomingPromise(
id: 2,
dDay: 1,
name: "누가 코코볼 다 먹었어?",
meetingName: "우마우스",
dressUpLevel: "",
date: "2024.07.17",
time: "PM 2:00",
placeName: "가자하우스"
),
UpcomingPromise(
id: 3,
dDay: 1,
name: "누가 코코볼 다 먹었어?",
meetingName: "우마우스",
dressUpLevel: "",
date: "2024.07.17",
time: "PM 2:00",
placeName: "가자하우스"
),
UpcomingPromise(
id: 4,
dDay: 1,
name: "누가 코코볼 다 먹었어?",
meetingName: "우마우스",
dressUpLevel: "",
date: "2024.07.17",
time: "PM 2:00",
placeName: "가자하우스"
)
]
)
return mockData
}
}
5 changes: 4 additions & 1 deletion KkuMulKum/Source/Core/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ final class MainTabBarController: UITabBarController {


private func setTabBar() {
let homeViewController: HomeViewController = HomeViewController().then {
let homeViewController: HomeViewController = HomeViewController(
viewModel: HomeViewModel(
service: MockHomeService()
)).then {
$0.tabBarItem.title = ""
$0.tabBarItem.image = .iconHome
}
Expand Down
56 changes: 0 additions & 56 deletions KkuMulKum/Source/Home/Model/UpcomingPromiseModel.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ final class UpcomingPromiseCollectionViewCell: BaseCollectionViewCell {
// MARK: - Data Bind

extension UpcomingPromiseCollectionViewCell {
func dataBind(_ contentData: UpcomingPromiseModel) {
func dataBind(_ contentData: UpcomingPromise) {
let dDayText = contentData.dDay == 0 ? "DAY" : "\(contentData.dDay)"
dDayLabel.setText(
"D-\(dDayText)",
Expand Down
26 changes: 21 additions & 5 deletions KkuMulKum/Source/Home/ViewController/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ class HomeViewController: BaseViewController {
// MARK: - Property

private let rootView = HomeView()
private let viewModel = HomeViewModel()

private let viewModel: HomeViewModel

final let cellWidth: CGFloat = 200
final let cellHeight: CGFloat = 216
final let contentInterSpacing: CGFloat = 12
final let contentInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)


// MARK: - Initializer

init(viewModel: HomeViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

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


// MARK: - LifeCycle
Expand All @@ -36,8 +49,9 @@ class HomeViewController: BaseViewController {

register()
updateUI()

updateUpcomingPromise()
viewModel.dummy()
viewModel.requestUpcomingPromise()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -107,7 +121,7 @@ extension HomeViewController: UICollectionViewDataSource {
_ collectionView: UICollectionView,
numberOfItemsInSection section: Int
) -> Int {
return viewModel.upcomingPromiseData.value.count
return viewModel.upcomingPromiseList.value?.promises.count ?? 0
}

func collectionView(
Expand All @@ -118,7 +132,9 @@ extension HomeViewController: UICollectionViewDataSource {
withReuseIdentifier: UpcomingPromiseCollectionViewCell.reuseIdentifier,
for: indexPath
) as? UpcomingPromiseCollectionViewCell else { return UICollectionViewCell() }
cell.dataBind(viewModel.upcomingPromiseData.value[indexPath.item])
if let data = viewModel.upcomingPromiseList.value?.promises[indexPath.item] {
cell.dataBind(data)
}
return cell
}
}
Expand Down Expand Up @@ -190,7 +206,7 @@ private extension HomeViewController {
}

func updateUpcomingPromise() {
viewModel.upcomingPromiseData.bind { [weak self] _ in
viewModel.upcomingPromiseList.bind { [weak self] _ in
DispatchQueue.main.async {
self?.rootView.upcomingPromiseView.reloadData()
}
Expand Down
24 changes: 18 additions & 6 deletions KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ enum ReadyState {

final class HomeViewModel {
var currentState = ObservablePattern<ReadyState>(.none)
var upcomingPromiseData = ObservablePattern<[UpcomingPromiseModel]>([])

var loginUser = ObservablePattern<LoginUserModel?>(nil)
var nearestPromise = ObservablePattern<NearestPromiseModel?>(nil)
var upcomingPromiseList = ObservablePattern<UpcomingPromiseListModel?>(nil)

private let service: HomeServiceType

init(service: HomeServiceType) {
self.service = service
}

var homePrepareTime: String = ""
var homeMoveTime: String = ""
Expand All @@ -45,12 +54,15 @@ final class HomeViewModel {
}
}

/// 더미 함수 이후에 삭제
func dummy() {
upcomingPromiseData.value = UpcomingPromiseModel.dummy()
func requestLoginUser() {
loginUser.value = service.fetchLoginUser()
}

func requestNearestPromise() {
nearestPromise.value = service.fetchNearestPromise()
}

func updateContentData(newData: [UpcomingPromiseModel]) {
upcomingPromiseData.value = newData
func requestUpcomingPromise() {
upcomingPromiseList.value = service.fetchUpcomingPromise()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class MeetingListViewController: BaseViewController {
rootView.tableView.dataSource = self
}

private func updateInfoLabel() {

}

private func updateMeetingList() {
viewModel.meetingList.bind { [weak self] _ in
DispatchQueue.main.async {
Expand Down Expand Up @@ -104,7 +100,6 @@ extension MeetingListViewController: UITableViewDataSource {
if let data = viewModel.meetingList.value?.meetings[indexPath.item] {
cell.dataBind(data)
}
//cell.dataBind(viewModel.meetingList.value?[indexPath.item])
cell.selectionStyle = .none
return cell
}
Expand Down

0 comments on commit 99ba219

Please sign in to comment.