mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-27 06:06:54 +08:00
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package test
|
|
|
|
import (
|
|
"github.com/gofrs/uuid"
|
|
"github.com/teamhanko/hanko/backend/persistence"
|
|
"github.com/teamhanko/hanko/backend/persistence/models"
|
|
)
|
|
|
|
func NewPasswordCredentialPersister(init []models.PasswordCredential) persistence.PasswordCredentialPersister {
|
|
return &passwordCredentialPersister{append([]models.PasswordCredential{}, init...)}
|
|
}
|
|
|
|
type passwordCredentialPersister struct {
|
|
passwords []models.PasswordCredential
|
|
}
|
|
|
|
func (p passwordCredentialPersister) Create(password models.PasswordCredential) error {
|
|
p.passwords = append(p.passwords, password)
|
|
return nil
|
|
}
|
|
|
|
func (p passwordCredentialPersister) GetByUserID(userId uuid.UUID) (*models.PasswordCredential, error) {
|
|
var found *models.PasswordCredential
|
|
for _, data := range p.passwords {
|
|
if data.UserId == userId {
|
|
d := data
|
|
found = &d
|
|
}
|
|
}
|
|
return found, nil
|
|
}
|
|
|
|
func (p passwordCredentialPersister) Update(password models.PasswordCredential) error {
|
|
for i, data := range p.passwords {
|
|
if data.ID == password.ID {
|
|
p.passwords[i] = password
|
|
}
|
|
}
|
|
return nil
|
|
}
|