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 #58 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 Jul 10, 2022
2 parents 7e92355 + 389fc76 commit c03a203
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 125 deletions.
16 changes: 12 additions & 4 deletions EatDa.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
FD94861427A955F6009BE666 /* FilterSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861327A955F6009BE666 /* FilterSectionView.swift */; };
FD94861627A95987009BE666 /* RecommendSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861527A95987009BE666 /* RecommendSectionView.swift */; };
FD94861827A9598C009BE666 /* AroundSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861727A9598C009BE666 /* AroundSectionView.swift */; };
FD94861D27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861B27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift */; };
FD94861D27A959EF009BE666 /* AroundCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861B27A959EF009BE666 /* AroundCollectionViewCell.swift */; };
FD94861E27A959EF009BE666 /* SeperatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD94861C27A959EF009BE666 /* SeperatorView.swift */; };
FD9C6F3427BFD04A005D88A6 /* AppleSDGothicNeoB.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FD9C6F3027BFD035005D88A6 /* AppleSDGothicNeoB.ttf */; };
FD9C6F3527BFD04C005D88A6 /* AppleSDGothicNeoEB.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FD9C6F3327BFD035005D88A6 /* AppleSDGothicNeoEB.ttf */; };
Expand All @@ -83,6 +83,8 @@
FDB7906E2805A783008621D1 /* ReviewFeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD0CF62C27A12BDA00BDEA53 /* ReviewFeedViewController.swift */; };
FDBC11E3285D7C4500FCADF4 /* LikeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBC11E2285D7C4500FCADF4 /* LikeViewModel.swift */; };
FDBC11E5285D85BF00FCADF4 /* BasicModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBC11E4285D85BF00FCADF4 /* BasicModel.swift */; };
FDBC12082868135E00FCADF4 /* AroundDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBC12072868135E00FCADF4 /* AroundDetailViewModel.swift */; };
FDBC120A2868162400FCADF4 /* AroundCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDBC12092868162400FCADF4 /* AroundCollectionView.swift */; };
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 */; };
Expand Down Expand Up @@ -171,7 +173,7 @@
FD94861327A955F6009BE666 /* FilterSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterSectionView.swift; sourceTree = "<group>"; };
FD94861527A95987009BE666 /* RecommendSectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecommendSectionView.swift; sourceTree = "<group>"; };
FD94861727A9598C009BE666 /* AroundSectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AroundSectionView.swift; sourceTree = "<group>"; };
FD94861B27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AroundRestaurantCollectionViewCell.swift; sourceTree = "<group>"; };
FD94861B27A959EF009BE666 /* AroundCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AroundCollectionViewCell.swift; sourceTree = "<group>"; };
FD94861C27A959EF009BE666 /* SeperatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SeperatorView.swift; sourceTree = "<group>"; };
FD9C6F2F27BFD035005D88A6 /* AppleSDGothicNeoM.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = AppleSDGothicNeoM.ttf; sourceTree = "<group>"; };
FD9C6F3027BFD035005D88A6 /* AppleSDGothicNeoB.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = AppleSDGothicNeoB.ttf; sourceTree = "<group>"; };
Expand All @@ -194,6 +196,8 @@
FDB7906C2805A704008621D1 /* RestaurantTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantTableViewCell.swift; sourceTree = "<group>"; };
FDBC11E2285D7C4500FCADF4 /* LikeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LikeViewModel.swift; sourceTree = "<group>"; };
FDBC11E4285D85BF00FCADF4 /* BasicModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicModel.swift; sourceTree = "<group>"; };
FDBC12072868135E00FCADF4 /* AroundDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundDetailViewModel.swift; sourceTree = "<group>"; };
FDBC12092868162400FCADF4 /* AroundCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundCollectionView.swift; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -508,7 +512,8 @@
children = (
FDE307242843433100EA15CF /* AroundDetail */,
FD94861727A9598C009BE666 /* AroundSectionView.swift */,
FD94861B27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift */,
FD94861B27A959EF009BE666 /* AroundCollectionViewCell.swift */,
FDBC12092868162400FCADF4 /* AroundCollectionView.swift */,
);
path = AroundView;
sourceTree = "<group>";
Expand Down Expand Up @@ -590,6 +595,7 @@
isa = PBXGroup;
children = (
FDEA5E3927EF10CD008EFD5E /* AroundDetailViewController.swift */,
FDBC12072868135E00FCADF4 /* AroundDetailViewModel.swift */,
);
path = AroundDetail;
sourceTree = "<group>";
Expand Down Expand Up @@ -866,7 +872,7 @@
F03FB66127B0333D0097D817 /* UILabel.swift in Sources */,
FD022E3E2833692100FC32E9 /* MapViewController.swift in Sources */,
FD0CF62B27A12BC400BDEA53 /* TalkViewController.swift in Sources */,
FD94861D27A959EF009BE666 /* AroundRestaurantCollectionViewCell.swift in Sources */,
FD94861D27A959EF009BE666 /* AroundCollectionViewCell.swift in Sources */,
FDEA5E3E27F04620008EFD5E /* RecommendDetailViewModel.swift in Sources */,
FDE3073A2846411A00EA15CF /* RestaurantListNetwork.swift in Sources */,
FDB40687283E14D5003C70A8 /* TokenUtils.swift in Sources */,
Expand All @@ -875,10 +881,12 @@
F0224C44282970840092683A /* RegistCompleteViewController.swift in Sources */,
F0128D3A281E5531005BE0B9 /* LoginViewController.swift in Sources */,
FD63EA9B27CCEDEB00DFBD0B /* LikeHeaderView.swift in Sources */,
FDBC120A2868162400FCADF4 /* AroundCollectionView.swift in Sources */,
F0CB9834284734D1002FCD94 /* ChangeProfileViewController.swift in Sources */,
FDE307602847422A00EA15CF /* SearchDetailViewController.swift in Sources */,
FDE37EAD27D389C400618163 /* SearchViewController.swift in Sources */,
FD94861427A955F6009BE666 /* FilterSectionView.swift in Sources */,
FDBC12082868135E00FCADF4 /* AroundDetailViewModel.swift in Sources */,
F0224C422829704C0092683A /* EnterNicknameViewController.swift in Sources */,
FDF78A2527EB421B005D37C8 /* NoticeViewController.swift in Sources */,
F03D976827DDC4A10011FA3D /* BestBoardTVC.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion EatDa/Global/Network/Entities/RestaurantListModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct RestaurantListModel: Decodable {
let name: String?
let explanation: String?
let imgUrl: String?
let distance: Int?
let distance: Double?
let hashTags: [String]
let liked: Bool
}
9 changes: 5 additions & 4 deletions EatDa/Global/Network/Service/RestaurantListNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import RxSwift
import Alamofire

struct RestaurantListNetwork {
let disposeBag = DisposeBag()
Expand Down Expand Up @@ -36,10 +37,10 @@ struct RestaurantListNetwork {
return apiCall.fetchWithRx()
}

// func getAroundRestaurantValue() -> Observable<[RestaurantListData]> {
// let apiCall = API<[RestaurantListData]>(url: APIConstants.GET_AROUND_RESTAURANT, method: .get, parameters: ["page": 1])
// return apiCall.fetchWithRx()
// }
func getAroundRestaurantValue(body: Parameters) -> Observable<[RestaurantListModel]> {
let apiCall = API<[RestaurantListModel]>(url: APIConstants.GET_AROUND_RESTAURANT, method: .post, parameters: body)
return apiCall.fetchWithRx()
}

func getRestaurantDetailValue(_ id: Int) -> Observable<RestaurantDetailModel> {
let apiCall = API<RestaurantDetailModel>(url: APIConstants.GET_RESTAURANT_DETAIL + "\(id)", method: .get, parameters: [:])
Expand Down
14 changes: 7 additions & 7 deletions EatDa/Scenes/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ class HomeViewController: UIViewController {
})
.disposed(by: disposeBag)

// viewModel.pushAroundDetailViewController
// .drive(onNext: { viewModel in
// 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
Expand Down
11 changes: 5 additions & 6 deletions EatDa/Scenes/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ struct HomeViewModel {
let collectionViewTapped = PublishRelay<Void>()
let pushCollectionViewController: Driver<RecommendDetailViewModel>

//let pushAroundDetailViewController: Driver<AroundDetailViewModel>
let pushAroundDetailViewController: Driver<AroundDetailViewModel>

let mapViewTapped = PublishSubject<Void>()

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

// let aroundDetailViewModel = AroundDetailViewModel()
let aroundDetailViewModel = AroundDetailViewModel()

self.pushSearchViewController = searchButtonTapped
.map { return searchViewModel }
Expand All @@ -54,9 +53,9 @@ struct HomeViewModel {
.map { return recommendDetailViewModel }
.asDriver(onErrorDriveWith: .empty())

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

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AroundCollectionView.swift
// EatDa
//
// Created by 김나희 on 6/26/22.
//

import RxSwift
import RxCocoa

final class AroundCollectionView: UICollectionView {
let disposeBag = DisposeBag()

override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.sectionInset = UIEdgeInsets(top: 0.0, left: 14.68, bottom: 0.0, right: 16.0)
layout.itemSize = CGSize(width: AroundCollectionViewCell.width , height: AroundCollectionViewCell.height)

super.init(frame: frame, collectionViewLayout: layout)

attribute()
bind(RestaurantListViewModel())
}


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

func attribute() {
self.backgroundColor = .systemBackground
self.showsHorizontalScrollIndicator = false
self.register(AroundCollectionViewCell.self, forCellWithReuseIdentifier: "AroundCollectionViewCell")
}


func bind(_ viewModel: RestaurantListViewModel) {
viewModel.aroundRestaurantData
.drive(self.rx.items) { collectionView, row, data in
let indexPath = IndexPath(row: row, section: 0)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AroundCollectionViewCell", for: indexPath) as! AroundCollectionViewCell
cell.setData(data)

return cell
}
.disposed(by: disposeBag)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit
import SnapKit

final class AroundRestaurantCollectionViewCell: UICollectionViewCell{
final class AroundCollectionViewCell: UICollectionViewCell{
static var width: CGFloat { 180.0 }
static var height: CGFloat { 250.0 }

Expand Down Expand Up @@ -56,13 +56,21 @@ final class AroundRestaurantCollectionViewCell: UICollectionViewCell{
return label
}()

func setup(){
override func layoutSubviews() {
super.layoutSubviews()

setupLayout()
}

func setData(_ data: RestaurantListModel){
self.titleLabel.text = data.name ?? ""
self.descriptionLabel.text = data.explanation ?? ""
//self.hashTagLabel.text = data.hashTags ?? ""
}
}


private extension AroundRestaurantCollectionViewCell {
private extension AroundCollectionViewCell {
func setupLayout(){

self.backgroundColor = .white
Expand All @@ -89,7 +97,7 @@ private extension AroundRestaurantCollectionViewCell {
}

titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().inset(12.0)
$0.leading.trailing.equalToSuperview().inset(12.0)
$0.top.equalTo(imageView.snp.bottom).offset(12.0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
//

import UIKit
import RxSwift

final class AroundDetailViewController: UIViewController {

let disposeBag = DisposeBag()

// MARK: - UIComponent
private lazy var searchBarButton: UIBarButtonItem = {
let button = UIBarButtonItem()
Expand All @@ -22,66 +24,32 @@ final class AroundDetailViewController: UIViewController {
return button
}()

private lazy var emptyHeaderView: UITableViewHeaderFooterView = {
let headerView = UITableViewHeaderFooterView()
return headerView
}()

private lazy var aroundTableView: UITableView = {
let tableview = UITableView()
tableview.backgroundColor = .systemBackground
tableview.rowHeight = 87.34
tableview.separatorColor = .lightGray
tableview.tableHeaderView = emptyHeaderView

// api 연결할때 rx로 코드 변경할 예정
tableview.delegate = self
tableview.dataSource = self

tableview.register(RestaurantTableViewCell.self, forCellReuseIdentifier: "RestaurantTableViewCell")

return tableview
}()

let listView = RestaurantListView()

override func loadView() {
super.loadView()
self.view = listView
}

override func viewDidLoad() {
super.viewDidLoad()
setLayout()
setNavigation()
}


}

extension AroundDetailViewController: UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RestaurantTableViewCell", for: indexPath) as? RestaurantTableViewCell
cell?.separatorInset = UIEdgeInsets.zero
cell?.setupLayout()

return cell ?? UITableViewCell()
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 97.34
func bind(_ viewModel: AroundDetailViewModel) {
listView.bindAroundRestaurantData(viewModel.listViewModel)
listView.rx.modelSelected(RestaurantListModel.self)
.subscribe(onNext: { model in
print(">> ", model.id)
}).disposed(by: disposeBag)
}

}


private extension AroundDetailViewController {
func setLayout() {
setNavigation()
view.addSubview(aroundTableView)
aroundTableView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview()
$0.top.equalToSuperview().inset(30.0)
}
}

func setNavigation() {
self.navigationItem.title = "주변 맛집"
self.navigationItem.title = "추천 맛집"
self.navigationItem.rightBarButtonItems = [noticeBarButton, searchBarButton]
let backButtonImage = UIImage(named: "back")?.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: -15, bottom: 0, right: 0))
self.navigationController?.navigationBar.backIndicatorImage = backButtonImage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AroundDetailViewModel.swift
// EatDa
//
// Created by 김나희 on 6/26/22.
//

import Foundation
import RxSwift

struct AroundDetailViewModel {
let listViewModel = RestaurantListViewModel()
}
Loading

0 comments on commit c03a203

Please sign in to comment.