I have a lot of data as response not parsed and also, so you can see what is in the response. But i want all the scores from the table results, the quary fiters on actorId, categoryId, what gets all the data of all subjects from that specific actorId.
parsed data response from the localhost of my:
[
{
"id": 1,
"name": "Word",
"tests": [
{
"id": 1,
"title": "Test 1",
"name": "Test 1",
"description": "This is the description of the first Test",
"totalPoints": 2,
"duration": 30,
"level": 1,
"subjectId": 1,
"questions": [ ],
"paragraphs": [ ],
"results": [
{
"id": 22,
"score": 100.0,
"timeElapsed": 5,
"actorId": 13,
"actor": null,
"testId": 1,
"resultQuestions": [ ],
"resultSliders": [ ]
}
],
"sliders": [ ],
"pausedTests": [ ]
},
{
"id": 5,
"title": "new test",
"name": "new test",
"description": "asdf",
"totalPoints": 0,
"duration": 9,
"level": 3,
"subjectId": 1,
"questions": [ ],
"paragraphs": [ ],
"results": [
{
"id": 19,
"score": 0.0,
"timeElapsed": 4,
"actorId": 13,
"actor": null,
"testId": 5,
"resultQuestions": [ ],
"resultSliders": [ ]
}
],
"sliders": [ ],
"pausedTests": [ ]
},
{
"id": 8,
"title": "test",
"name": "test-1",
"description": "Dit is een test",
"totalPoints": 2,
"duration": 1,
"level": 1,
"subjectId": 1,
"questions": [ ],
"paragraphs": [ ],
"results": [ ],
"sliders": [ ],
"pausedTests": [ ]
}
],
"schools": [ ],
"categoryId": 1,
"category": null
},
Data that comes back if you console.log the reponse of the API from the console.log(response):
The function is called [{"id":1,"name":"Word","tests":[{"id":1,"title":"Test 1","name":"Test 1","description":"This is the description of the first Test","totalPoints":2,"duration":30,"level":1,"subjectId":1,"questions":[],"paragraphs":[],"results":[{"id":22,"score":100.0,"timeElapsed":5,"actorId":13,"actor":null,"testId":1,"resultQuestions":[],"resultSliders":[]}],"sliders":[],"pausedTests":[]},{"id":5,"title":"new test","name":"new test","description":"asdf","totalPoints":0,"duration":9,"level":3,"subjectId":1,"questions":[],"paragraphs":[],"results":[{"id":19,"score":0.0,"timeElapsed":4,"actorId":13,"actor":null,"testId":5,"resultQuestions":[],"resultSliders":[]}],"sliders":[],"pausedTests":[]},{"id":8,"title":"test","name":"test-1","description":"Dit is een test","totalPoints":2,"duration":1,"level":1,"subjectId":1,"questions":[],"paragraphs":[],"results":[],"sliders":[],"pausedTests":[]}],"schools":[],"categoryId":1,"category":null},{"id":2,"name":"PowerPoint","tests":[{"id":2,"title":"Test 2","name":"Test 1","description":"This is the description of the first Test","totalPoints":2,"duration":30,"level":2,"subjectId":2,"questions":[],"paragraphs":[],"results":[],"sliders":[],"pausedTests":[]},{"id":3,"title":"De titel der titelen","name":"Deze test heet programmeren voor gevorderden","description":"Deze test gaat over hoe leraren ict moet leren begrijpen.","totalPoints":25,"duration":30,"level":3,"subjectId":2,"questions":[],"paragraphs":[],"results":[{"id":20,"score":44.0,"timeElapsed":50,"actorId":13,"actor":null,"testId":3,"resultQuestions":[],"resultSliders":[]}],"sliders":[],"pausedTests":[]}],"schools":[],"categoryId":1,"category":null},{"id":3,"name":"Excel","tests":[],"schools":[],"categoryId":1,"category":null},{"id":7,"name":"Test","tests":[],"schools":[],"categoryId":1,"category":null}]
I tried for myself if i could get the score’s back from the results array table.
function showAllSubjectsScores(response) {
var parsedData = JSON.parse(response);
console.log('The function is called', parsedData[results][0].score)
}
This is how the APi call is made for the response of all the data:
// Global var's
var categoryId = 1;
var actorId = 13; // This is my actorId
var websiteUrl = localStorage.getItem('url');
function getSubjectsByActorid() {
var xHttp = new XMLHttpRequest();
xHttp.onreadystatechange = function () {
if (xHttp.readyState == XMLHttpRequest.DONE) {
var response = xHttp.response;
if (xHttp.status == 200) {
console.log('ANTWOORD IS TERUG VAN DE SERVER')
showAllSubjectsScores(response);
} else {
console.log(response);
console.log(xHttp.status);
}
}
};
xHttp.onerror = function () {
console.log(xHttp.statusText);
};
xHttp.open("GET", websiteUrl + "/api/Subjects/" + categoryId + "/" + actorId, true);
xHttp.send();
console.log('AANVRAAG IS VERZONDEN')
}
function showAllSubjectsScores(response) {
var parsedData = JSON.parse(response);
console.log('The function is called', response)
}
getSubjectsByActorid();
This is how the api quarry is build:
// GET: api/Subjects
[HttpGet("/api/Subjects/{categoryId}/{actorId}")]
public async Task<ActionResult<List<Subject>>> GetSubjectResults(int categoryId, int actorId)
{
var subjectResults = _context.Subjects
.Where(i => i.CategoryId == categoryId)
.Include(t => t.Tests)
.ThenInclude(r => r.Results.Where(a => a.ActorId == actorId))
.AsNoTracking().ToListAsync();
if (subjectResults == null)
{
return StatusCode(204);
}
return await subjectResults;
}