11import 'package:flutter_it/flutter_it.dart' ;
22import 'package:school_data_hub_client/school_data_hub_client.dart' ;
3+ import 'package:school_data_hub_flutter/core/client/client_helper.dart' ;
34
45/// API service for user-related operations.
56class UserApiService {
67 Client get _client => di <Client >();
78
89 /// Fetch all users.
9- Future <List <User >> getAllUsers () async {
10- return _client.user.getAllUsers ();
10+ Future <List <User >?> getAllUsers () async {
11+ return ClientHelper .apiCall (
12+ call: () => _client.user.getAllUsers (),
13+ errorMessage: 'Benutzer abrufen' ,
14+ );
1115 }
1216
1317 /// Fetch all users with UserInfo and list of UserDevices per user.
14- Future <List <UserWithDevices >> getAllUsersWithDevices () async {
15- return _client.user.getAllUsersWithDevices ();
18+ Future <List <UserWithDevices >?> getAllUsersWithDevices () async {
19+ return ClientHelper .apiCall (
20+ call: () => _client.user.getAllUsersWithDevices (),
21+ errorMessage: 'Benutzer mit Geräten abrufen' ,
22+ );
1623 }
1724
1825 /// Get the currently authenticated user.
1926 Future <User ?> getCurrentUser () async {
20- return _client.user.getCurrentUser ();
27+ return ClientHelper .apiCall <User ?>(
28+ call: () => _client.user.getCurrentUser (),
29+ errorMessage: 'Aktuellen Benutzer abrufen' ,
30+ );
2131 }
2232
2333 /// Create a new user.
@@ -34,18 +44,21 @@ class UserApiService {
3444 required bool isTester,
3545 Set <int >? pupilsAuth,
3646 }) async {
37- await _client.adminUser.createUser (
38- userName: userName,
39- fullName: fullName,
40- email: email,
41- matrixUserId: matrixUserId,
42- password: password,
43- role: role,
44- timeUnits: timeUnits,
45- reliefTimeUnits: reliefTimeUnits,
46- scopeNames: scopeNames,
47- isTester: isTester,
48- pupilsAuth: pupilsAuth,
47+ await ClientHelper .apiCall (
48+ call: () => _client.adminUser.createUser (
49+ userName: userName,
50+ fullName: fullName,
51+ email: email,
52+ matrixUserId: matrixUserId,
53+ password: password,
54+ role: role,
55+ timeUnits: timeUnits,
56+ reliefTimeUnits: reliefTimeUnits,
57+ scopeNames: scopeNames,
58+ isTester: isTester,
59+ pupilsAuth: pupilsAuth,
60+ ),
61+ errorMessage: 'Benutzer erstellen' ,
4962 );
5063 }
5164
@@ -65,55 +78,76 @@ class UserApiService {
6578 String ? imageUrl,
6679 Set <int >? pupilsAuth,
6780 }) async {
68- await _client.adminUser.updateUser (
69- userId,
70- userName: userName,
71- fullName: fullName,
72- email: email,
73- role: role,
74- matrixUserId: matrixUserId,
75- timeUnits: timeUnits,
76- reliefTimeUnits: reliefTimeUnits,
77- credit: credit,
78- isTester: isTester,
79- pupilsAuth: pupilsAuth,
81+ await ClientHelper .apiCall (
82+ call: () => _client.adminUser.updateUser (
83+ userId,
84+ userName: userName,
85+ fullName: fullName,
86+ email: email,
87+ role: role,
88+ matrixUserId: matrixUserId,
89+ timeUnits: timeUnits,
90+ reliefTimeUnits: reliefTimeUnits,
91+ credit: credit,
92+ isTester: isTester,
93+ pupilsAuth: pupilsAuth,
94+ ),
95+ errorMessage: 'Benutzer aktualisieren' ,
8096 );
8197 // TODO: when server supports UserInfo.imageUrl, add imageUrl to the
8298 // endpoint and pass it here (client must be regenerated).
8399 }
84100
85101 /// Reset a user's password. Returns `true` on success.
86- Future <bool > resetPassword (String userEmail, String newPassword) async {
87- return _client.adminUser.resetPassword (userEmail, newPassword);
102+ Future <bool ?> resetPassword (String userEmail, String newPassword) async {
103+ return ClientHelper .apiCall (
104+ call: () => _client.adminUser.resetPassword (userEmail, newPassword),
105+ errorMessage: 'Passwort zurücksetzen' ,
106+ );
88107 }
89108
90109 /// Change the current user's password. Returns `true` on success.
91- Future <bool > changePassword (String oldPassword, String newPassword) async {
92- return _client.user.changePassword (oldPassword, newPassword);
110+ Future <bool ?> changePassword (String oldPassword, String newPassword) async {
111+ return ClientHelper .apiCall (
112+ call: () => _client.user.changePassword (oldPassword, newPassword),
113+ errorMessage: 'Passwort ändern' ,
114+ );
93115 }
94116
95117 /// Delete (block) a user by ID.
96118 Future <void > deleteUser (int userId) async {
97- await _client.adminUser.deleteUser (userId);
119+ await ClientHelper .apiCall (
120+ call: () => _client.adminUser.deleteUser (userId),
121+ errorMessage: 'Benutzer löschen' ,
122+ );
98123 }
99124
100125 /// Delete the auth key associated with a device. Returns updated user+devices
101126 /// for the session user (or null if not authenticated).
102127 Future <UserWithDevices ?> deleteAuthKeyAssociatedWithDevice (
103128 UserDevice device,
104129 ) async {
105- return _client.adminUser.deleteAuthKeyAssociatedWithDevice (device);
130+ return ClientHelper .apiCall <UserWithDevices ?>(
131+ call: () => _client.adminUser.deleteAuthKeyAssociatedWithDevice (device),
132+ errorMessage: 'Geräte-Auth-Key löschen' ,
133+ );
106134 }
107135
108136 /// Increase staff credit for all users. Returns `true` on success.
109- Future <bool > increaseStaffCredit () async {
110- return _client.user.increaseStaffCredit ();
137+ Future <bool ?> increaseStaffCredit () async {
138+ return ClientHelper .apiCall (
139+ call: () => _client.user.increaseStaffCredit (),
140+ errorMessage: 'Mitarbeiter-Guthaben erhöhen' ,
141+ );
111142 }
112143
113144 /// Batch-creates users. Returns credentials for successes and errors for skipped/failed rows.
114- Future <BatchCreateUsersResponse > batchCreateUsers (
145+ Future <BatchCreateUsersResponse ? > batchCreateUsers (
115146 List <CreateUserRequest > requests,
116147 ) async {
117- return _client.adminUser.batchCreateUsers (requests);
148+ return ClientHelper .apiCall (
149+ call: () => _client.adminUser.batchCreateUsers (requests),
150+ errorMessage: 'Benutzer-Stapelimport' ,
151+ );
118152 }
119153}
0 commit comments