Skip to content

Commit

Permalink
[Feat] Health-Food-Me#205 - 데이터 바인딩 옵셔널로 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
L-j-h-c committed Jul 22, 2022
1 parent 7a0c04d commit 392fac4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@ struct MainDetailEntity: Codable {

// MARK: - Menu
struct Menu: Codable {
let id, name: String
let id, name: String?
let image: String?
let kcal, per: Int?
let price: Int
let isPick: Bool
let kcal: Double?
let per: Int?
let price: Int?
let isPick: Bool?

enum CodingKeys: String, CodingKey {
case id = "_id"
case name, image, kcal, per, price, isPick
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

id = (try? container.decode(String.self, forKey: .id)) ?? ""
name = (try? container.decode(String.self, forKey: .name)) ?? ""
image = (try? container.decode(String.self, forKey: .image)) ?? ""
kcal = (try? container.decode(Double.self, forKey: .kcal)) ?? 0
per = (try? container.decode(Int.self, forKey: .per)) ?? 0
price = (try? container.decode(Int.self, forKey: .price)) ?? 0
isPick = (try? container.decode(Bool.self, forKey: .isPick)) ?? false
}

func toDomain() -> MenuDataModel {
var imageURL: String?
var perText: String?
Expand All @@ -39,7 +52,16 @@ struct Menu: Codable {
} else {
perText = nil
}
return MenuDataModel.init(restaurantID: id, isPick: isPick, memuImageURL: imageURL, menuName: name, menuPrice: price, menuKcal: kcal, carbohydrates: nil, protein: nil, fat: nil, per: perText)
return MenuDataModel.init(restaurantID: id ?? "",
isPick: isPick ?? false,
memuImageURL: imageURL,
menuName: name ?? "",
menuPrice: price ?? 0,
menuKcal: kcal,
carbohydrates: nil,
protein: nil,
fat: nil,
per: perText)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class BaseService {

switch decodingMode {
case .model:
print("여기여기")
dump(decodedData)
return .success(decodedData.data ?? "None-Data")

case .message:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@ extension MainDetailVC {
RestaurantService.shared.fetchRestaurantDetail(restaurantId: restaurantId, userId: UserManager.shared.getUser ?? "", latitude: location.latitude, longitude: location.longitude) { networkResult in
switch networkResult {
case .success(let data):
dump(data)
print("옵셔널")
if let data = data as? MainDetailEntity {
print("성공")
self.navigationTitle = data.restaurant.name
self.restaurantName = data.restaurant.name
self.mainInfoTVC.isInitialReload = self.mainInfoInitialReload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ extension MenuCellCVC {
menuView.kcalView.isHidden = true
} else {
guard let menuKcal = menuData.menuKcal else { return }
menuView.kcalLabel.text = "\(menuKcal)"
let intKcal = Int(menuKcal)
menuView.kcalLabel.text = "\(intKcal)"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct MenuDataModel: Codable {
let memuImageURL: String?
let menuName: String
let menuPrice: Int
let menuKcal: Int?
let menuKcal: Double?
let carbohydrates: Int?
let protein: Int?
let fat: Int?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class MainMapVC: UIViewController, NMFLocationManagerDelegate {
setMapView()
addObserver()
self.bindViewModels()

let temp: Double = 116.40000000000001
}

override func viewWillAppear(_ animated: Bool) {
Expand Down

0 comments on commit 392fac4

Please sign in to comment.