I have a Table "team" with below structure:
| Column | Type | Collation | Nullable | Default |
|---|---|---|---|---|
id |
uuid | not null | ||
team_name |
character varying(200) | not null | ||
admin_group |
uuid | not null | ||
lead_group |
uuid | not null | ||
user_group |
uuid | not null |
I am using Spring Data JPA and need to execute query equivalent to:
SELECT *,
CASE
WHEN lead_group IN groupList THEN 3
WHEN admin_group IN groupList THEN 2
WHEN user_group IN groupList THEN 1
ELSE 0 END AS role
FROM team;
Here groupList is list of all groups user is part of. I get this info from another service.
What is the best way to do it using Spring Data JPA? I also need to support sorting based on all columns and pagination. Do I add a additional field 'role' in my Team entity or create a separate class altogether to collect the data from the query?