I'm creating a REST API in Spring Boot and there are the following tables on the DB:
CREATE TABLE Question
(
id SERIAL,
id_survey INT,
description VARCHAR(1000)
* Other fields *
);
CREATE TABLE QuestionChoice
(
id SERIAL,
id_question INT,
description VARCHAR(1000)
* Other fields *
);
I have created their respective models, however I need something more flexible for handling different operations, for instance:
- Returning just a
Question
- Returning a
Question
with a list of itsQuestionChoices
- Creating a
Question
, not sending in the POST call itsid
, along with a list of itsQuestionChoices
missing theid_question
field, since all of the relations will be linked after the call
So far I've been using the Question
model for the first task. For the second and third, I don't know what should I do.
What practices are the best for handling situations such as this?