0

I have to create a system to interview people on a few topics where they have to answer both objective and discursive questions, where questions may change between interviews. I structured the database in the following manner:

  1. Interview is a table with the user's e-mail and timestamps.
  2. Objective/Discursive Answers fields are the Interview key, the Objective/Discursive Questions key and the answer that may be a string for discursive answers and a bool (true/false) for the objective ones.
  3. Objective/Discursive Question is just the description of the question.
  4. All tables use artificial keys.

So, we have these kind of relationships:

Interview 1 - n Objective Answers n - n Objective Questions

Interview 1 - n Discursive Answers n - n Discursive Questions

When the user lands into the interview page, they will face a single form, where these types of questions will be distributed. So, when they submit it, all the answers are going to be together.

Should the InterviewController handle this request? Or it must be specifically used for normal operations of the Interview model such as create and delete? I was thinking about creating another such as InterviewAnswersController, even though there is no corresponding model of it, to handle the request.

The same goes for repositories. Since I'm operating three tables simultaneously, I suppose there should also be an InterviewAnswers repository, where it will at first create the Interview in the database and, using its key, in a single transaction insert the answers in the database.

1
  • 1
    Build whatever makes most sense for your UI/UX and user journeys in your app. I'd recommend avoiding the trap of letting the database structure influence the code. I would typically not expect database entities to have any kind of neat mapping on to classes in your program (avoiding using table names to decide how to structure your code), as Database structure is about persistence and integrity of the data. On the other hand, your code structure exists to provide behaviour, so look at class names that make sense from a user behaviour or UX point of view Jul 30, 2023 at 6:51

1 Answer 1

1

As your question is marked MVC and you ask about repositories and controllers without model, I think that some clarifications are needed.

As several variants of MVC exist, I'll refer to the original MVC architecture and you'll have to adapt to your target environment.

Your repository are part of the model. The tables that you describe are related to the interview domain. Also the processing of the content of the answers, i.e. evaluating if they are right or wrong or rating them according to different criteria, is part of the model - even if you don't store the results.

Getting the answer, i.e. clicking on the buttons getting the input, and sending the content gathereed to th the model is the job of the controler. How you split your controler into smaller parts (i.e. specializing it per view or keeping a single one) is your choice: if you created already a controler component for managing the interview question, there is no issue to create a different component to manage the interview answers, especially if these work with different views.

Same regarding the repositories. The repositories are used to process querries and commands received by the model from a controller. How these repositories deal with the tables is left to you. A good practice is to use DDD, i.e. identifying entities and aggregates, and organize the repositories by aggregate. But it's not the only way (e.g. others use table gateways or active records).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.