-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
53 lines (48 loc) · 1.42 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"encoding/base64"
"errors"
)
func GenerateAccountNumber(p Person) string {
email := p.User.Email
accountHash := base64.StdEncoding.EncodeToString([]byte(email))
return accountHash
}
func ValidateUser(email, password string) bool {
for _, user := range Users {
if user.Email == email && user.Password == password {
return true
}
}
return false
}
func GetData(person Person, detailType string) (*BankDetail, *[]UserTransaction, *[]TransferTransaction, error) {
var userBankDetails BankDetail
var userTransactions []UserTransaction
var transferTransactions []TransferTransaction
switch detailType {
case "bankDetails":
for _, bankDetail := range BankDetails {
if bankDetail.AccountHash == person.AccountHash {
userBankDetails = bankDetail
}
}
return &userBankDetails, nil, nil, nil
case "userTransactions":
for _, userTransaction := range userTransactions {
if userTransaction.AccountHash == person.AccountHash {
userTransactions = append(userTransactions, userTransaction)
}
}
return nil, &userTransactions, nil, nil
case "transferTransactions":
for _, transferTransaction := range TransferTransactions {
if transferTransaction.From == person.AccountHash {
transferTransactions = append(transferTransactions, transferTransaction)
}
}
return nil, nil, &transferTransactions, nil
default:
return nil, nil, nil, errors.New("no valid option selected")
}
}