Say I have a task entity modelled in my application as
{
id: "qweqdsad",
name:"Drink Coffee",
description:"Coffee helps in overcoming laziness",
userId:12
}
Now in my application, say the above JSON is the payload for create task endpoint, In this case if I should prevent the user from adding or creating tasks to other users apart from him. Should the api payload be modelled as
{
id: "qweqdsad",
name:"Drink Coffee",
description:"Coffee helps in overcoming laziness"
}
Note that the userId information is removed from the payload, since the userId information is already available as part of the auth token. Is this method of remodelling the api correct or the api payload structure should always remain the same, while prevention of users adding tasks to other users is prevented by an authorization logic.
To put it simply, should I remodel my entity structure based on the functionality or authorization?
Which one is the right approach to follow here?