Skip to content

Commit

Permalink
feat: 위시리스트 실제 데이터 반영 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhnSangHee committed Jun 11, 2022
1 parent 7d17c72 commit 5610a6d
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 10 deletions.
12 changes: 12 additions & 0 deletions iOS/airbnb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
D00B74652852503800B31424 /* WishListResponseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B74642852503800B31424 /* WishListResponseData.swift */; };
D00B74692852526200B31424 /* SearchLocationResponseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B74682852526200B31424 /* SearchLocationResponseData.swift */; };
D00B746D2852BBBE00B31424 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B746C2852BBBE00B31424 /* Constant.swift */; };
D00B7486285332E500B31424 /* WishListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B7485285332E500B31424 /* WishListViewModel.swift */; };
D01D65EF283C70710067B5E1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65EE283C70710067B5E1 /* AppDelegate.swift */; };
D01D65F1283C70710067B5E1 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65F0283C70710067B5E1 /* SceneDelegate.swift */; };
D01D65F3283C70710067B5E1 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65F2283C70710067B5E1 /* MainViewController.swift */; };
Expand Down Expand Up @@ -128,6 +129,7 @@
D00B74642852503800B31424 /* WishListResponseData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WishListResponseData.swift; sourceTree = "<group>"; };
D00B74682852526200B31424 /* SearchLocationResponseData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchLocationResponseData.swift; sourceTree = "<group>"; };
D00B746C2852BBBE00B31424 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
D00B7485285332E500B31424 /* WishListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WishListViewModel.swift; sourceTree = "<group>"; };
D01D65EB283C70710067B5E1 /* airbnb.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = airbnb.app; sourceTree = BUILT_PRODUCTS_DIR; };
D01D65EE283C70710067B5E1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D01D65F0283C70710067B5E1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -297,6 +299,13 @@
path = Model;
sourceTree = "<group>";
};
D00B747A2852E72F00B31424 /* Network */ = {
isa = PBXGroup;
children = (
);
path = Network;
sourceTree = "<group>";
};
D01D65E2283C70710067B5E1 = {
isa = PBXGroup;
children = (
Expand All @@ -323,6 +332,7 @@
D01D65ED283C70710067B5E1 /* airbnb */ = {
isa = PBXGroup;
children = (
D00B747A2852E72F00B31424 /* Network */,
D068BCF528406D7700EF783E /* App */,
D01D662E283D3A050067B5E1 /* Common */,
D01D6624283CB50E0067B5E1 /* Present */,
Expand Down Expand Up @@ -514,6 +524,7 @@
D0D29A1E284F4300009D1608 /* WishListCollectionViewDataSource.swift */,
D0D299F0284F1D4D009D1608 /* WishListFlowCoordinator.swift */,
D01D6627283CB5550067B5E1 /* WishListViewController.swift */,
D00B7485285332E500B31424 /* WishListViewModel.swift */,
);
path = WishList;
sourceTree = "<group>";
Expand Down Expand Up @@ -815,6 +826,7 @@
D00B742E285059C900B31424 /* CalendarCollectionViewDataSource.swift in Sources */,
D0D299DC284CB88A009D1608 /* CommonCollectionViewCell.swift in Sources */,
D089E80528460B4C0000AE78 /* MainSectionDiffableDataSource.swift in Sources */,
D00B7486285332E500B31424 /* WishListViewModel.swift in Sources */,
D0D299FD284F2498009D1608 /* WishListCollectionViewCell.swift in Sources */,
D089E80B284621770000AE78 /* SearchDiffableDataSource.swift in Sources */,
D087289D283F0DB9009983A5 /* CustomButton.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions iOS/airbnb/Common/Model/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ import Foundation

struct Constant {
static let urlString = "http://52.79.106.69:8080"
static let tempToken = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJteWJsb29tIn0.16uZEJLejIvHUuYrUtcbiu6RbtFluK0mW837R0a9BP0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct WishListData: Codable {
let accommodationId: Int
let name: String
let price: Int
let imageUrls: [String]
let imagesUrls: [String]
let wishId: Int
let isWish: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import UIKit
class WishListCollectionViewCell: CommonCollectionViewCell {

func configure(with cell: WishListModel) {
self.accomodationImageView.image = cell.image
let imgUrl = cell.imageUrls?.randomElement() ?? ""

if imgUrl.count > 0 {
DispatchQueue.global().async {
if let data = try? Data(contentsOf: URL(string: imgUrl)!) {
let img = UIImage(data: data)

DispatchQueue.main.async {
self.accomodationImageView.image = img
}
}
}
}
self.ratingLabel.text = "\(cell.rating ?? 0)"
self.reviewCountingLabel.text = "(후기 \(cell.reviewCount ?? 0)개)"
self.accomodationNameLabel.text = cell.accomodationName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
// Created by 안상희 on 2022/06/07.
//

import Alamofire
import UIKit

final class WishListCollectionViewDataSource: NSObject, UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return MockDataModel.mockWishListItems.count
return !wishListItems.isEmpty ? wishListItems.count: MockDataModel.mockWishListItems.count
}

func collectionView(_ collectionView: UICollectionView,
Expand All @@ -21,8 +22,20 @@ final class WishListCollectionViewDataSource: NSObject, UICollectionViewDataSour
return UICollectionViewCell()
}

if !wishListItems.isEmpty {
let item = wishListItems[indexPath.item]
cell.configure(with: item)
return cell
}

let item = MockDataModel.mockWishListItems[indexPath.item]
cell.configure(with: item)
return cell
}

init(wishListItems: [WishListModel]) {
self.wishListItems = wishListItems
}

private var wishListItems: [WishListModel]
}
24 changes: 17 additions & 7 deletions iOS/airbnb/Present/WishList/WishListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ final class WishListViewController: UIViewController {
var coordinate: WishListFlow?

private var wishListCollectionView: UICollectionView! = nil
private var dataSource = WishListCollectionViewDataSource()
private lazy var dataSource: WishListCollectionViewDataSource = {
let dataSource =
WishListCollectionViewDataSource(wishListItems:
wishListItems ?? MockDataModel.mockWishListItems)
return dataSource
}()

private let viewModel = WishListViewModel()
private var wishListItems: [WishListModel]?

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white

configureCollectionView()
configureDataSource()

configure()

getWishList()
viewModel.getWishList {
self.wishListItems = self.viewModel.wishListItems

self.configureCollectionView()
self.configureDataSource()

self.configure()
}
}

private func configure() {
Expand Down
50 changes: 50 additions & 0 deletions iOS/airbnb/Present/WishList/WishListViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// WishListViewModel.swift
// airbnb
//
// Created by 안상희 on 2022/06/10.
//

import Alamofire
import Foundation

class WishListViewModel {
var wishListItems = [WishListModel]()

private func dataToModel(responseData: WishListResponseData) {
for data in responseData.data {
let rating = Double.random(in: 3.00...5.00)
let reviewCount = Int.random(in: 1...100)
let model = WishListModel(id: data.wishId,
imageUrls: data.imagesUrls,
rating: round(rating * 100) / 100,
reviewCount: reviewCount,
accomodationName: data.name,
price: data.price)
wishListItems.append(model)
}
}

func getWishList(completion: @escaping () -> Void) {
let url = "\(Constant.urlString)/api/wishlist?customerId=1"
AF.request(url,
method: .get,
parameters: nil,
encoding: URLEncoding.default,
headers: [
"Authorization": Constant.tempToken,
"Content-Type": "application/json",
"Accept": "application/json"])
.validate(statusCode: 200..<300)
.responseDecodable(of: WishListResponseData.self) { response in
switch response.result {
case .success(let response):
self.dataToModel(responseData: response)
completion()
case .failure(let error):
print(error.localizedDescription)
}
}

}
}

0 comments on commit 5610a6d

Please sign in to comment.