From fb47ad1c56dd578b1aedb66be3b882929678dd00 Mon Sep 17 00:00:00 2001 From: doyeonk429 <80318425+doyeonk429@users.noreply.github.com> Date: Sat, 17 Aug 2024 03:18:15 +0900 Subject: [PATCH] #56 User Review API --- .../Search/ReviewListCollectionViewCell.swift | 4 +++- .../VCs/Search/ReviewListViewController.swift | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListCollectionViewCell.swift b/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListCollectionViewCell.swift index 76a42c0..c7ccb4a 100644 --- a/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListCollectionViewCell.swift +++ b/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListCollectionViewCell.swift @@ -10,7 +10,7 @@ import SnapKit class ReviewListCollectionViewCell: UICollectionViewCell { - var score: Double? = nil + var score: Double = 0.0 private let scoreLabel = UILabel() private let name: UILabel = { @@ -98,5 +98,7 @@ class ReviewListCollectionViewCell: UICollectionViewCell { self.name.text = review.name self.score = review.satisfaction self.content.text = review.review + + configureScore() } } diff --git a/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListViewController.swift b/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListViewController.swift index da2e2cb..b45661a 100644 --- a/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListViewController.swift +++ b/Drink-EG/Drink-EG/Sources/VCs/Search/ReviewListViewController.swift @@ -85,10 +85,17 @@ class ReviewListViewController: UIViewController { super.viewDidLoad() self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) - + view.backgroundColor = .white - getReviewList(query: self.wineId ?? 1) - setupUI() + getReviewList(query: self.wineId ?? 1) { [weak self] isSuccess in + if isSuccess { + self?.reviewListCollectionView.reloadData() + self?.setupUI() + } else { + print("GET 호출 실패") + } + } +// setupUI() } @@ -142,7 +149,7 @@ class ReviewListViewController: UIViewController { scoreLabel.font = .boldSystemFont(ofSize: 14) scoreLabel.textColor = UIColor(hex: "#FA735B") } - + } extension ReviewListViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { @@ -164,27 +171,28 @@ extension ReviewListViewController: UICollectionViewDataSource, UICollectionView return CGSize(width: collectionView.frame.width - 32, height: 110) } - func getReviewList(query: Int) { + func getReviewList(query: Int, completion: @escaping (Bool) -> Void) { provider.request(.getWineReview(wineId: query)) { result in switch result { case .success(let response): do { - if let jsonString = String(data: response.data, encoding: .utf8) { print("Received JSON: \(jsonString)") } - let responseData = try JSONDecoder().decode(APIResponseWineReviewResponse.self, from: response.data) self.reviewResults = responseData.result self.reviewListCollectionView.reloadData() + completion(true) } catch { print("Failed to decode response: \(error)") + completion(false) } case.failure(let error): print("Error: \(error.localizedDescription)") if let response = error.response { print("Response Body: \(String(data: response.data, encoding: .utf8) ?? "")") } + completion(false) } } }