-
Notifications
You must be signed in to change notification settings - Fork 3
/
in-memory-account.go
46 lines (38 loc) · 1021 Bytes
/
in-memory-account.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
package repositories
import (
"github.com/KPMGE/go-users-clean-api/src/domain/entities"
)
var accounts []*entities.Account
type InMemoryAccountRepository struct{}
func (repo *InMemoryAccountRepository) CheckAccountByEmail(email string) bool {
for _, account := range accounts {
if account.Email == email {
return true
}
}
return false
}
func (repo *InMemoryAccountRepository) CheckAccountByUserName(userName string) bool {
for _, account := range accounts {
if account.UserName == userName {
return true
}
}
return false
}
func (repo *InMemoryAccountRepository) Save(account *entities.Account) error {
accounts = append(accounts, account)
return nil
}
func (repo *InMemoryAccountRepository) DeleteAccountById(accountId string) bool {
for index, account := range accounts {
if account.ID == accountId {
accounts = removeIndex(accounts, index)
return true
}
}
return false
}
func NewInmemoryAccountRepository() *InMemoryAccountRepository {
return &InMemoryAccountRepository{}
}