posted 4 years ago
Hi,
I am building an endpoint that fetches Quizzes object list.
The Quiz model looks like this:
And here is an example of the endpoint response:
[
{
"createdAt": "2019-08-17T12:00:43.522+0000",
"updatedAt": "2019-08-17T12:00:43.522+0000",
"id": "bf013209-9e00-4890-8c74-a40298b51e12",
"title": "quiz v",
"description": "This quiz is called quiz v and it is just an example, this text should be the description of the quiz",
"imageUrl": "https://images.immediate.co.uk/production/volatile/sites/3/2018/04/Screen-Shot-2018-04-05-at-09.20.50-96984e5.png",
"isPublic": true,
"assignedUsers": null,
"creatorId": "620a1b29-94f3-4f55-b55c-51b173d35113",
"answers": [
{
"createdAt": "2019-08-17T12:00:43.522+0000",
"updatedAt": "2019-08-17T12:00:43.522+0000",
"id": "69d3ed74-4382-44f4-b874-f9fc9c2f2181",
"content": "answer x",
"isCorrect": true,
"userAnswers": [
{
"createdAt": "2019-08-17T12:02:31.070+0000",
"updatedAt": "2019-08-17T12:02:31.070+0000",
"id": "2e749bff-08a8-4f20-8709-7bf3a76cbafe"
}
]
}
],
"userAnswers": [
{
"createdAt": "2019-08-17T12:02:31.070+0000",
"updatedAt": "2019-08-17T12:02:31.070+0000",
"id": "2e749bff-08a8-4f20-8709-7bf3a76cbafe"
}
]
},
{
"createdAt": "2019-08-17T12:00:43.514+0000",
"updatedAt": "2019-08-17T12:00:43.514+0000",
"id": "a2c8e185-2bd2-4f2a-b6b5-f5f6139b377d",
"title": "quiz o",
"description": "This quiz is called quiz o and it is just an example, this text should be the description of the quiz",
"imageUrl": "https://images.immediate.co.uk/production/volatile/sites/3/2018/04/Screen-Shot-2018-04-05-at-09.20.50-96984e5.png",
"isPublic": true,
"assignedUsers": null,
"creatorId": "620a1b29-94f3-4f55-b55c-51b173d35113",
"answers": [
{
"createdAt": "2019-08-17T12:00:43.514+0000",
"updatedAt": "2019-08-17T12:00:43.514+0000",
"id": "53a398f7-f4ec-48e7-9551-54f2b6f90159",
"content": "answer x",
"isCorrect": true,
"userAnswers": []
}
],
"userAnswers": []
}
]
I want to have the ability to add additional information in each item of the response array,
for example, i want to add the "number-of-correct-answers" for each quiz object
But without adding an attribute to the "Quiz" class because it represents the table on DB
How can I achieve this?
My goal is to be able to have an additional information in the JSON response without altering my table
Thanks in advance,
Redan