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

은행창구 관리앱 [Step4] 미르, 희동 #99

Open
wants to merge 20 commits into
base: d_Mireu
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
457ecdd
feat: 스토리보드 없이 코드로 UI구성
mireu930 Feb 6, 2024
0890154
feat: MVC 파일 분리
mireu930 Feb 6, 2024
23e9646
feat: 고객추가버튼을 눌렀을때 타이머가 작동하도록 구현
mireu930 Feb 6, 2024
2fb486d
feat: 초기화버튼을 눌렀을때 타이머가 처음으로 돌아가도록 구현
mireu930 Feb 6, 2024
ebc6963
feat: 고객추가버튼을 눌렀을때 임의의 10명의 고객이 추가되도록 구현
mireu930 Feb 6, 2024
53e8a79
feat: 초기화버튼을 눌렀을때 고객도 초기화되도록 구현
mireu930 Feb 6, 2024
f050141
refactor: 고객이 10명이 추가되면 고객번호가 이어지도록 수정
mireu930 Feb 6, 2024
a3266c9
refactor: 초기화되면 고객도 처음부터 reset되도록 구현
mireu930 Feb 6, 2024
568ac43
refactor: 두개의 Queue를 Queue 하나로 수정 처리될수 있도록 수정
mireu930 Feb 8, 2024
9844140
feat: 추가버튼을 눌렀을때 BankManager의 메서드 구현
mireu930 Feb 8, 2024
6158026
refactor: global Qos 지정
mireu930 Feb 8, 2024
5bf8e85
feat: 델리게이트패턴으로 UI 업데이트 구현
mireu930 Feb 8, 2024
06d79aa
feat: 업무가 끝나면 타이머가 종료되도록 구현
mireu930 Feb 8, 2024
9fdb0a8
feat: 스크롤하면 타이머가 일시정지 되는 에러 수정
mireu930 Feb 8, 2024
9941e85
feat: true/false로 업무가 끝나면 타이머가 종료되도록 수정
mireu930 Feb 8, 2024
ac2b203
refactor: 파일분리
mireu930 Feb 8, 2024
03fa920
feat: 대출업무를 한명이 할수 있도록 수정
mireu930 Feb 8, 2024
63dbf94
refactor: final키워드, 네이밍 수정
mireu930 Feb 10, 2024
228339d
refactor: 고객레이블을 제거 메서드 분리
mireu930 Feb 10, 2024
e5d8de4
refactor: View타입 분리
mireu930 Feb 10, 2024
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
72 changes: 36 additions & 36 deletions BankManagerConsoleApp/BankManagerConsoleApp/Bank/Bank.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@

import Foundation

struct Bank {
private let bankManager: BankManager
private let customNum: Int

init(customNum: Int, bankManager: BankManager) {
self.customNum = customNum
self.bankManager = bankManager
}

func openBank() {
setCustomerCount(customer: customNum)
let workTime = calulateWorkTime {
do {
try bankManager.assignBank()
} catch {
print(error.localizedDescription)
}
}
closeBank(time: workTime)
}

private func setCustomerCount(customer: Int) {
(1...customer).forEach { bankManager.standBy(customer: Customer(banking: Banking.allCases.randomElement(), numOfPerson: $0)) }
}

private func calulateWorkTime(work: () -> Void) -> String {
let startTime = CFAbsoluteTimeGetCurrent()
work()
let endTime = CFAbsoluteTimeGetCurrent()
return String(format: "%.2f", endTime - startTime)
}

private func closeBank(time: String) {
print("업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 \(customNum)명이며, 총 업무시간은 \(time)초 입니다.")
}
}
//struct Bank {
Copy link
Member

Choose a reason for hiding this comment

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

실제 사용되지 않는 코드들은 데드 코드로 남겨두기보단 없애는것이 추후 현업에서 협업 PR을 올릴 때 신경쓰셔야할 하나의 부분이라 남겨둡니다 🙋🏻
아니라면, MARK 주석으로 왜 주석을 처리하는지에 대해 남겨둬도 좋습니다ㅎㅎ

// private let bankManager: BankManager
// private let customNum: Int
//
// init(customNum: Int, bankManager: BankManager) {
// self.customNum = customNum
// self.bankManager = bankManager
// }
//
// func openBank() {
// setCustomerCount(customer: customNum)
// let workTime = calulateWorkTime {
// do {
// try bankManager.assignBank()
// } catch {
// print(error.localizedDescription)
// }
// }
// closeBank(time: workTime)
// }
//
// private func setCustomerCount(customer: Int) {
// (1...customer).forEach { bankManager.standBy(customer: Customer(banking: Banking.allCases.randomElement(), numOfPerson: $0)) }
// }
//
// private func calulateWorkTime(work: () -> Void) -> String {
// let startTime = CFAbsoluteTimeGetCurrent()
// work()
// let endTime = CFAbsoluteTimeGetCurrent()
// return String(format: "%.2f", endTime - startTime)
// }
//
// private func closeBank(time: String) {
// print("업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 \(customNum)명이며, 총 업무시간은 \(time)초 입니다.")
// }
//}
50 changes: 25 additions & 25 deletions BankManagerConsoleApp/BankManagerConsoleApp/Bank/BankClerk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@

import Foundation

struct BankClerk {
private var work: Banking
private var pace: Double {
switch work {
case .deposit:
return 0.7
case .loan:
return 1.1
}
}

init(work: Banking) {
self.work = work
}

func recieve(customer: Customer) {
print("\(customer.numOfPerson)번 고객 \(work.rawValue)업무 시작")
paceTime(pace)
print("\(customer.numOfPerson)번 고객 \(work.rawValue)업무 완료")
}

private func paceTime(_ pace: Double) {
usleep(useconds_t(pace * 1000000))
}
}
//struct BankClerk {
// private var work: Banking
// private var pace: Double {
// switch work {
// case .deposit:
// return 0.7
// case .loan:
// return 1.1
// }
// }
//
// init(work: Banking) {
// self.work = work
// }
//
// func recieve(customer: Customer) {
// print("\(customer.numOfPerson)번 고객 \(work.rawValue)업무 시작")
// paceTime(pace)
// print("\(customer.numOfPerson)번 고객 \(work.rawValue)업무 완료")
// }
//
// private func paceTime(_ pace: Double) {
// usleep(useconds_t(pace * 1000000))
// }
//}
52 changes: 31 additions & 21 deletions BankManagerConsoleApp/BankManagerConsoleApp/Bank/BankManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,56 @@ import Foundation

struct BankManager {
private let queue = Queue<CustomerNumbering>(queue: LinkedList<CustomerNumbering>())
private let bankClerk: [Banking: BankClerk]
private let dispatchgroup = DispatchGroup()
private let semaphore = DispatchSemaphore(value: 2)
private let loanQueue = DispatchQueue(label: "loanQueue")
private let depositQueue = DispatchQueue(label: "depositQueue", attributes: .concurrent)

init(bankClerk: [Banking : BankClerk]) {
self.bankClerk = bankClerk
}
private let depositSemaphore = DispatchSemaphore(value: 2)
private let loanSemaphore = DispatchSemaphore(value: 1)
private let dispatchQueue = DispatchQueue.global(qos: .utility)
weak var delegate: ManageLabel?

func standBy(customer: CustomerNumbering) {
queue.enqueue(element: customer)
}

func assignBank() throws {
func stop() {
queue.clear()
}

func assignBank(dispatchGroup: DispatchGroup) throws {
while let list = try? queue.dequeue(), let banking = list.banking {
guard let customer = list as? Customer else {
throw QueueError.dequeueError
}
switch banking {
case .deposit:
assignDeposit(customer: customer)
assignDeposit(customer: customer, dispatchGroup: dispatchGroup)
case .loan:
assignLoan(customer: customer)
assignLoan(customer: customer, dispatchGroup: dispatchGroup)
}
}
dispatchgroup.wait()
}

func assignDeposit(customer: Customer) {
depositQueue.async(group: dispatchgroup) {
semaphore.wait()
bankClerk[.deposit]?.recieve(customer: customer)
semaphore.signal()
func assignDeposit(customer: Customer, dispatchGroup: DispatchGroup) {
dispatchQueue.async(group: dispatchGroup) {
depositSemaphore.wait()
recieve(customer: customer)
depositSemaphore.signal()
}
}

func assignLoan(customer: Customer) {
loanQueue.async(group: dispatchgroup) {
bankClerk[.loan]?.recieve(customer: customer)
func assignLoan(customer: Customer, dispatchGroup: DispatchGroup) {
dispatchQueue.async(group: dispatchGroup) {
loanSemaphore.wait()
recieve(customer: customer)
loanSemaphore.signal()
}
}

func recieve(customer: Customer) {
delegate?.turn(customer: customer)
paceTime(customer.banking?.pace ?? 0)
delegate?.quit(customer: customer)
}

private func paceTime(_ pace: Double) {
usleep(useconds_t(pace * 1000000))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ import Foundation
enum Banking: String, CaseIterable {
case deposit = "예금"
case loan = "대출"

var pace: Double {
switch self {
case .deposit:
return 0.7
case .loan:
return 1.1
}
}
}
92 changes: 72 additions & 20 deletions BankManagerUIApp/BankManagerUIApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
objects = {

/* Begin PBXBuildFile section */
4E37814A2B74A56E002E1B11 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781412B74A56E002E1B11 /* Queue.swift */; };
4E37814D2B74A56E002E1B11 /* LinkedList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781442B74A56E002E1B11 /* LinkedList.swift */; };
4E37814E2B74A56E002E1B11 /* Banking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781452B74A56E002E1B11 /* Banking.swift */; };
4E37814F2B74A56E002E1B11 /* BankManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781462B74A56E002E1B11 /* BankManager.swift */; };
4E3781502B74A56E002E1B11 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781472B74A56E002E1B11 /* Node.swift */; };
4E3781512B74A56E002E1B11 /* QueueError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781482B74A56E002E1B11 /* QueueError.swift */; };
4E3781522B74A56E002E1B11 /* Customer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3781492B74A56E002E1B11 /* Customer.swift */; };
4EE77F812B7213CE005D0F76 /* BankView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE77F802B7213CE005D0F76 /* BankView.swift */; };
4EE77F9B2B721DDE005D0F76 /* CustomerLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE77F9A2B721DDE005D0F76 /* CustomerLabel.swift */; };
C7694E3B259C3E9F0053667F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3A259C3E9F0053667F /* AppDelegate.swift */; };
C7694E3D259C3E9F0053667F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3C259C3E9F0053667F /* SceneDelegate.swift */; };
C7694E3F259C3E9F0053667F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3E259C3E9F0053667F /* ViewController.swift */; };
C7694E42259C3E9F0053667F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7694E40259C3E9F0053667F /* Main.storyboard */; };
C7694E3F259C3E9F0053667F /* BankViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3E259C3E9F0053667F /* BankViewController.swift */; };
C7694E44259C3EA20053667F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7694E43259C3EA20053667F /* Assets.xcassets */; };
C7694E47259C3EA20053667F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7694E45259C3EA20053667F /* LaunchScreen.storyboard */; };
C7694E52259C3EA20053667F /* BankManagerUIAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E51259C3EA20053667F /* BankManagerUIAppTests.swift */; };
C7694E5D259C3EA20053667F /* BankManagerUIAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E5C259C3EA20053667F /* BankManagerUIAppUITests.swift */; };
C7D65D1E259C81BD005510E0 /* BankManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D65D1D259C81BD005510E0 /* BankManager.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -36,11 +43,19 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4E3781412B74A56E002E1B11 /* Queue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
4E3781442B74A56E002E1B11 /* LinkedList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkedList.swift; sourceTree = "<group>"; };
4E3781452B74A56E002E1B11 /* Banking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Banking.swift; path = ../../../BankManagerConsoleApp/BankManagerConsoleApp/Bank/Banking.swift; sourceTree = "<group>"; };
4E3781462B74A56E002E1B11 /* BankManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BankManager.swift; path = ../../../BankManagerConsoleApp/BankManagerConsoleApp/Bank/BankManager.swift; sourceTree = "<group>"; };
4E3781472B74A56E002E1B11 /* Node.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
4E3781482B74A56E002E1B11 /* QueueError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueueError.swift; sourceTree = "<group>"; };
4E3781492B74A56E002E1B11 /* Customer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Customer.swift; path = ../../../BankManagerConsoleApp/BankManagerConsoleApp/Bank/Customer.swift; sourceTree = "<group>"; };
4EE77F802B7213CE005D0F76 /* BankView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankView.swift; sourceTree = "<group>"; };
4EE77F9A2B721DDE005D0F76 /* CustomerLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerLabel.swift; sourceTree = "<group>"; };
C7694E37259C3E9F0053667F /* BankManagerUIApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankManagerUIApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
C7694E3A259C3E9F0053667F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C7694E3C259C3E9F0053667F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
C7694E3E259C3E9F0053667F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C7694E41259C3E9F0053667F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C7694E3E259C3E9F0053667F /* BankViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankViewController.swift; sourceTree = "<group>"; };
C7694E43259C3EA20053667F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C7694E46259C3EA20053667F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C7694E48259C3EA20053667F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -50,7 +65,6 @@
C7694E58259C3EA20053667F /* BankManagerUIAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BankManagerUIAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C7694E5C259C3EA20053667F /* BankManagerUIAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankManagerUIAppUITests.swift; sourceTree = "<group>"; };
C7694E5E259C3EA20053667F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7D65D1D259C81BD005510E0 /* BankManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BankManager.swift; path = ../../BankManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -78,6 +92,45 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4E3781402B74A55B002E1B11 /* Model */ = {
isa = PBXGroup;
children = (
4E3781532B74D03F002E1B11 /* DataSource */,
4E3781452B74A56E002E1B11 /* Banking.swift */,
4E3781462B74A56E002E1B11 /* BankManager.swift */,
4E3781492B74A56E002E1B11 /* Customer.swift */,
);
path = Model;
sourceTree = "<group>";
};
4E3781532B74D03F002E1B11 /* DataSource */ = {
isa = PBXGroup;
children = (
4E3781442B74A56E002E1B11 /* LinkedList.swift */,
4E3781472B74A56E002E1B11 /* Node.swift */,
4E3781412B74A56E002E1B11 /* Queue.swift */,
4E3781482B74A56E002E1B11 /* QueueError.swift */,
);
path = DataSource;
sourceTree = "<group>";
};
4EE77F822B721553005D0F76 /* View */ = {
isa = PBXGroup;
children = (
4EE77F802B7213CE005D0F76 /* BankView.swift */,
4EE77F9A2B721DDE005D0F76 /* CustomerLabel.swift */,
);
path = View;
sourceTree = "<group>";
};
4EE77F842B7215BF005D0F76 /* Controller */ = {
isa = PBXGroup;
children = (
C7694E3E259C3E9F0053667F /* BankViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
};
C7694E2E259C3E9F0053667F = {
isa = PBXGroup;
children = (
Expand All @@ -101,11 +154,11 @@
C7694E39259C3E9F0053667F /* BankManagerUIApp */ = {
isa = PBXGroup;
children = (
C7D65D1D259C81BD005510E0 /* BankManager.swift */,
4E3781402B74A55B002E1B11 /* Model */,
4EE77F822B721553005D0F76 /* View */,
4EE77F842B7215BF005D0F76 /* Controller */,
C7694E3A259C3E9F0053667F /* AppDelegate.swift */,
C7694E3C259C3E9F0053667F /* SceneDelegate.swift */,
C7694E3E259C3E9F0053667F /* ViewController.swift */,
C7694E40259C3E9F0053667F /* Main.storyboard */,
C7694E43259C3EA20053667F /* Assets.xcassets */,
C7694E45259C3EA20053667F /* LaunchScreen.storyboard */,
C7694E48259C3EA20053667F /* Info.plist */,
Expand Down Expand Up @@ -236,7 +289,6 @@
files = (
C7694E47259C3EA20053667F /* LaunchScreen.storyboard in Resources */,
C7694E44259C3EA20053667F /* Assets.xcassets in Resources */,
C7694E42259C3E9F0053667F /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -261,10 +313,18 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C7694E3F259C3E9F0053667F /* ViewController.swift in Sources */,
4E37814D2B74A56E002E1B11 /* LinkedList.swift in Sources */,
4E3781522B74A56E002E1B11 /* Customer.swift in Sources */,
4E3781512B74A56E002E1B11 /* QueueError.swift in Sources */,
4EE77F812B7213CE005D0F76 /* BankView.swift in Sources */,
4E37814A2B74A56E002E1B11 /* Queue.swift in Sources */,
4E3781502B74A56E002E1B11 /* Node.swift in Sources */,
4EE77F9B2B721DDE005D0F76 /* CustomerLabel.swift in Sources */,
C7694E3F259C3E9F0053667F /* BankViewController.swift in Sources */,
C7694E3B259C3E9F0053667F /* AppDelegate.swift in Sources */,
4E37814E2B74A56E002E1B11 /* Banking.swift in Sources */,
C7694E3D259C3E9F0053667F /* SceneDelegate.swift in Sources */,
C7D65D1E259C81BD005510E0 /* BankManager.swift in Sources */,
4E37814F2B74A56E002E1B11 /* BankManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -300,14 +360,6 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C7694E40259C3E9F0053667F /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
C7694E41259C3E9F0053667F /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
C7694E45259C3EA20053667F /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
Loading