-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathget_course_summary_command.dart
72 lines (64 loc) · 2.49 KB
/
get_course_summary_command.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Package imports:
import 'package:http/http.dart' as http;
import 'package:xml/xml.dart';
// Project imports:
import 'package:notredame/constants/urls.dart';
import 'package:notredame/features/app/signets-api/models/course.dart';
import 'package:notredame/features/app/signets-api/models/course_summary.dart';
import 'package:notredame/features/app/signets-api/models/signets_errors.dart';
import 'package:notredame/features/app/signets-api/signets_api_client.dart';
import 'package:notredame/features/app/signets-api/soap_service.dart';
import 'package:notredame/utils/api_exception.dart';
import 'package:notredame/utils/command.dart';
/// Call the SignetsAPI to get all the evaluations (exams) and the summary
/// of [course] for the student ([username]).
class GetCourseSummaryCommand implements Command<CourseSummary> {
final SignetsAPIClient client;
final http.Client _httpClient;
final String username;
final String password;
final Course course;
GetCourseSummaryCommand(
this.client,
this._httpClient, {
required this.username,
required this.password,
required this.course,
});
@override
Future<CourseSummary> execute() async {
// Generate initial soap envelope
final body = SoapService.buildBasicSOAPBody(
Urls.listEvaluationsOperation, username, password)
.buildDocument();
final operationContent = XmlBuilder();
// Add the content needed by the operation
operationContent.element("pSigle", nest: () {
operationContent.text(course.acronym);
});
operationContent.element("pGroupe", nest: () {
operationContent.text(course.group);
});
operationContent.element("pSession", nest: () {
operationContent.text(course.session);
});
body
.findAllElements(Urls.listEvaluationsOperation,
namespace: Urls.signetsOperationBase)
.first
.children
.add(operationContent.buildFragment());
final responseBody = await SoapService.sendSOAPRequest(
_httpClient, body, Urls.listEvaluationsOperation);
final errorTag = responseBody.getElement(SignetsError.signetsErrorSoapTag);
if (errorTag != null &&
errorTag.innerText.contains(SignetsError.gradesNotAvailable) ||
responseBody.findAllElements('ElementEvaluation').isEmpty) {
throw const ApiException(
prefix: SignetsAPIClient.tag,
message: "No grades available",
errorCode: SignetsError.gradesEmpty);
}
return CourseSummary.fromXmlNode(responseBody);
}
}