-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
fetchUser()
gRPC method in user_handler.dart
and update…
… `user_viewmodel.dart`
- Loading branch information
1 parent
a2b3cb1
commit 8435810
Showing
3 changed files
with
29 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import 'package:gocast_mobile/models/user/user_model.dart'; | ||
import 'package:gocast_mobile/base/helpers/model_generator.dart'; | ||
import 'package:gocast_mobile/base/networking/api/grpc_handler.dart'; | ||
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pbgrpc.dart'; | ||
import 'package:gocast_mobile/models/user/user_model.dart' as model; | ||
|
||
/// Class responsible for fetching and posting user-related data (e.g., fetch user details, update usersettings, etc.) | ||
class UserHandler { | ||
// Generate user mock for testing the views until API/v2 is implemented | ||
final GrpcHandler _grpcHandler; | ||
|
||
/// Performs SSO authentication. | ||
/// | ||
/// This method opens the SSO login page in a web view. After the user logs in, | ||
/// it saves the JWT token and redirects back to the app. | ||
/// | ||
/// Throws an [AppError] if a network error occurs or if no JWT-cookie is set. | ||
UserHandler(this._grpcHandler); | ||
|
||
static Future<User> fetchUser() async { | ||
// TODO: Fetch user information from API (preferably over gRPC) - see issues | ||
return ModelGenerator.generateRandomUser(); | ||
Future<model.User> fetchUser() async { | ||
return await _grpcHandler.callGrpcMethod( | ||
(client) async { | ||
final response = await client.getUser(GetUserRequest()); | ||
// Deserialize the gRPC response into a User instance | ||
return model.User.fromProto(response.user); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters