28 lines
793 B
Go
28 lines
793 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
func (s *Store) DeleteCustomDomain(ctx context.Context, id, projectID uint64) error {
|
|
result, err := s.db.ExecContext(ctx, "DELETE FROM domains WHERE id=? AND project_id=? AND kind='custom' AND dns_record_id IS NULL", id, projectID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if n, _ := result.RowsAffected(); n != 1 {
|
|
return ErrNotFound
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Store) ProjectAssignedDomain(ctx context.Context, tenantID, projectID uint64) (string, error) {
|
|
var domain string
|
|
err := s.db.QueryRowContext(ctx, "SELECT domain FROM domains WHERE tenant_id=? AND project_id=? AND kind='assigned' ORDER BY id LIMIT 1", tenantID, projectID).Scan(&domain)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
err = ErrNotFound
|
|
}
|
|
return domain, err
|
|
}
|