changed error message in api client (nothing lol)

This commit is contained in:
Kima 2023-08-16 02:11:41 +02:00
parent 22cd08165b
commit d2003893e8
3 changed files with 116 additions and 66 deletions

View File

@ -1,30 +1,30 @@
// This is a basic Flutter widget test. // // This is a basic Flutter widget test.
// // //
// To perform an interaction with a widget in your test, use the WidgetTester // // To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll // // utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget // // gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct. // // tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; // import 'package:flutter_test/flutter_test.dart';
import 'package:filcnaplo/main.dart'; // import 'package:filcnaplo/main.dart';
void main() { // void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { // testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); // await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0. // // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); // expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing); // expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame. // // Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add)); // await tester.tap(find.byIcon(Icons.add));
await tester.pump(); // await tester.pump();
// Verify that our counter has incremented. // // Verify that our counter has incremented.
expect(find.text('0'), findsNothing); // expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget); // expect(find.text('1'), findsOneWidget);
}); // });
} // }

View File

@ -7,39 +7,69 @@ class KretaAPI {
static const clientId = "kreta-ellenorzo-mobile-android"; static const clientId = "kreta-ellenorzo-mobile-android";
// ELLENORZO API // ELLENORZO API
static String notes(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.notes; static String notes(String iss) =>
static String events(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.events; BaseKreta.kreta(iss) + KretaApiEndpoints.notes;
static String student(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.student; static String events(String iss) =>
static String grades(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.grades; BaseKreta.kreta(iss) + KretaApiEndpoints.events;
static String absences(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.absences; static String student(String iss) =>
static String groups(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.groups; BaseKreta.kreta(iss) + KretaApiEndpoints.student;
static String grades(String iss) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.grades;
static String absences(String iss) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.absences;
static String groups(String iss) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.groups;
static String groupAverages(String iss, String uid) => static String groupAverages(String iss, String uid) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.groupAverages + "?oktatasiNevelesiFeladatUid=" + uid; BaseKreta.kreta(iss) +
KretaApiEndpoints.groupAverages +
"?oktatasiNevelesiFeladatUid=" +
uid;
static String timetable(String iss, {DateTime? start, DateTime? end}) => static String timetable(String iss, {DateTime? start, DateTime? end}) =>
BaseKreta.kreta(iss) + BaseKreta.kreta(iss) +
KretaApiEndpoints.timetable + KretaApiEndpoints.timetable +
(start != null && end != null ? "?datumTol=" + start.toUtc().toIso8601String() + "&datumIg=" + end.toUtc().toIso8601String() : ""); (start != null && end != null
static String exams(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.exams; ? "?datumTol=" +
start.toUtc().toIso8601String() +
"&datumIg=" +
end.toUtc().toIso8601String()
: "");
static String exams(String iss) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.exams;
static String homework(String iss, {DateTime? start, String? id}) => static String homework(String iss, {DateTime? start, String? id}) =>
BaseKreta.kreta(iss) + BaseKreta.kreta(iss) +
KretaApiEndpoints.homework + KretaApiEndpoints.homework +
(id != null ? "/$id" : "") + (id != null ? "/$id" : "") +
(id == null && start != null ? "?datumTol=" + DateFormat('yyyy-MM-dd').format(start) : ""); (id == null && start != null
static String capabilities(String iss) => BaseKreta.kreta(iss) + KretaApiEndpoints.capabilities; ? "?datumTol=" + DateFormat('yyyy-MM-dd').format(start)
static String downloadHomeworkAttachments(String iss, String uid, String type) => : "");
BaseKreta.kreta(iss) + KretaApiEndpoints.downloadHomeworkAttachments(uid, type); static String capabilities(String iss) =>
BaseKreta.kreta(iss) + KretaApiEndpoints.capabilities;
static String downloadHomeworkAttachments(
String iss, String uid, String type) =>
BaseKreta.kreta(iss) +
KretaApiEndpoints.downloadHomeworkAttachments(uid, type);
// ADMIN API // ADMIN API
static const sendMessage = BaseKreta.kretaAdmin + KretaAdminEndpoints.sendMessage; static const sendMessage =
static String messages(String endpoint) => BaseKreta.kretaAdmin + KretaAdminEndpoints.messages(endpoint); BaseKreta.kretaAdmin + KretaAdminEndpoints.sendMessage;
static String message(String id) => BaseKreta.kretaAdmin + KretaAdminEndpoints.message(id); static String messages(String endpoint) =>
static const recipientCategories = BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientCategories; BaseKreta.kretaAdmin + KretaAdminEndpoints.messages(endpoint);
static const availableCategories = BaseKreta.kretaAdmin + KretaAdminEndpoints.availableCategories; static String message(String id) =>
static const recipientsTeacher = BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientsTeacher; BaseKreta.kretaAdmin + KretaAdminEndpoints.message(id);
static const uploadAttachment = BaseKreta.kretaAdmin + KretaAdminEndpoints.uploadAttachment; static const recipientCategories =
static String downloadAttachment(String id) => BaseKreta.kretaAdmin + KretaAdminEndpoints.downloadAttachment(id); BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientCategories;
static const trashMessage = BaseKreta.kretaAdmin + KretaAdminEndpoints.trashMessage; static const availableCategories =
static const deleteMessage = BaseKreta.kretaAdmin + KretaAdminEndpoints.deleteMessage; BaseKreta.kretaAdmin + KretaAdminEndpoints.availableCategories;
static const recipientsTeacher =
BaseKreta.kretaAdmin + KretaAdminEndpoints.recipientsTeacher;
static const uploadAttachment =
BaseKreta.kretaAdmin + KretaAdminEndpoints.uploadAttachment;
static String downloadAttachment(String id) =>
BaseKreta.kretaAdmin + KretaAdminEndpoints.downloadAttachment(id);
static const trashMessage =
BaseKreta.kretaAdmin + KretaAdminEndpoints.trashMessage;
static const deleteMessage =
BaseKreta.kretaAdmin + KretaAdminEndpoints.deleteMessage;
} }
class BaseKreta { class BaseKreta {
@ -58,25 +88,30 @@ class KretaApiEndpoints {
static const grades = "/ellenorzo/V3/Sajat/Ertekelesek"; static const grades = "/ellenorzo/V3/Sajat/Ertekelesek";
static const absences = "/ellenorzo/V3/Sajat/Mulasztasok"; static const absences = "/ellenorzo/V3/Sajat/Mulasztasok";
static const groups = "/ellenorzo/V3/Sajat/OsztalyCsoportok"; static const groups = "/ellenorzo/V3/Sajat/OsztalyCsoportok";
static const groupAverages = "/ellenorzo/V3/Sajat/Ertekelesek/Atlagok/OsztalyAtlagok"; static const groupAverages =
"/ellenorzo/V3/Sajat/Ertekelesek/Atlagok/OsztalyAtlagok";
static const timetable = "/ellenorzo/V3/Sajat/OrarendElemek"; static const timetable = "/ellenorzo/V3/Sajat/OrarendElemek";
static const exams = "/ellenorzo/V3/Sajat/BejelentettSzamonkeresek"; static const exams = "/ellenorzo/V3/Sajat/BejelentettSzamonkeresek";
static const homework = "/ellenorzo/V3/Sajat/HaziFeladatok"; static const homework = "/ellenorzo/V3/Sajat/HaziFeladatok";
// static const homeworkDone = "/ellenorzo/V3/Sajat/HaziFeladatok/Megoldva"; // Removed from the API // static const homeworkDone = "/ellenorzo/V3/Sajat/HaziFeladatok/Megoldva"; // Removed from the API
static const capabilities = "/ellenorzo/V3/Sajat/Intezmenyek"; static const capabilities = "/ellenorzo/V3/Sajat/Intezmenyek";
static String downloadHomeworkAttachments(String uid, String type) => "/ellenorzo/V3/Sajat/Csatolmany/$uid"; static String downloadHomeworkAttachments(String uid, String type) =>
"/ellenorzo/V3/Sajat/Csatolmany/$uid";
} }
class KretaAdminEndpoints { class KretaAdminEndpoints {
//static const messages = "/api/v1/kommunikacio/postaladaelemek/sajat"; //static const messages = "/api/v1/kommunikacio/postaladaelemek/sajat";
static const sendMessage = "/api/v1/kommunikacio/uzenetek"; static const sendMessage = "/api/v1/kommunikacio/uzenetek";
static String messages(String endpoint) => "/api/v1/kommunikacio/postaladaelemek/$endpoint"; static String messages(String endpoint) =>
static String message(String id) => "/api/v1/kommunikacio/postaladaelemek/$id"; "/api/v1/kommunikacio/postaladaelemek/$endpoint";
static String message(String id) =>
"/api/v1/kommunikacio/postaladaelemek/$id";
static const recipientCategories = "/api/v1/adatszotarak/cimzetttipusok"; static const recipientCategories = "/api/v1/adatszotarak/cimzetttipusok";
static const availableCategories = "/api/v1/kommunikacio/cimezhetotipusok"; static const availableCategories = "/api/v1/kommunikacio/cimezhetotipusok";
static const recipientsTeacher = "/api/v1/kreta/alkalmazottak/tanar"; static const recipientsTeacher = "/api/v1/kreta/alkalmazottak/tanar";
static const uploadAttachment = "/ideiglenesfajlok"; static const uploadAttachment = "/ideiglenesfajlok";
static String downloadAttachment(String id) => "/api/v1/dokumentumok/uzenetek/$id"; static String downloadAttachment(String id) =>
"/api/v1/dokumentumok/uzenetek/$id";
static const trashMessage = "/api/v1/kommunikacio/postaladaelemek/kuka"; static const trashMessage = "/api/v1/kommunikacio/postaladaelemek/kuka";
static const deleteMessage = "/api/v1/kommunikacio/postaladaelemek/torles"; static const deleteMessage = "/api/v1/kommunikacio/postaladaelemek/torles";
} }

View File

@ -66,8 +66,10 @@ class KretaClient {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (autoHeader) { if (autoHeader) {
if (!headerMap.containsKey("authorization") && accessToken != null) headerMap["authorization"] = "Bearer $accessToken"; if (!headerMap.containsKey("authorization") && accessToken != null)
if (!headerMap.containsKey("user-agent") && userAgent != null) headerMap["user-agent"] = "$userAgent"; headerMap["authorization"] = "Bearer $accessToken";
if (!headerMap.containsKey("user-agent") && userAgent != null)
headerMap["user-agent"] = "$userAgent";
} }
res = await client.get(Uri.parse(url), headers: headerMap); res = await client.get(Uri.parse(url), headers: headerMap);
@ -94,7 +96,8 @@ class KretaClient {
return res.body; return res.body;
} }
} on http.ClientException catch (error) { } on http.ClientException catch (error) {
print("ERROR: KretaClient.getAPI ($url) ClientException: ${error.message}"); print(
"ERROR: KretaClient.getAPI ($url) ClientException: ${error.message}");
} catch (error) { } catch (error) {
print("ERROR: KretaClient.getAPI ($url) ${error.runtimeType}: $error"); print("ERROR: KretaClient.getAPI ($url) ${error.runtimeType}: $error");
} }
@ -120,9 +123,12 @@ class KretaClient {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (autoHeader) { if (autoHeader) {
if (!headerMap.containsKey("authorization") && accessToken != null) headerMap["authorization"] = "Bearer $accessToken"; if (!headerMap.containsKey("authorization") && accessToken != null)
if (!headerMap.containsKey("user-agent") && userAgent != null) headerMap["user-agent"] = "$userAgent"; headerMap["authorization"] = "Bearer $accessToken";
if (!headerMap.containsKey("content-type")) headerMap["content-type"] = "application/json"; if (!headerMap.containsKey("user-agent") && userAgent != null)
headerMap["user-agent"] = "$userAgent";
if (!headerMap.containsKey("content-type"))
headerMap["content-type"] = "application/json";
} }
res = await client.post(Uri.parse(url), headers: headerMap, body: body); res = await client.post(Uri.parse(url), headers: headerMap, body: body);
@ -142,9 +148,10 @@ class KretaClient {
return res.body; return res.body;
} }
} on http.ClientException catch (error) { } on http.ClientException catch (error) {
print("ERROR: KretaClient.getAPI ($url) ClientException: ${error.message}"); print(
"ERROR: KretaClient.postAPI ($url) ClientException: ${error.message}");
} catch (error) { } catch (error) {
print("ERROR: KretaClient.getAPI ($url) ${error.runtimeType}: $error"); print("ERROR: KretaClient.postAPI ($url) ${error.runtimeType}: $error");
} }
} }
@ -157,7 +164,8 @@ class KretaClient {
}; };
String nonceStr = await getAPI(KretaAPI.nonce, json: false); String nonceStr = await getAPI(KretaAPI.nonce, json: false);
Nonce nonce = getNonce(nonceStr, loginUser.username, loginUser.instituteCode); Nonce nonce =
getNonce(nonceStr, loginUser.username, loginUser.instituteCode);
headers.addAll(nonce.header()); headers.addAll(nonce.header());
if (_settings.presentationMode) { if (_settings.presentationMode) {
@ -175,18 +183,25 @@ class KretaClient {
)); ));
if (loginRes != null) { if (loginRes != null) {
if (loginRes.containsKey("access_token")) accessToken = loginRes["access_token"]; if (loginRes.containsKey("access_token"))
if (loginRes.containsKey("refresh_token")) refreshToken = loginRes["refresh_token"]; accessToken = loginRes["access_token"];
if (loginRes.containsKey("refresh_token"))
refreshToken = loginRes["refresh_token"];
// Update role // Update role
loginUser.role = JwtUtils.getRoleFromJWT(accessToken ?? "") ?? Role.student; loginUser.role =
JwtUtils.getRoleFromJWT(accessToken ?? "") ?? Role.student;
} }
if (refreshToken != null) { if (refreshToken != null) {
Map? refreshRes = await postAPI(KretaAPI.login, Map? refreshRes = await postAPI(KretaAPI.login,
headers: headers, body: User.refreshBody(refreshToken: refreshToken!, instituteCode: loginUser.instituteCode)); headers: headers,
body: User.refreshBody(
refreshToken: refreshToken!,
instituteCode: loginUser.instituteCode));
if (refreshRes != null) { if (refreshRes != null) {
if (refreshRes.containsKey("id_token")) idToken = refreshRes["id_token"]; if (refreshRes.containsKey("id_token"))
idToken = refreshRes["id_token"];
} }
} }
} }