I'm creating an .NET Core 3 API with Entity Framework. The data is from an existing database.
Now I've the following situation:
/persons -- get all the persons
/companies -- get all the companies
/attributes -- get all the attributes
/attributes/groups -- get all the attribute groups
/attributes/types -- get all the attribute types
/attributes/usage - get all the attribute usages
- Attributes can be in one or multiple groups.
- Attributes can have one type: person or company.
- Attributes are assigned to a person or company, listed in the usage end-point.
We have in the 'usage' end-point something like:
fk_attribute_id = 1
identifier_attribute = 3
type_id = "person"
So, this means person 3 has attribute 1.
Another example:
fk_attribute_id = 2
identifier_attribute = 2
type_id = "company"
This means company 2 has attribute 2.
In my API I have multiple controllers / services to get this data based on EF. The client could combine the data to get the desired result.
Now I think it's nice to be able to have these end-points:
/persons/3/attributes -- Get the attributes of person 3
/companies/2/attributes -- Get the attributes of company 2
But... that means I have to call my own end-points somehow and combine the data? I can also call the DB and use a stored procedure for this, althrough we do want to avoid have business logic in multiple places.
What would be the best-practise for this? Should we say: the API doesn't provide this, good luck client. Or... are there other options to provide this?
SELECT * FROM attributes_tbl WHERE type_id="person" AND identifier_attribute=3
. Did I miss something in your question?