From 3d2a6da0a9345102fe06223972615a0c26197dc1 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 1 Nov 2021 17:18:50 +0900 Subject: [PATCH 01/29] =?UTF-8?q?feat:=20=EC=9E=AC=EA=B3=A0=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=ED=99=94=EB=A9=B4=20=EC=A7=84=EC=9E=85=EC=8B=9C=20?= =?UTF-8?q?Label,=20Stepper=EC=9D=98=20Value=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JuiceMakerViewController에 prepare 메소드 구현 - 현 재고의 갯수를 재고수정 화면에도 연동 기능 추가 - FruitStoreViewController 내부에 Stepper setup 관련 메소드 3개 구현 --- .../Controller/FruitStoreViewController.swift | 40 +++++++++++++++++++ .../Controller/JuiceMakerViewController.swift | 15 ++++++- .../View/Base.lproj/Main.storyboard | 16 +++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift index 235a9c4bd..5717bab0c 100644 --- a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift @@ -9,11 +9,51 @@ import UIKit class FruitStoreViewController: UIViewController { + var receivedText: String? + @IBOutlet weak var strawberryStockLabel: UILabel! + @IBOutlet weak var bananaStockLabel: UILabel! + @IBOutlet weak var pineappleStockLabel: UILabel! + @IBOutlet weak var kiwiStockLabel: UILabel! + @IBOutlet weak var mangoStockLabel: UILabel! + + @IBOutlet weak var strawberryStockStepper: UIStepper! + @IBOutlet weak var bananaStockStepper: UIStepper! + @IBOutlet weak var pineappleStockStepper: UIStepper! + @IBOutlet weak var kiwiStockStepper: UIStepper! + @IBOutlet weak var mangoStockStepper: UIStepper! + override func viewDidLoad() { super.viewDidLoad() + setUpFruitStepperValues() + } @IBAction func cancelButtonTapped(_ sender: UIButton) { self.dismiss(animated: true, completion: nil) } + + func setUpFruitStepperValues() { + currentStockStepperValueUpdate(fruit: .strawberry, stepper: strawberryStockStepper) + currentStockStepperValueUpdate(fruit: .banana, stepper: bananaStockStepper) + currentStockStepperValueUpdate(fruit: .pineapple, stepper: pineappleStockStepper) + currentStockStepperValueUpdate(fruit: .kiwi, stepper: kiwiStockStepper) + currentStockStepperValueUpdate(fruit: .mango, stepper: mangoStockStepper) + } + + func currentStockStepperValueUpdate(fruit: Fruit, stepper: UIStepper) { + do { + let stock = try FruitStore.shared.stock(fruit: fruit) + stepper.value = Double(stock) + } catch { + showNotificationAlert(message: Message.unknownError.description) + } + } + + func showNotificationAlert(message: String, title: String = Text.ok.title) { + let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) + let cancel = UIAlertAction(title: title, style: .cancel, handler: nil) + alert.addAction(cancel) + present(alert, animated: true, completion: nil) + } + } diff --git a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift index cec65319b..e1f8c2eb1 100644 --- a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift @@ -129,8 +129,21 @@ class JuiceMakerViewController: UIViewController { } private func presentFruitStoreViewController(_ action: UIAlertAction) { - guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreViewController") else { return } + guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreViewController") as? UINavigationController else { return } self.present(viewController, animated: true, completion: nil) } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + guard let navigationController = segue.destination as? UINavigationController else { return } + + guard let nextViewController = navigationController.topViewController as? FruitStoreViewController else { return } + + nextViewController.loadViewIfNeeded() + nextViewController.strawberryStockLabel.text = strawberryStockLabel.text + nextViewController.bananaStockLabel.text = bananaStockLabel.text + nextViewController.pineappleStockLabel.text = pineappleStockLabel.text + nextViewController.kiwiStockLabel.text = kiwiStockLabel.text + nextViewController.mangoStockLabel.text = mangoStockLabel.text + } } diff --git a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard index ccbbba830..bb745246f 100644 --- a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard +++ b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -430,6 +430,18 @@ + + + + + + + + + + + + From 1e85463e1eb13e807acbeebfba2095911821006d Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 1 Nov 2021 17:39:23 +0900 Subject: [PATCH 02/29] =?UTF-8?q?feat:=20FruitStore=EC=97=90=EC=84=9C=20La?= =?UTF-8?q?bel=EA=B3=BC=20Stepper=EC=9D=98=20=EA=B0=92=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=20=EB=B0=8F=20Stepper=20=ED=84=B0=EC=B9=98=20?= =?UTF-8?q?=EC=8B=9C=20Label=20=EA=B0=92=20=EB=B3=80=ED=99=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/FruitStoreViewController.swift | 18 +++++++++++++++++- .../View/Base.lproj/Main.storyboard | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift index 5717bab0c..2a269be81 100644 --- a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift @@ -32,6 +32,23 @@ class FruitStoreViewController: UIViewController { self.dismiss(animated: true, completion: nil) } + @IBAction func stepperTapped(_ sender: UIStepper) { + switch sender { + case strawberryStockStepper: + strawberryStockLabel.text = String(format: "%.0f", sender.value) + case bananaStockStepper: + bananaStockLabel.text = String(format: "%.0f", sender.value) + case pineappleStockStepper: + pineappleStockLabel.text = String(format: "%.0f", sender.value) + case kiwiStockStepper: + kiwiStockLabel.text = String(format: "%.0f", sender.value) + case mangoStockStepper: + mangoStockLabel.text = String(format: "%.0f", sender.value) + default: + showNotificationAlert(message: Message.unknownError.description) + } + } + func setUpFruitStepperValues() { currentStockStepperValueUpdate(fruit: .strawberry, stepper: strawberryStockStepper) currentStockStepperValueUpdate(fruit: .banana, stepper: bananaStockStepper) @@ -55,5 +72,4 @@ class FruitStoreViewController: UIViewController { alert.addAction(cancel) present(alert, animated: true, completion: nil) } - } diff --git a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard index bb745246f..6eb797fec 100644 --- a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard +++ b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -309,6 +309,9 @@ + + + @@ -333,6 +336,9 @@ + + + @@ -357,6 +363,9 @@ + + + @@ -381,6 +390,9 @@ + + + @@ -405,6 +417,9 @@ + + + From df7531a74a74e8afd5ae183c8f4bc2301d58b8cd Mon Sep 17 00:00:00 2001 From: Ari Date: Tue, 2 Nov 2021 11:34:10 +0900 Subject: [PATCH 03/29] =?UTF-8?q?feat:=20Stepper=EB=A5=BC=20=ED=81=B4?= =?UTF-8?q?=EB=A6=AD=EC=8B=9C=20=EC=9E=AC=EA=B3=A0=EA=B0=80=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=EB=90=98=EB=8F=84=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stepperTapped 내부에 계산하는 로직 추가 - 계산과 관련된 메서드 3개 추가 (fruitStockChange, chooseCalculator, calculateFruitStock) --- .../Controller/FruitStoreViewController.swift | 36 +++++++++++++++++++ .../View/Base.lproj/Main.storyboard | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift index 2a269be81..f67def40d 100644 --- a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift @@ -36,14 +36,19 @@ class FruitStoreViewController: UIViewController { switch sender { case strawberryStockStepper: strawberryStockLabel.text = String(format: "%.0f", sender.value) + fruitStockChange(fruit: .strawberry, value: sender.value) case bananaStockStepper: bananaStockLabel.text = String(format: "%.0f", sender.value) + fruitStockChange(fruit: .banana, value: sender.value) case pineappleStockStepper: pineappleStockLabel.text = String(format: "%.0f", sender.value) + fruitStockChange(fruit: .pineapple, value: sender.value) case kiwiStockStepper: kiwiStockLabel.text = String(format: "%.0f", sender.value) + fruitStockChange(fruit: .kiwi, value: sender.value) case mangoStockStepper: mangoStockLabel.text = String(format: "%.0f", sender.value) + fruitStockChange(fruit: .mango, value: sender.value) default: showNotificationAlert(message: Message.unknownError.description) } @@ -72,4 +77,35 @@ class FruitStoreViewController: UIViewController { alert.addAction(cancel) present(alert, animated: true, completion: nil) } + + func fruitStockChange(fruit: Fruit, value: Double) { + let oldStockValue: Int + let newStockValue = Int(value) + do { + oldStockValue = try FruitStore.shared.stock(fruit: fruit) + chooseCalculator(fruit: fruit, oldStockValue: oldStockValue, newStockValue: newStockValue) + } catch { + showNotificationAlert(message: Message.unknownError.description) + } + + } + + func chooseCalculator(fruit: Fruit, oldStockValue: Int, newStockValue: Int) { + switch oldStockValue < newStockValue { + case true: + let count = newStockValue - oldStockValue + calculateFruitStock(fruit: fruit, count: count, calculate: FruitStore.shared.addFruitStock) + case false: + let count = oldStockValue - newStockValue + calculateFruitStock(fruit: fruit, count: count, calculate: FruitStore.shared.subtractFruitStock) + } + } + + func calculateFruitStock(fruit: Fruit, count: Int, calculate: (Fruit, Int) throws -> Void ) { + do { + try calculate(fruit, count) + } catch { + showNotificationAlert(message: Message.unknownError.description) + } + } } diff --git a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard index 6eb797fec..62f398e0c 100644 --- a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard +++ b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + From 23a4bdc9f79908e574267e6a1df7a2531d9ab75e Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 2 Nov 2021 11:38:13 +0900 Subject: [PATCH 04/29] =?UTF-8?q?fix:=20FruitStore=EC=9D=98=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=EB=90=9C=20=EC=A1=B0=EA=B1=B4=EB=AC=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JuiceMaker/JuiceMaker/Model/FruitStore.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Model/FruitStore.swift b/JuiceMaker/JuiceMaker/Model/FruitStore.swift index 3cefda0bd..788136030 100644 --- a/JuiceMaker/JuiceMaker/Model/FruitStore.swift +++ b/JuiceMaker/JuiceMaker/Model/FruitStore.swift @@ -52,10 +52,10 @@ class FruitStore { guard let oldFruitCount = fruitBasket[fruit] else { throw RequestError.fruitNotFound } - guard count <= oldFruitCount else { + let newFruitCount = calculator(oldFruitCount, count) + guard newFruitCount >= 0 else { throw RequestError.fruitStockOut } - let newFruitCount = calculator(oldFruitCount, count) fruitBasket[fruit] = newFruitCount NotificationCenter.default.post(name: .changedFruitStockNotification, object: fruit) From febd113421afe1bbdef162f187f49ed257acfb63 Mon Sep 17 00:00:00 2001 From: Ari Date: Tue, 2 Nov 2021 11:39:59 +0900 Subject: [PATCH 05/29] =?UTF-8?q?fix:=20=EC=9E=AC=EA=B3=A0=20=EB=B6=80?= =?UTF-8?q?=EC=A1=B1=EC=8B=9C=20=EC=9E=AC=EA=B3=A0=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=84=98=EC=96=B4=EA=B0=88=20=EB=95=8C=20?= =?UTF-8?q?Label=20=EB=B0=98=EC=98=81=20=EC=95=88=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JuiceMaker/Controller/JuiceMakerViewController.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift index e1f8c2eb1..e725b3217 100644 --- a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift @@ -131,6 +131,15 @@ class JuiceMakerViewController: UIViewController { private func presentFruitStoreViewController(_ action: UIAlertAction) { guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreViewController") as? UINavigationController else { return } self.present(viewController, animated: true, completion: nil) + + guard let nextViewController = viewController.topViewController as? FruitStoreViewController else { return } + + nextViewController.loadViewIfNeeded() + nextViewController.strawberryStockLabel.text = strawberryStockLabel.text + nextViewController.bananaStockLabel.text = bananaStockLabel.text + nextViewController.pineappleStockLabel.text = pineappleStockLabel.text + nextViewController.kiwiStockLabel.text = kiwiStockLabel.text + nextViewController.mangoStockLabel.text = mangoStockLabel.text } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { From bd2ac4240c945b4b2625f2f98d663c078cf579e8 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 2 Nov 2021 11:43:46 +0900 Subject: [PATCH 06/29] =?UTF-8?q?refactor:=20JuiceMakerViewController?= =?UTF-8?q?=EC=9D=98=20=EC=A4=91=EB=B3=B5=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EB=B9=BC=EC=A3=BC=EC=96=B4=20=EB=A9=94=EC=86=8C=EB=93=9C=20set?= =?UTF-8?q?upNextViewLabel(of:)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/JuiceMakerViewController.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift index e725b3217..f89e04b9b 100644 --- a/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift @@ -134,12 +134,7 @@ class JuiceMakerViewController: UIViewController { guard let nextViewController = viewController.topViewController as? FruitStoreViewController else { return } - nextViewController.loadViewIfNeeded() - nextViewController.strawberryStockLabel.text = strawberryStockLabel.text - nextViewController.bananaStockLabel.text = bananaStockLabel.text - nextViewController.pineappleStockLabel.text = pineappleStockLabel.text - nextViewController.kiwiStockLabel.text = kiwiStockLabel.text - nextViewController.mangoStockLabel.text = mangoStockLabel.text + setupNextViewLabel(of: nextViewController) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -147,6 +142,10 @@ class JuiceMakerViewController: UIViewController { guard let nextViewController = navigationController.topViewController as? FruitStoreViewController else { return } + setupNextViewLabel(of: nextViewController) + } + + func setupNextViewLabel(of nextViewController: FruitStoreViewController) { nextViewController.loadViewIfNeeded() nextViewController.strawberryStockLabel.text = strawberryStockLabel.text nextViewController.bananaStockLabel.text = bananaStockLabel.text From 9b545cf21e8fe2f4f51801d46b3f48316f0d9092 Mon Sep 17 00:00:00 2001 From: Ari Date: Tue, 2 Nov 2021 11:46:44 +0900 Subject: [PATCH 07/29] =?UTF-8?q?refactor:=20stepperTapped=20=EB=82=B4?= =?UTF-8?q?=EB=B6=80=20=EA=B0=80=EB=8F=85=EC=84=B1=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20fruitLabelText=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EC=97=AC=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/FruitStoreViewController.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift index f67def40d..9a599aeca 100644 --- a/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift +++ b/JuiceMaker/JuiceMaker/Controller/FruitStoreViewController.swift @@ -32,22 +32,26 @@ class FruitStoreViewController: UIViewController { self.dismiss(animated: true, completion: nil) } + func fruitLabelText(value: Double) -> String { + return String(format: "%.0f", value) + } + @IBAction func stepperTapped(_ sender: UIStepper) { switch sender { case strawberryStockStepper: - strawberryStockLabel.text = String(format: "%.0f", sender.value) + strawberryStockLabel.text = fruitLabelText(value: sender.value) fruitStockChange(fruit: .strawberry, value: sender.value) case bananaStockStepper: - bananaStockLabel.text = String(format: "%.0f", sender.value) + bananaStockLabel.text = fruitLabelText(value: sender.value) fruitStockChange(fruit: .banana, value: sender.value) case pineappleStockStepper: - pineappleStockLabel.text = String(format: "%.0f", sender.value) + pineappleStockLabel.text = fruitLabelText(value: sender.value) fruitStockChange(fruit: .pineapple, value: sender.value) case kiwiStockStepper: - kiwiStockLabel.text = String(format: "%.0f", sender.value) + kiwiStockLabel.text = fruitLabelText(value: sender.value) fruitStockChange(fruit: .kiwi, value: sender.value) case mangoStockStepper: - mangoStockLabel.text = String(format: "%.0f", sender.value) + mangoStockLabel.text = fruitLabelText(value: sender.value) fruitStockChange(fruit: .mango, value: sender.value) default: showNotificationAlert(message: Message.unknownError.description) From e71fa4fd7cd752530547173be4d6dcc69e3ce100 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 2 Nov 2021 16:22:47 +0900 Subject: [PATCH 08/29] =?UTF-8?q?fix:=20Storyboard=EC=97=90=EC=84=9C=20Jui?= =?UTF-8?q?ceMakerViewController=20Scene=EC=9D=98=20Content=20Priority=20?= =?UTF-8?q?=EC=B6=A9=EB=8F=8C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Base.lproj/Main.storyboard | 123 +++++++++--------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard index 62f398e0c..1f0548b72 100644 --- a/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard +++ b/JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard @@ -1,9 +1,10 @@ - - + + + - + @@ -15,23 +16,23 @@ - + - + - + - - + - - + - - + - - + - - + - +