Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #44 from k-nh/feature/home
Browse files Browse the repository at this point in the history
기능추가🔧: #42 추천 맛집 api 연동 및 MVVM 리팩토링
  • Loading branch information
k-nh authored Jun 1, 2022
2 parents 12de858 + 2ffc180 commit 249f52c
Show file tree
Hide file tree
Showing 20 changed files with 419 additions and 239 deletions.
66 changes: 63 additions & 3 deletions EatDa.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@
FDD8DDCD27A423450072034C /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD8DDCC27A423450072034C /* HomeViewController.swift */; };
FDD8DDD027A423740072034C /* FilterButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD8DDCF27A423740072034C /* FilterButtonView.swift */; };
FDD8DDD327A426C40072034C /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD8DDD227A426C40072034C /* UIColor.swift */; };
FDE30726284343C500EA15CF /* AroundDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE30725284343C500EA15CF /* AroundDetailViewModel.swift */; };
FDE3072828434CA600EA15CF /* HomeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE3072728434CA600EA15CF /* HomeModel.swift */; };
FDE3072B284474A900EA15CF /* RecommendCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE3072A284474A900EA15CF /* RecommendCollectionView.swift */; };
FDE3072D2844CB9400EA15CF /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE3072C2844CB9300EA15CF /* SearchView.swift */; };
FDE30732284640B500EA15CF /* RestaurantListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE30731284640B500EA15CF /* RestaurantListView.swift */; };
FDE30734284640CE00EA15CF /* RestaurantListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE30733284640CE00EA15CF /* RestaurantListViewModel.swift */; };
FDE30736284640EA00EA15CF /* RestaurantListData.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE30735284640EA00EA15CF /* RestaurantListData.swift */; };
FDE30738284640FF00EA15CF /* RestaurantListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE30737284640FF00EA15CF /* RestaurantListCell.swift */; };
FDE3073A2846411A00EA15CF /* RestaurantListNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE307392846411A00EA15CF /* RestaurantListNetwork.swift */; };
FDE37EAB27D37DCB00618163 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE37EAA27D37DCB00618163 /* HomeViewModel.swift */; };
FDE37EAD27D389C400618163 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE37EAC27D389C400618163 /* SearchViewController.swift */; };
FDE37EAF27D389CF00618163 /* SearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE37EAE27D389CF00618163 /* SearchViewModel.swift */; };
Expand Down Expand Up @@ -177,6 +186,15 @@
FDD8DDCC27A423450072034C /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
FDD8DDCF27A423740072034C /* FilterButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterButtonView.swift; sourceTree = "<group>"; };
FDD8DDD227A426C40072034C /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
FDE30725284343C500EA15CF /* AroundDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundDetailViewModel.swift; sourceTree = "<group>"; };
FDE3072728434CA600EA15CF /* HomeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeModel.swift; sourceTree = "<group>"; };
FDE3072A284474A900EA15CF /* RecommendCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendCollectionView.swift; sourceTree = "<group>"; };
FDE3072C2844CB9300EA15CF /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
FDE30731284640B500EA15CF /* RestaurantListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListView.swift; sourceTree = "<group>"; };
FDE30733284640CE00EA15CF /* RestaurantListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListViewModel.swift; sourceTree = "<group>"; };
FDE30735284640EA00EA15CF /* RestaurantListData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListData.swift; sourceTree = "<group>"; };
FDE30737284640FF00EA15CF /* RestaurantListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListCell.swift; sourceTree = "<group>"; };
FDE307392846411A00EA15CF /* RestaurantListNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantListNetwork.swift; sourceTree = "<group>"; };
FDE37EAA27D37DCB00618163 /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
FDE37EAC27D389C400618163 /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; };
FDE37EAE27D389CF00618163 /* SearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -467,20 +485,20 @@
FD9C6F4927C108AC005D88A6 /* RecommendView */ = {
isa = PBXGroup;
children = (
FDE3072928446E1400EA15CF /* RecommendDetail */,
FD94861527A95987009BE666 /* RecommendSectionView.swift */,
FDE3072A284474A900EA15CF /* RecommendCollectionView.swift */,
FD9C6F3927BFDA4F005D88A6 /* RecommendCollectionViewCell.swift */,
FDEA5E3727EF10BF008EFD5E /* RecommendDetailViewController.swift */,
FDEA5E3D27F04620008EFD5E /* RecommendDetailViewModel.swift */,
);
path = RecommendView;
sourceTree = "<group>";
};
FD9C6F4A27C108C0005D88A6 /* AroundView */ = {
isa = PBXGroup;
children = (
FDE307242843433100EA15CF /* AroundDetail */,
FD94861727A9598C009BE666 /* AroundSectionView.swift */,
FD94861B27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift */,
FDEA5E3927EF10CD008EFD5E /* AroundDetailViewController.swift */,
);
path = AroundView;
sourceTree = "<group>";
Expand Down Expand Up @@ -517,6 +535,7 @@
children = (
FDD8DDCC27A423450072034C /* HomeViewController.swift */,
FDE37EAA27D37DCB00618163 /* HomeViewModel.swift */,
FDE3072728434CA600EA15CF /* HomeModel.swift */,
FDD8DDCE27A423620072034C /* SubComponents */,
);
path = Home;
Expand All @@ -531,6 +550,7 @@
FD9C6F4827C1087E005D88A6 /* FilterView */,
FD9C6F4927C108AC005D88A6 /* RecommendView */,
FD9C6F4A27C108C0005D88A6 /* AroundView */,
FDE307302846407D00EA15CF /* RestaurantListView */,
FD9C6F4B27C108EF005D88A6 /* MapView */,
FD94861C27A959EF009BE666 /* SeperatorView.swift */,
);
Expand All @@ -549,10 +569,41 @@
path = Extensions;
sourceTree = "<group>";
};
FDE307242843433100EA15CF /* AroundDetail */ = {
isa = PBXGroup;
children = (
FDEA5E3927EF10CD008EFD5E /* AroundDetailViewController.swift */,
FDE30725284343C500EA15CF /* AroundDetailViewModel.swift */,
);
path = AroundDetail;
sourceTree = "<group>";
};
FDE3072928446E1400EA15CF /* RecommendDetail */ = {
isa = PBXGroup;
children = (
FDEA5E3727EF10BF008EFD5E /* RecommendDetailViewController.swift */,
FDEA5E3D27F04620008EFD5E /* RecommendDetailViewModel.swift */,
);
path = RecommendDetail;
sourceTree = "<group>";
};
FDE307302846407D00EA15CF /* RestaurantListView */ = {
isa = PBXGroup;
children = (
FDE30731284640B500EA15CF /* RestaurantListView.swift */,
FDE30733284640CE00EA15CF /* RestaurantListViewModel.swift */,
FDE30735284640EA00EA15CF /* RestaurantListData.swift */,
FDE30737284640FF00EA15CF /* RestaurantListCell.swift */,
FDE307392846411A00EA15CF /* RestaurantListNetwork.swift */,
);
path = RestaurantListView;
sourceTree = "<group>";
};
FDE37EA927D37BAA00618163 /* Search */ = {
isa = PBXGroup;
children = (
FDE37EAC27D389C400618163 /* SearchViewController.swift */,
FDE3072C2844CB9300EA15CF /* SearchView.swift */,
FDE37EAE27D389CF00618163 /* SearchViewModel.swift */,
);
path = Search;
Expand Down Expand Up @@ -736,19 +787,23 @@
files = (
FDB7906E2805A783008621D1 /* ReviewFeedViewController.swift in Sources */,
F0224C36282963560092683A /* InputSchoolViewController.swift in Sources */,
FDE3072828434CA600EA15CF /* HomeModel.swift in Sources */,
FDE30726284343C500EA15CF /* AroundDetailViewModel.swift in Sources */,
F0CCC0FA2839B830007DCBD0 /* School.swift in Sources */,
FDB7906D2805A704008621D1 /* RestaurantTableViewCell.swift in Sources */,
F0CCC0EB2838D09E007DCBD0 /* UIButton.swift in Sources */,
F0CCC0FD2839E8DD007DCBD0 /* ProgressCheck.swift in Sources */,
FD63339027A0DADC004783E3 /* TabBarController.swift in Sources */,
F0CCC0F428394226007DCBD0 /* APIResponse.swift in Sources */,
FDE3072D2844CB9400EA15CF /* SearchView.swift in Sources */,
F0224C3C28296FB90092683A /* VerifyEmailViewController.swift in Sources */,
F0128D38281E517F005BE0B9 /* SplashViewController.swift in Sources */,
FDB40685283E14B1003C70A8 /* KeyChainKey.swift in Sources */,
FDE37EAB27D37DCB00618163 /* HomeViewModel.swift in Sources */,
FDEA5E4727F834AA008EFD5E /* FilterViewModel.swift in Sources */,
FD6FBDB9283CF4A900BD7E20 /* RestaurantDetailViewModel.swift in Sources */,
F03FB65F27B025460097D817 /* RestaurantMenuTVC.swift in Sources */,
FDE30732284640B500EA15CF /* RestaurantListView.swift in Sources */,
FDF78A2727EB4284005D37C8 /* NoticeViewModel.swift in Sources */,
FD63338C27A0DADC004783E3 /* AppDelegate.swift in Sources */,
FD022E482833BB2200FC32E9 /* LikeButton.swift in Sources */,
Expand All @@ -762,16 +817,20 @@
FD9D4F7227B503090005205E /* TitleSectionView.swift in Sources */,
F03FB65627A6EBB90097D817 /* RestaurantImageCVC.swift in Sources */,
FD022E4028337E4F00FC32E9 /* MapDetailView.swift in Sources */,
FDE30738284640FF00EA15CF /* RestaurantListCell.swift in Sources */,
F03FB65327A6DDA40097D817 /* RestaurantDetailViewController.swift in Sources */,
F0128D3C281E5E9B005BE0B9 /* ImageSliderCollectionViewCell.swift in Sources */,
F0128D3E281E86DD005BE0B9 /* BottomSheetViewController.swift in Sources */,
FDE3072B284474A900EA15CF /* RecommendCollectionView.swift in Sources */,
FD0CF62F27A12BF400BDEA53 /* CommunityViewController.swift in Sources */,
F03FB66127B0333D0097D817 /* UILabel.swift in Sources */,
FD022E3E2833692100FC32E9 /* MapViewController.swift in Sources */,
FD0CF62B27A12BC400BDEA53 /* TalkViewController.swift in Sources */,
FD94861D27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift in Sources */,
FDEA5E3E27F04620008EFD5E /* RecommendDetailViewModel.swift in Sources */,
FDE3073A2846411A00EA15CF /* RestaurantListNetwork.swift in Sources */,
FDB40687283E14D5003C70A8 /* TokenUtils.swift in Sources */,
FDE30734284640CE00EA15CF /* RestaurantListViewModel.swift in Sources */,
FD9C6F5027C11838005D88A6 /* FilterView.swift in Sources */,
F0224C44282970840092683A /* RegistCompleteViewController.swift in Sources */,
F0128D3A281E5531005BE0B9 /* LoginViewController.swift in Sources */,
Expand All @@ -782,6 +841,7 @@
FDF78A2527EB421B005D37C8 /* NoticeViewController.swift in Sources */,
F03D976827DDC4A10011FA3D /* BestBoardTVC.swift in Sources */,
FDB4068B283E3EB2003C70A8 /* SignIn.swift in Sources */,
FDE30736284640EA00EA15CF /* RestaurantListData.swift in Sources */,
FDD8DDD327A426C40072034C /* UIColor.swift in Sources */,
FD0DBC6027B8D9770001E526 /* MapSectionView.swift in Sources */,
F0CCC0E92838C9BA007DCBD0 /* SchoolSearchViewController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion EatDa.xcodeproj/xcshareddata/xcschemes/EatDa.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1330"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
43 changes: 31 additions & 12 deletions EatDa/Global/Network/Util/APIResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ struct APIResponse<T: Decodable>: Decodable {
}

struct APIConstants {
// MARK: BASE URL
static let BASE_URL = "http://api.foorun.co.kr"

// MARK: SIGNUP/SIGNIN
static let GET_SCHOOL_DATA = "/school"
static let POST_SIGN_IN = "/member/sign-in"

// MARK: HOME
static let GET_RECOMMEND_RESTAURANT = "/restaurant"
static let GET_AROUND_RESTAURANT = "/restaurant/near"


}

class API<T: Decodable> {

var fetchURL: String
var method: HTTPMethod
var parameters: Parameters
Expand Down Expand Up @@ -63,29 +71,40 @@ class API<T: Decodable> {
headers: headers)
.validate(statusCode: 200..<300)
.responseJSON { response in
// 토큰 설정
guard let accessToken = response.response?.allHeaderFields["Authorization"] as? String else { return }
guard let refreshToken = response.response?.allHeaderFields["X-Refresh-Token"] as? String else { return }
// 토큰 키체인에 저장
TokenUtils.create(key: Const.KeyChainKey.accessToken, token: accessToken)
TokenUtils.create(key: Const.KeyChainKey.refreshToken, token: refreshToken)
if self.fetchURL == APIConstants.BASE_URL + APIConstants.POST_SIGN_IN {
guard let accessToken = response.response?.allHeaderFields["Authorization"] as? String else { return }
guard let refreshToken = response.response?.allHeaderFields["X-Refresh-Token"] as? String else { return }
// 로그인 시 토큰 키체인에 저장
TokenUtils.create(key: Const.KeyChainKey.accessToken, token: accessToken)
TokenUtils.create(key: Const.KeyChainKey.refreshToken, token: refreshToken)
}

switch response.result {
case .success(let value):

do {
let jsonData = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted)
let result = try JSONDecoder().decode(APIResponse<T>.self, from: jsonData)

completion(result)
} catch (let err){
print(err.localizedDescription)
print("네트워크 에러: ", err.localizedDescription)
}

case .failure(let error):
print(error.localizedDescription)
print("네트워크 에러: ", error.localizedDescription)
}

}
}

func fetchWithRx() -> Observable<T> {
return Observable.create { emitter in
self.fetch() { result in
guard result.data != nil else{
print("데이터가 존재하지 않습니다.")
return
}
emitter.onNext(result.data!)
}
return Disposables.create()
}
}

Expand Down
4 changes: 3 additions & 1 deletion EatDa/Global/Network/Util/Constants/Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
import Foundation

struct Const {
static var headerToken: String = TokenUtils.read(key: Const.KeyChainKey.accessToken) ?? ""
static var headerToken: String? = TokenUtils.read(key: Const.KeyChainKey.accessToken)
static var refreshToken: String? = TokenUtils.read(key: Const.KeyChainKey.refreshToken)

}
2 changes: 1 addition & 1 deletion EatDa/Global/Network/Util/Constants/TokenUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TokenUtils {
return value
} else { return nil }
} else {
print("\(status) 에러: 로딩에 실패하였습니다.")
print("\(status) 에러: 토큰 값 로딩에 실패하였습니다.")
return nil
}
}
Expand Down
10 changes: 7 additions & 3 deletions EatDa/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(windowScene: windowScene)
window?.backgroundColor = .systemBackground
let accessToken = TokenUtils.read(key: Const.KeyChainKey.accessToken)
var rootVC: UIViewController

if accessToken != nil {
var rootVC: UIViewController

if Const.headerToken != nil {
if UserDefaults.standard.bool(forKey: "loginComplete") {

print(Const.headerToken)
print(Const.headerToken)

rootVC = TabBarController()
window?.rootViewController = rootVC
window?.makeKeyAndVisible()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import RxCocoa

struct RestaurantDetailViewModel {
let mapViewTapped = PublishSubject<Void>()

}
22 changes: 11 additions & 11 deletions EatDa/Scenes/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ class HomeViewController: UIViewController {
})
.disposed(by: disposeBag)

viewModel.recommendDetailButtonTapped
.asDriver(onErrorDriveWith: .empty())
.drive(onNext: {
viewModel.pushRecommendDetailViewController
.drive(onNext: { viewModel in
let viewController = RecommendDetailViewController()
viewController.bind(viewModel)
self.show(viewController, sender: nil)
})
.disposed(by: disposeBag)

viewModel.aroundDetailButtonTapped
.asDriver(onErrorDriveWith: .empty())
.drive(onNext: {
let viewController = AroundDetailViewController()
//viewController.bind(viewModel)
self.show(viewController, sender: nil)
})
.disposed(by: disposeBag)
// viewModel.pushAroundDetailViewController
// .drive(onNext: { viewModel in
// let viewController = AroundDetailViewController()
// viewController.bind(viewModel)
// self.show(viewController, sender: nil)
// })
// .disposed(by: disposeBag)


viewModel.mapViewTapped
.asDriver(onErrorDriveWith: .empty())
Expand Down
23 changes: 21 additions & 2 deletions EatDa/Scenes/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ import RxSwift
import RxCocoa

struct HomeViewModel {
let disposeBag = DisposeBag()

let searchButtonTapped = PublishRelay<Void>()
let pushSearchViewController: Driver<SearchViewModel>

let noticeButtonTapped = PublishRelay<Void>()
let pushNoticeViewController: Driver<NoticeViewModel>

let filterButtonTapped = PublishRelay<Void>()

let recommendDetailButtonTapped = PublishRelay<Void>()
let pushRecommendDetailViewController: Driver<RecommendDetailViewModel>

let aroundDetailButtonTapped = PublishRelay<Void>()
let mapViewTapped = PublishSubject<Void>()
let pushAroundDetailViewController: Driver<AroundDetailViewModel>

init() {
let mapViewTapped = PublishSubject<Void>()

init(model: RestaurantListNetwork = RestaurantListNetwork()) {
let searchViewModel = SearchViewModel()
let noticeViewModel = NoticeViewModel()
let recommendDetailViewModel = RecommendDetailViewModel()
let aroundDetailViewModel = AroundDetailViewModel()

self.pushSearchViewController = searchButtonTapped
.map { return searchViewModel }
Expand All @@ -31,5 +40,15 @@ struct HomeViewModel {
self.pushNoticeViewController = noticeButtonTapped
.map { return noticeViewModel }
.asDriver(onErrorDriveWith: .empty())

self.pushRecommendDetailViewController = recommendDetailButtonTapped
.map { return recommendDetailViewModel }
.asDriver(onErrorDriveWith: .empty())

self.pushAroundDetailViewController = aroundDetailButtonTapped
.map { return aroundDetailViewModel }
.asDriver(onErrorDriveWith: .empty())

}

}
Loading

0 comments on commit 249f52c

Please sign in to comment.