Created
January 14, 2018 08:06
-
-
Save masa-x/b386fdfa5e93efcf79c7b7b4cef00b35 to your computer and use it in GitHub Desktop.
Withdrawal.go 機能追加前
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usecase | |
import "strconv" | |
type Withdrawal struct{ | |
mOutputBoundary OutputBoundary | |
mDataAccessor DataAccessor | |
} | |
func CreateWithdrawal(aOutputBoundary OutputBoundary, | |
aDataAccessor DataAccessor) *Withdrawal{ | |
return &Withdrawal{ | |
mOutputBoundary: aOutputBoundary, | |
mDataAccessor: aDataAccessor} | |
} | |
func (r Withdrawal) Input(aDataSource map[string]string){ | |
aDataSource["process"] = "Withdrawal"; | |
amountOfMoney, err := strconv.Atoi(aDataSource["amount_of_money"]) | |
if err != nil { | |
aDataSource["result"] = "Failed"; | |
r.mOutputBoundary.Output(aDataSource) | |
return; | |
} | |
balance := r.mDataAccessor.GetBalance(); | |
subtratedBalance := balance.Subtract(amountOfMoney) | |
aDataSource["balance"] = subtratedBalance.ValueAsString() | |
aDataSource["result"] = "Success"; | |
r.mDataAccessor.UpdateBalance(subtratedBalance.Value()) | |
r.mOutputBoundary.Output(aDataSource) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment