1

I'm trying to understand how people work to factorize validations definition in Angular / Spring Boot context.

I wonder about several things :

  • In angular, fields can appear in multiple forms across the app. How to define once for all the constraints for these given fields ? Externalize in a a property file ? A custom validator for ALL inputs of our app (sick) ? Something else ?
  • We need to validate front side and back-end side. How to ensure front and back-end are using the same constraints ? How to do not do the job twice, which is error prone.

If you have a feedback about this, it would be appreciated.

Thank you

    -
flodor2
  • 87
  • 1
  • 10
  • 1
    Maybe you could write your validation code in kotlin lib that is multiplatform (js + java/kotlin) and use it in your backend and front (how to here https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-a-multiplatform-project). – JEY Mar 22 '19 at 10:14

1 Answers1

0

I had this problem when i was developpement my spring boot / angular Application, in fact there're two approches for contains :

- Application level Validation :(in your case you're using this approches)

- Database Contains : the contrains should be in the data base

You should use the database contains because it is "easier, integrity, flexible" and It's easier to maintain 100 tables than 100,000 lines of code.

In general, constraints that are enforced in the application but not in the database have to be replicated across many applications. Sometimes those applications are even written and maintained by different teams.

for more information about this topics :

Link 1 :Database constraints vs Application level validation

Link 2 :https://dzone.com/articles/validation-in-java-applications

I don't know if this is the anwser that you're looking for, hope that will help .

youssef elhayani
  • 625
  • 8
  • 28
  • The thing is i think Database constraints are too restrictive. For example, an user account not activated don't have to have a password yet. But the password will become mandatory when the account is activated. I'm sure we could use tricks like another table or something, but it's complicating too much on my opinion. That's why i hesitate to do validation in DTO and not entities for example – flodor2 Mar 22 '19 at 12:38