From 8baee98ea47a21be2b2c04039393057f4b6c117b Mon Sep 17 00:00:00 2001 From: CJiu01 Date: Fri, 13 Dec 2024 18:49:32 +0900 Subject: [PATCH 1/2] [#189] change ChangeMenuTableResponse DTO --- .../Data/Network/DTO/Home/ChangeMenuTableResponse.swift | 6 +++--- .../RestaurantTableView/RestaurantTableViewMenuCell.swift | 8 ++++---- .../ViewController/HomeRestaurantViewController.swift | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/ChangeMenuTableResponse.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/ChangeMenuTableResponse.swift index 48ac4a7..32a973f 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/ChangeMenuTableResponse.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/ChangeMenuTableResponse.swift @@ -10,11 +10,11 @@ import Foundation struct ChangeMenuTableResponse: Codable { let mealId: Int? let price: Int? - let mainRating: Double? - var menusInformationList: [MenusInformation] + let rating: Double? + let briefMenus: [BriefMenus] } -struct MenusInformation: Codable { +struct BriefMenus: Codable { let menuId: Int let name: String } diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift index c1c53ea..75b1757 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift @@ -98,18 +98,18 @@ extension RestaurantTableViewMenuCell { case .change(let data): priceLabel.text = data.price != nil ? data.price?.formattedWithCommas : "" - if data.mainRating != nil { - let formatRating = String(format: "%.1f", data.mainRating ?? 0) + if data.rating != nil { + let formatRating = String(format: "%.1f", data.rating ?? 0) ratingLabel.text = formatRating } else { ratingLabel.text = TextLiteral.Home.emptyRating } - if data.menusInformationList.isEmpty { + if data.briefMenus.isEmpty { // vc에서 이미 필터링되어 의미 없음. 리팩 필요 nameLabel.text = "제공되는 메뉴가 없습니다" } else { - nameLabel.text = data.menusInformationList.map { $0.name }.joined(separator: "+") + nameLabel.text = data.briefMenus.map { $0.name }.joined(separator: "+") } case .fix(let data): diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift index 06b348d..6e9ce33 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift @@ -46,7 +46,7 @@ final class HomeRestaurantViewController: BaseViewController { // 빈 name을 가지지 않은 ChangeMenuTableResponse만 필터링 changeMenuTableViewData = changeMenuTableViewData.mapValues { menuTableResponses in menuTableResponses.filter { response in - !(response.menusInformationList.first?.name.isEmpty ?? true) + !(response.briefMenus.first?.name.isEmpty ?? true) } } @@ -263,7 +263,7 @@ extension HomeRestaurantViewController: UITableViewDelegate { if [0, 1, 2].contains(indexPath.section) { reviewMenuTypeInfo.menuType = "VARIABLE" reviewMenuTypeInfo.menuID = changeMenuTableViewData[restaurant]?[indexPath.row - restaurantTableViewMenuTitleCellCount].mealId ?? 100 - if let list = changeMenuTableViewData[restaurant]?[indexPath.row - restaurantTableViewMenuTitleCellCount].menusInformationList { + if let list = changeMenuTableViewData[restaurant]?[indexPath.row - restaurantTableViewMenuTitleCellCount].briefMenus { reviewMenuTypeInfo.changeMenuIDList = list.compactMap { $0.menuId } } } else if [3, 4, 5].contains(indexPath.section) { From ac2c3dbc970be276ecf8c3d7ead483d070501a7f Mon Sep 17 00:00:00 2001 From: CJiu01 Date: Fri, 13 Dec 2024 18:55:24 +0900 Subject: [PATCH 2/2] [#189] change FixedMenuTableResponse DTO --- .../DTO/Home/FixedMenuTableResponse.swift | 10 ++--- .../Presentation/Home/Enum/MenuTypeInfo.swift | 2 +- .../RestaurantTableViewMenuCell.swift | 2 +- .../HomeRestaurantViewController.swift | 42 +++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/FixedMenuTableResponse.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/FixedMenuTableResponse.swift index 6f4f141..a445080 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/FixedMenuTableResponse.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Data/Network/DTO/Home/FixedMenuTableResponse.swift @@ -8,17 +8,17 @@ import Foundation struct FixedMenuTableResponse: Codable { - let categoryMenuListCollection: [CategoryMenu] + let categoryMenuListCollection: [CategoryMenuListCollection] } -struct CategoryMenu: Codable { +struct CategoryMenuListCollection: Codable { let category: String - let menuInformationList: [MenuInformation] + let menus: [Menus] } -struct MenuInformation: Codable { +struct Menus: Codable { let menuId: Int let name: String - let mainRating: Double? let price: Int? + let rating: Double? } diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/Enum/MenuTypeInfo.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/Enum/MenuTypeInfo.swift index 8f5750f..5a96eb4 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/Enum/MenuTypeInfo.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/Enum/MenuTypeInfo.swift @@ -9,5 +9,5 @@ import Foundation enum MenuTypeInfo { case change(ChangeMenuTableResponse) - case fix(MenuInformation) + case fix(Menus) } diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift index 75b1757..4a323d5 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/View/RestaurantTableView/RestaurantTableViewMenuCell.swift @@ -115,7 +115,7 @@ extension RestaurantTableViewMenuCell { case .fix(let data): if let price = data.price { priceLabel.text = price.formattedWithCommas - let formatRating = String(format: "%.1f", data.mainRating ?? 0) + let formatRating = String(format: "%.1f", data.rating ?? 0) ratingLabel.text = formatRating != "0.0" ? formatRating : "-" nameLabel.text = data.name } else { diff --git a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift index 6e9ce33..33408ba 100644 --- a/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift +++ b/EATSSU_MVC/EATSSU_MVC/Sources/Presentation/Home/ViewController/HomeRestaurantViewController.swift @@ -34,13 +34,13 @@ final class HomeRestaurantViewController: BaseViewController { TextLiteral.studentRestaurant, TextLiteral.snackCorner] let restaurantButtonTitleToName = [TextLiteral.dormitoryRestaurant: "DORMITORY", - TextLiteral.dodamRestaurant: "DODAM", - TextLiteral.studentRestaurant: "HAKSIK", - TextLiteral.snackCorner: "SNACK_CORNER"] + TextLiteral.dodamRestaurant: "DODAM", + TextLiteral.studentRestaurant: "HAKSIK", + TextLiteral.snackCorner: "SNACK_CORNER"] var currentRestaurant = "" var isWeekend = false var isSelectable = false - + var changeMenuTableViewData: [String: [ChangeMenuTableResponse]] = [:] { didSet { // 빈 name을 가지지 않은 ChangeMenuTableResponse만 필터링 @@ -49,15 +49,15 @@ final class HomeRestaurantViewController: BaseViewController { !(response.briefMenus.first?.name.isEmpty ?? true) } } - + // 필터링된 데이터로 테이블 뷰 섹션을 새로고침 if let sectionIndex = getSectionIndex(for: currentRestaurant) { restaurantView.restaurantTableView.reloadSections([sectionIndex], with: .automatic) } } } - - var fixMenuTableViewData: [String: [MenuInformation]] = [:] { + + var fixMenuTableViewData: [String: [Menus]] = [:] { didSet { if let sectionIndex = getSectionIndex(for: currentRestaurant) { restaurantView.restaurantTableView.reloadSections([sectionIndex], with: .automatic) @@ -85,7 +85,7 @@ final class HomeRestaurantViewController: BaseViewController { override func configureUI() { view.addSubviews(restaurantView) } - + override func setLayout() { restaurantView.snp.makeConstraints { $0.edges.equalToSuperview() @@ -121,7 +121,7 @@ final class HomeRestaurantViewController: BaseViewController { Restaurant.snackCorner.identifier] return restaurantRawValue[section] } - + func fetchData(date: Date, time: String) { let formatDate = changeDateFormat(date: date) getChageMenuData(date: formatDate, restaurant: Restaurant.dormitoryRestaurant.identifier, time: time) {} @@ -130,14 +130,14 @@ final class HomeRestaurantViewController: BaseViewController { let weekday = Weekday.from(date: date) isWeekend = weekday.isWeekend - + if time == TextLiteral.lunchRawValue { - + if !FirebaseRemoteConfig.shared.isVacationPeriod && !weekday.isWeekend { getFixMenuData(restaurant: TextLiteral.snackCornerRawValue) {} } else { currentRestaurant = Restaurant.snackCorner.identifier - self.fixMenuTableViewData[Restaurant.snackCorner.identifier] = [MenuInformation(menuId: 0, name: "", mainRating: nil, price: nil)] + self.fixMenuTableViewData[Restaurant.snackCorner.identifier] = [Menus(menuId: 0, name: "", price: nil, rating: nil)] } } } @@ -170,7 +170,7 @@ extension HomeRestaurantViewController: UITableViewDataSource { } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - + /// Menu Title Cell if indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: RestaurantTableViewMenuTitleCell.identifier, for: indexPath) @@ -209,12 +209,12 @@ extension HomeRestaurantViewController: UITableViewDataSource { return cell } } - + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { guard let restaurantTableViewHeader = tableView.dequeueReusableHeaderFooterView(withIdentifier: RestaurantTableViewHeader.identifier) as? RestaurantTableViewHeader else { return nil } - + let restaurantName = sectionHeaderRestaurant[section] restaurantTableViewHeader.titleLabel.text = restaurantName @@ -241,7 +241,7 @@ extension HomeRestaurantViewController: UITableViewDataSource { } } - + // MARK: - UITableViewDelegate extension HomeRestaurantViewController: UITableViewDelegate { @@ -255,7 +255,7 @@ extension HomeRestaurantViewController: UITableViewDelegate { if indexPath.row == 0 { return } - + let restaurant = getSectionKey(for: indexPath.section) /// bind Data var reviewMenuTypeInfo: ReviewMenuTypeInfo = ReviewMenuTypeInfo(menuType: "", menuID: 0) @@ -281,9 +281,9 @@ extension HomeRestaurantViewController: UITableViewDelegate { delegate?.didDelegateReviewMenuTypeInfo(for: reviewMenuTypeInfo) } - -} +} + // MARK: - Network extension HomeRestaurantViewController { @@ -315,9 +315,9 @@ extension HomeRestaurantViewController { let responseDetailDto = try responseData.map(BaseResponse.self) let responseResult = responseDetailDto.result - var allMenuInformations = [MenuInformation]() + var allMenuInformations = [Menus]() for categoryMenu in responseResult.categoryMenuListCollection { - allMenuInformations += categoryMenu.menuInformationList + allMenuInformations += categoryMenu.menus } self.fixMenuTableViewData[restaurant] = allMenuInformations } catch(let err) {