I have an Entity called Users
that have login, name and department as fields that are stored in Users
table.
My Spring-Boot
configuration defines the departments that gives the system manager role for users in this application.
The key problem is that I want the login end-point
to return the User data with the additional information that he/she is or is not a system manager.
I think that this information should be in the User class, but I do not want this information to be stored in the database along with other fields as the management departments may change or the user my change from one department to another that does not manage the system.
(Edit) I will define this IsManager field when user request login(): I will get user's department
field and check against managerDepartment
's list to set it to true ou false.
So the question is if it is right to put that information in a non-persistent field in the entity class (and how to do that) or if I may change the ResponseEntity in the rest method to add the additional information (and how) ?
Short answer is to use @Transient annotation. Correct answer is to separate UserEntity and UserDto to two different classes and use MapStruct for example for transformation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With