Skip to content

Commit

Permalink
Merge pull request #200 from EAT-SSU/feat/#199
Browse files Browse the repository at this point in the history
[#199] 고정/변동메뉴 조회 DTO 변경사항 prod 적용
  • Loading branch information
CJiu01 authored Dec 19, 2024
2 parents 35cb05c + ac2c3db commit 3cedb99
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import Foundation

enum MenuTypeInfo {
case change(ChangeMenuTableResponse)
case fix(MenuInformation)
case fix(Menus)
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ 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):
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ 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만 필터링
changeMenuTableViewData = changeMenuTableViewData.mapValues { menuTableResponses in
menuTableResponses.filter { response in
!(response.menusInformationList.first?.name.isEmpty ?? true)
!(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)
Expand Down Expand Up @@ -85,7 +85,7 @@ final class HomeRestaurantViewController: BaseViewController {
override func configureUI() {
view.addSubviews(restaurantView)
}

override func setLayout() {
restaurantView.snp.makeConstraints {
$0.edges.equalToSuperview()
Expand Down Expand Up @@ -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) {}
Expand All @@ -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)]
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -241,7 +241,7 @@ extension HomeRestaurantViewController: UITableViewDataSource {
}

}

// MARK: - UITableViewDelegate

extension HomeRestaurantViewController: UITableViewDelegate {
Expand All @@ -255,15 +255,15 @@ extension HomeRestaurantViewController: UITableViewDelegate {
if indexPath.row == 0 {
return
}

let restaurant = getSectionKey(for: indexPath.section)
/// bind Data
var reviewMenuTypeInfo: ReviewMenuTypeInfo = ReviewMenuTypeInfo(menuType: "", menuID: 0)

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) {
Expand All @@ -281,9 +281,9 @@ extension HomeRestaurantViewController: UITableViewDelegate {

delegate?.didDelegateReviewMenuTypeInfo(for: reviewMenuTypeInfo)
}

}

}

// MARK: - Network

extension HomeRestaurantViewController {
Expand Down Expand Up @@ -315,9 +315,9 @@ extension HomeRestaurantViewController {
let responseDetailDto = try responseData.map(BaseResponse<FixedMenuTableResponse>.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) {
Expand Down

0 comments on commit 3cedb99

Please sign in to comment.