4
Imagine you have 3 entities: Student, Discipline and Alunodiscipline.
The entity AlunoDisciplina
, in addition to relating the Aluno
with the 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;
}
The way the above entity is exposed, aluno
and disciplina
make up a composite primary key, since a student cannot be associated with the same discipline more than once.
Some operations I need to implement:
- List of students enrolled in the course (with their grades);
- List of subjects in which the student is enrolled (with their grades);
- Add/Remove a student from a discipline;
- Edit the student’s final grade in the discipline.
How can I expose this relationship Restful way?
What I thought so far
For items 1 and 2, respectively, I imagine the resources below.
(GET) /disciplines/{idDisciplina}/students-enrolled.json
{
"alunosMatriculados": [{
"aluno": {
"id": 2,
"nome": "Pedro"
},
"notaFinal": 9.5
}, {
"aluno": {
"id": 6,
"nome": "Maria"
},
"notaFinal": 10
}]
}
(GET) /students/{idAluno}/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 am not finding the best way to solve.
The best solution would be this or is there some other better way?
Have any suggestions for items 3 and 4?
I would add (POST) /disciplines/{idDisciplina}/{idAluno} also to add a student to the discipline, as an alternative route perhaps
– Caputo
@Tobymosque in his suggestion would (POST)
/alunos/1/2
, right? It doesn’t get a little confusing the 2 ids as they are?– José Filipe Lyra
José, really this was my fault, I updated the answer to pass this information on Content Body.
– Tobias Mesquita