allowlist.go 772 B

123456789101112131415161718192021222324252627282930313233
  1. package gorm
  2. import (
  3. "github.com/porter-dev/porter/internal/models"
  4. "github.com/porter-dev/porter/internal/repository"
  5. "gorm.io/gorm"
  6. )
  7. // AllowlistRepository uses gorm.DB for querying the database
  8. type AllowlistRepository struct {
  9. db *gorm.DB
  10. }
  11. // NewAllowlistRepository returns a AllowListRepository which uses
  12. // gorm.DB for querying the database.
  13. func NewAllowlistRepository(db *gorm.DB) repository.AllowlistRepository {
  14. return &AllowlistRepository{db}
  15. }
  16. func (repo *AllowlistRepository) UserEmailExists(email string) (bool, error) {
  17. al := &models.Allowlist{}
  18. result := repo.db.Where("user_email = ?", email).Find(&al)
  19. if err := result.Error; err != nil {
  20. return false, err
  21. }
  22. if result.RowsAffected > 0 {
  23. return true, nil
  24. }
  25. return false, nil
  26. }