Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce invariants in the models #50

Open
pauljamescleary opened this issue Dec 24, 2017 · 2 comments
Open

Enforce invariants in the models #50

pauljamescleary opened this issue Dec 24, 2017 · 2 comments

Comments

@pauljamescleary
Copy link
Owner

Our entities / domain model have virtually no validations.

Add invariant checks so that no domain model can be created.

For example, for a user, the phone number must be a valid form, the email must be a valid form, first name and last name must only contain valid characters.

Can possibly add other invariants for Pets and Orders. The invariants to add can be arbitrary.

Also, looking for ideas on how to tie these into Circe serialization.

My current thinking is to have custom decoders that call out to the smart constructors, and somehow translate the ValidatedNels to an appropriate response.

Here is an example...

case class User(...)
object User {
  def apply(userName: String, firstName: String ... ): ValidatedNel[String, User] = ...
@tbrown1979
Copy link
Contributor

sealed abstract case class can be helpful in situations like this. Refined may also be useful.

I'm not totally fluent with the project yet, but refined-circe could be really useful for validating input to the endpoints. It can do a lot of the heavy lifting to Refined types for you.

@pauljamescleary
Copy link
Owner Author

I looked at Refined recently, unclear on how everything comes together there yet, but it is definitely a good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants