2fas-server/internal/api/mobile/service/validation.go

26 lines
469 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package service
import (
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
2023-01-30 19:59:42 +01:00
"github.com/twofas/2fas-server/internal/api/mobile/domain"
2022-12-31 10:22:38 +01:00
)
func DeviceIdExistsValidator(repository domain.MobileDeviceRepository) validator.Func {
return func(fl validator.FieldLevel) bool {
id, err := uuid.Parse(fl.Field().String())
if err != nil {
return false
}
_, err = repository.FindById(id)
if err != nil {
return false
}
return true
}
}