Imagine that you have 3 entities: Student, Discipline and Student Discipline.
The AlunoDisciplina
entity, in addition to relating Aluno
to Disciplina
, also includes other information, such as the student's final grade. So basically we have something like this:
class AlunoDisciplina {
Aluno aluno;
Disciplina disciplina;
double notaFinal;
}
As the above entity is exposed, aluno
and disciplina
compose a composite primary key, since a student can not be associated with the same discipline more than once.
Some operations I need to implement:
How can I expose this relationship in a RESTful way?
What I thought so far
For items 1 and 2, respectively, I envision the features below.
(GET) / disciplines / {idDiscipline} /children.json
{
"alunosMatriculados": [{
"aluno": {
"id": 2,
"nome": "Pedro"
},
"notaFinal": 9.5
}, {
"aluno": {
"id": 6,
"nome": "Maria"
},
"notaFinal": 10
}]
}
(GET) / students / {StudentName} /disciplines.json
{
"matriculadoNasDisciplinas": [{
"disciplina": {
"id": 1,
"nome": "Matemática"
},
"notaFinal": 9.5
}, {
"disciplina": {
"id": 2,
"nome": "Filosofia"
},
"notaFinal": 7
}]
}
For items 3 and 4 I'm not finding the best way to solve.
The best solution would be this same or is there any other better way?
Do you have any suggestions for items 3 and 4?