Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

쥬스메이커 [STEP 2] 제이티, Ari #119

Merged
merged 17 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
68927c4
feat: 쥬스 주문버튼 터치 시 Alret 표시되는 기능 구현
leeari95 Oct 25, 2021
c8f2ac6
feat: 주문 버튼 터치시 재고가 있는 경우와 없는 경우에 대한 기능 구현
HoneyCoding Oct 25, 2021
e083fff
feat: 과일의 재고가 바뀔 때 마다 화면에 반영되도록 기능 구현
leeari95 Oct 25, 2021
293f811
refactor: HIG 지침에 따라 Alert의 선택지 문구 수정
HoneyCoding Oct 26, 2021
a560ab2
refactor: Fruit타입을 FruitStore 내부에서 외부로 이동
leeari95 Oct 26, 2021
57031d7
refactor: JuiceMakerViewController의 UILabel 프로퍼티 이름 수정
HoneyCoding Oct 26, 2021
eb48bef
refactor: JuiceMakerViewController 내부 메서드명 수정
leeari95 Oct 26, 2021
0331594
refactor: JuiceMakerViewController 내부 메소드 순서 변경
HoneyCoding Oct 26, 2021
8edd150
refactor: orderJuiceButtonTapped 메서드 분리 및 리팩토링
leeari95 Oct 26, 2021
b28fab2
chore: 불필요한 주석 제거
HoneyCoding Oct 26, 2021
5d1c1da
chore: mixFruit 메서드 내부에 에러 문구를 수정
leeari95 Oct 26, 2021
f7bb20f
docs: README.md 파일 내용 추가
HoneyCoding Oct 26, 2021
8bfece8
refactor: 문자열을 모아놓은 enum Text 추가 및 숫자를 문자열로 형변환 하는 코드 수정
HoneyCoding Oct 28, 2021
5f09d5c
refactor: Juice 타입 리팩토링 및 Text 타입 이름 수정
leeari95 Oct 28, 2021
d252b60
refactor: Alert 버튼의 타이틀을 따로 Text 타입으로 구현
HoneyCoding Oct 28, 2021
0484cd1
refactor: FruitStore 내부에 전역변수를 enum Const 타입으로 리팩토링
leeari95 Oct 28, 2021
494468c
refactor: JuiceMakerViewController 내부의 showOutOfStockAlert 메소드의 코드 일부…
HoneyCoding Oct 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 주문 버튼 터치시 재고가 있는 경우와 없는 경우에 대한 기능 구현
- JuiceMakerViewController 클래스에 juiceMaker 프로퍼티 생성
- orderJuiceButtonTapped 메소드 로직 수정
- notificationAlert 메소드를 통해 버튼이 하나인 Alert를 보여주도록 구현
- outOfStockAlert 메소드를 통해 버튼이 2개인 Alert를 보여주도록 구현
- juiceCompletionAlert 메소드 삭제 (notificationAlert에 통합)
  • Loading branch information
HoneyCoding committed Oct 25, 2021
commit c8f2ac66d9c3899461b31ada6b6c3376b4109a8f
54 changes: 38 additions & 16 deletions JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,65 @@ import UIKit

class JuiceMakerViewController: UIViewController {

private let juiceMaker = JuiceMaker()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

@IBAction func orderJuiceButtonTapped(_ sender: UIButton) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 button 의 action method 를 개별로 구현할 때와 이렇게 하나에 구현할 때의 장단점은 무엇인가요?

let buttonText = sender.titleLabel?.text
let juice: Juice

switch buttonText {
case "딸바쥬스 주문":
juiceCompletionAlret(juice: .strawberryBanana)
juice = .strawberryBanana
case "망키쥬스 주문":
juiceCompletionAlret(juice: .mangoKiwi)
juice = .mangoKiwi
case "딸기쥬스 주문":
juiceCompletionAlret(juice: .strawberry)
juice = .strawberry
case "바나나쥬스 주문":
juiceCompletionAlret(juice: .banana)
juice = .banana
case "파인애플쥬스 주문":
juiceCompletionAlret(juice: .pineapple)
juice = .pineapple
case "키위쥬스 주문":
juiceCompletionAlret(juice: .kiwi)
juice = .kiwi
case "망고쥬스 주문":
juiceCompletionAlret(juice: .mango)
juice = .mango
default:
let alret = UIAlertController(title: "오류", message: "잘못된 접근입니다.", preferredStyle: .alert)
let cencel = UIAlertAction(title: "Cencel", style: .destructive, handler: nil)
alret.addAction(cencel)
present(alret, animated: true, completion: nil)
notificationAlert(message: "잘못된 접근입니다.")
return
}

do {
try juiceMaker.mixFruit(juice: juice)
} catch RequestError.fruitStockOut {
outOfStockAlert()
} catch let error as RequestError {
notificationAlert(message: error.errorDescription)
} catch {
notificationAlert(message: "잘못된 접근입니다.")
}
}

func juiceCompletionAlret(juice: Juice){
let alret = UIAlertController(title: nil, message: "\(juice) 쥬스 나왔습니다! 맛있게 드세요!", preferredStyle: .alert)
let cancel = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
alret.addAction(cancel)
present(alret, animated: true, completion: nil)
func notificationAlert(message: String, title: String = "OK") {
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)
}

func outOfStockAlert() {
let alert = UIAlertController(title: nil, message: "재료가 모자라요. 재고를 수정할까요?", preferredStyle: .alert)
let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil)
let yesAction = UIAlertAction(title: "네", style: .default) { _ in
guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreView") else { return }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 재고 화면 view controller 는 왜 이름이 FruitStoreview 인가요?
  • 해당 함수를 따로 빼면 어떤가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분도 피드백 반영하여 개선해보았습니다 😄
오늘 시간내서 코드리뷰 해주셔서 정말 감사합니다! 많은 도움이 되었어요!!!!! 😊🙏🏻

self.present(viewController, animated: true, completion: nil)
}
alert.addAction(noAction)
alert.addAction(yesAction)
present(alert, animated: true, completion: nil)
}

}
Expand Down
2 changes: 1 addition & 1 deletion JuiceMaker/JuiceMaker/Model/RequestError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum RequestError: Error, LocalizedError {
enum RequestError: Error {
case wrongCount
case fruitNotFound
case fruitStockOut
Expand Down
2 changes: 1 addition & 1 deletion JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
<!--Navigation Controller-->
<scene sceneID="cAf-jL-tPK">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="WwV-Td-3Bn" sceneMemberID="viewController">
<navigationController storyboardIdentifier="FruitStoreView" automaticallyAdjustsScrollViewInsets="NO" id="WwV-Td-3Bn" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="x5k-dG-c9Q"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ufw-7J-6hD">
Expand Down