Data model structure using autowire

97 Views Asked by At

what is the best approach to structure data model when using autowire? here is basic use case: i have domain data model on the backend which has case class User with fields id, username, active, auth_token which represents. This class maps to sql database table. On the frontend i only need fields id, username of User entity. I see only two approaches:

  1. map User class to some FrontUser class with fields i need
  2. divide database table on two separate which will be mapped to two different objects User and FrontUser
1

There are 1 best solutions below

3
On

This is mostly a matter of opinion -- there's likely no One True Answer to it. But from this description I'd recommend simply having User and FrontUser. Dividing the database table usually introduces additional latencies and complexity to the code, whereas introducing a smaller case class for the API and front end is usually pretty small and easy -- possibly as little as a couple of lines of code. That seems likely to be easier both to write and maintain.