Files
hanko/backend/persistence/models/password_credential.go
2024-10-09 12:36:26 +02:00

36 lines
932 B
Go

package models
import (
"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gobuffalo/validate/v3/validators"
"github.com/gofrs/uuid"
"time"
)
type PasswordCredential struct {
ID uuid.UUID `db:"id"`
UserId uuid.UUID `db:"user_id"`
Password string `db:"password"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
func NewPasswordCredential(userId uuid.UUID, password string) *PasswordCredential {
id, _ := uuid.NewV4()
return &PasswordCredential{
ID: id,
UserId: userId,
Password: password,
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
}
}
func (password *PasswordCredential) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.StringIsPresent{Name: "Password", Field: password.Password},
&validators.UUIDIsPresent{Name: "UserId", Field: password.UserId},
), nil
}