@@ -7,13 +7,13 @@ import (
77)
88
99type WithdrawNote struct {
10- FiveHundread int
11- Hundread int
12- Left int
10+ FiveHundred int
11+ Hundred int
12+ Left int
1313}
1414
1515type ATM struct {
16- countOFNotes map [string ]int
16+ countOfNotes map [string ]int
1717 card model.Card
1818 account Account
1919 uiOption []string
@@ -30,7 +30,7 @@ func (a *ATM) SetState(s ATMState) {
3030 a .currentState = s
3131}
3232
33- func (a * ATM ) ResetAtm () {
33+ func (a * ATM ) CleanPreviousAtmTransaction () {
3434 a .mu .Lock ()
3535 defer a .mu .Unlock ()
3636 a .WithdrawAs = & WithdrawNote {}
@@ -41,7 +41,7 @@ func (a *ATM) ResetAtm() {
4141func (a * ATM ) PrintMoney () {
4242 a .mu .Lock ()
4343 defer a .mu .Unlock ()
44- fmt .Printf ("\n 500 note present:%d, 100 not present:%d" , a .countOFNotes ["500" ], a .countOFNotes ["100" ])
44+ fmt .Printf ("\n 500 note present:%d, 100 not present:%d" , a .countOfNotes ["500" ], a .countOfNotes ["100" ])
4545}
4646
4747func (a * ATM ) StateName () string {
@@ -64,8 +64,15 @@ func (a *ATM) GetCardDetail() error {
6464
6565func (a * ATM ) DispenserAmount () error {
6666 a .mu .Lock ()
67- defer a .mu .Unlock ()
68- return a .currentState .DispenserAmount ()
67+ if err := a .currentState .DispenserAmount (); err != nil {
68+ return err
69+ }
70+
71+ a .mu .Unlock ()
72+
73+ a .CleanPreviousAtmTransaction ()
74+
75+ return nil
6976}
7077
7178func (a * ATM ) SelectAccount () error {
@@ -77,7 +84,7 @@ func (a *ATM) SelectAccount() error {
7784func (a * ATM ) Execute (operation func () error ) {
7885 err := operation ()
7986 if err != nil {
80- a .ResetAtm ()
87+ a .CleanPreviousAtmTransaction ()
8188 a .SetState (a .insertCard )
8289 fmt .Println ("All operation will be nil operation:" )
8390 fmt .Println ("Error while operation:" , err .Error ())
@@ -86,7 +93,7 @@ func (a *ATM) Execute(operation func() error) {
8693
8794func NewATM () * ATM {
8895 atm := & ATM {
89- countOFNotes : map [string ]int {
96+ countOfNotes : map [string ]int {
9097 "500" : 1000 ,
9198 "200" : 2000 ,
9299 "100" : 1000 ,
@@ -106,10 +113,6 @@ func NewATM() *ATM {
106113 atm : atm ,
107114 }
108115
109- atm .readCard = & ReadCard {
110- atm : atm ,
111- }
112-
113116 atm .dispenserAmount = & DispenserAmount {
114117 atm : atm ,
115118 }
0 commit comments