Skip to content

Commit

Permalink
Merge pull request #1 from JIINHEO/step1
Browse files Browse the repository at this point in the history
Step1
  • Loading branch information
JIINHEO committed Feb 16, 2022
2 parents 70768bb + 59b76a1 commit 17b0545
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 71 deletions.
20 changes: 10 additions & 10 deletions JuiceMaker/JuiceMaker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
C73DAF40255D0CDE00020D38 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C73DAF3F255D0CDE00020D38 /* Assets.xcassets */; };
C73DAF43255D0CDF00020D38 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C73DAF41255D0CDF00020D38 /* LaunchScreen.storyboard */; };
C73DAF4C255D0D0400020D38 /* JuiceMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73DAF4B255D0D0400020D38 /* JuiceMaker.swift */; };
E52D141227BBF0B700F6566D /* Juicable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52D141127BBF0B700F6566D /* Juicable.swift */; };
E52D141427BBF2AF00F6566D /* Fruit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52D141327BBF2AF00F6566D /* Fruit.swift */; };
E52D141627BBF3B400F6566D /* Recipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52D141527BBF3B400F6566D /* Recipe.swift */; };
E52D141827BBF48200F6566D /* Juice.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52D141727BBF48200F6566D /* Juice.swift */; };
E52D141A27BBFA9D00F6566D /* JuiceMakeResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52D141927BBFA9D00F6566D /* JuiceMakeResult.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -33,11 +31,9 @@
C73DAF42255D0CDF00020D38 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C73DAF44255D0CDF00020D38 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C73DAF4B255D0D0400020D38 /* JuiceMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JuiceMaker.swift; sourceTree = "<group>"; };
E52D141127BBF0B700F6566D /* Juicable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Juicable.swift; sourceTree = "<group>"; };
E52D141327BBF2AF00F6566D /* Fruit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fruit.swift; sourceTree = "<group>"; };
E52D141527BBF3B400F6566D /* Recipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recipe.swift; sourceTree = "<group>"; };
E52D141727BBF48200F6566D /* Juice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Juice.swift; sourceTree = "<group>"; };
E52D141927BBFA9D00F6566D /* JuiceMakeResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JuiceMakeResult.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -54,8 +50,6 @@
C71CD66D266C7B470038B9CB /* Controller */ = {
isa = PBXGroup;
children = (
C73DAF36255D0CDD00020D38 /* AppDelegate.swift */,
C73DAF38255D0CDD00020D38 /* SceneDelegate.swift */,
C73DAF3A255D0CDD00020D38 /* ViewController.swift */,
);
path = Controller;
Expand All @@ -66,11 +60,9 @@
children = (
C73DAF4B255D0D0400020D38 /* JuiceMaker.swift */,
C71CD66A266C7ACB0038B9CB /* FruitStore.swift */,
E52D141127BBF0B700F6566D /* Juicable.swift */,
E52D141327BBF2AF00F6566D /* Fruit.swift */,
E52D141527BBF3B400F6566D /* Recipe.swift */,
E52D141727BBF48200F6566D /* Juice.swift */,
E52D141927BBFA9D00F6566D /* JuiceMakeResult.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -104,6 +96,7 @@
C73DAF35255D0CDD00020D38 /* JuiceMaker */ = {
isa = PBXGroup;
children = (
E8CEBFAB27BCA96D009CD8DE /* Application */,
C71CD66D266C7B470038B9CB /* Controller */,
C71CD66F266C7B500038B9CB /* Model */,
C71CD671266C7B570038B9CB /* View */,
Expand All @@ -112,6 +105,15 @@
path = JuiceMaker;
sourceTree = "<group>";
};
E8CEBFAB27BCA96D009CD8DE /* Application */ = {
isa = PBXGroup;
children = (
C73DAF36255D0CDD00020D38 /* AppDelegate.swift */,
C73DAF38255D0CDD00020D38 /* SceneDelegate.swift */,
);
path = Application;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -182,12 +184,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E52D141227BBF0B700F6566D /* Juicable.swift in Sources */,
C71CD66B266C7ACB0038B9CB /* FruitStore.swift in Sources */,
C73DAF3B255D0CDD00020D38 /* ViewController.swift in Sources */,
C73DAF37255D0CDD00020D38 /* AppDelegate.swift in Sources */,
E52D141827BBF48200F6566D /* Juice.swift in Sources */,
E52D141A27BBFA9D00F6566D /* JuiceMakeResult.swift in Sources */,
E52D141427BBF2AF00F6566D /* Fruit.swift in Sources */,
C73DAF39255D0CDD00020D38 /* SceneDelegate.swift in Sources */,
C73DAF4C255D0D0400020D38 /* JuiceMaker.swift in Sources */,
Expand Down
3 changes: 0 additions & 3 deletions JuiceMaker/JuiceMaker/Controller/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Do any additional setup after loading the view.
}


}

17 changes: 16 additions & 1 deletion JuiceMaker/JuiceMaker/Model/Fruit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@

import Foundation

enum Fruit: Juicable, CaseIterable, Hashable {
enum Fruit: CaseIterable {
case strawberry
case banana
case pineapple
case kiwi
case mango

var name: String {
switch self {
case .strawberry:
return "딸기"
case .banana:
return "바나나"
case .pineapple:
return "파인애플"
case .kiwi:
return "키위"
case .mango:
return "망고"
}
}
}
25 changes: 8 additions & 17 deletions JuiceMaker/JuiceMaker/Model/FruitStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import Foundation

enum FruitStoreError: String, Error {
case notEnoughFruit = "과일이 부족합니다."
}

// 과일 저장소 타입
class FruitStore {
private var stock: [Fruit: Int] = [:]
Expand All @@ -20,29 +24,16 @@ class FruitStore {
}
}

private func reduceFruit(fruit: Fruit, count: Int) {
private func reduceFruit(fruit: Fruit, count: Int) throws {
guard let currentFruitCount = stock[fruit], currentFruitCount >= count else {
fatalError()
throw FruitStoreError.notEnoughFruit
}
stock[fruit] = currentFruitCount - count
}

func useFruit(juice: Juice) {
juice.recipe.fruitList.forEach { fruitInfo in
reduceFruit(fruit: fruitInfo.fruit, count: fruitInfo.count)
}
}

func canMakeJuice(juice: Juice) -> Bool {
func useFruit(juice: Juice) throws {
for fruitInfo in juice.recipe.fruitList {
guard let currentFruitCount = stock[fruitInfo.fruit] else {
return false
}

if currentFruitCount < fruitInfo.count {
return false
}
try reduceFruit(fruit: fruitInfo.fruit, count: fruitInfo.count)
}
return true
}
}
12 changes: 0 additions & 12 deletions JuiceMaker/JuiceMaker/Model/Juicable.swift

This file was deleted.

22 changes: 0 additions & 22 deletions JuiceMaker/JuiceMaker/Model/JuiceMakeResult.swift

This file was deleted.

12 changes: 7 additions & 5 deletions JuiceMaker/JuiceMaker/Model/JuiceMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Foundation
struct JuiceMaker {
private var fruitStore: FruitStore = FruitStore()

func makeJuice(juice: Juice) -> JuiceMakeResult {
if fruitStore.canMakeJuice(juice: juice) {
fruitStore.useFruit(juice: juice)
return .success
func makeJuice(juice: Juice) {
do {
try fruitStore.useFruit(juice: juice)
} catch let error as FruitStoreError {
print(error.rawValue)
} catch {
print(error)
}
return .fail(needFruits: []) //TODO: 부족한 과일 종류 전달 필요함
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ iOS 쥬스 메이커 재고관리 시작 저장소
<br />
<br />

<img width="1098" src="https://user-images.githubusercontent.com/39071796/154079820-9ad5de0f-7e21-4399-9bec-3e3318d4e8a7.png"/>
<img width="1098" src="https://user-images.githubusercontent.com/25359605/154262361-858a2fe7-d0e6-43f3-a2c5-5fa5d38b5c3c.png"/>

## 팀원
- [higgs](https://github.com/higgs1022)
Expand Down

0 comments on commit 17b0545

Please sign in to comment.