forked from codesquad-members-2022/airbnb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d17c72
commit 5610a6d
Showing
7 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
||
} | ||
} |