Frontend first draft
This commit is contained in:
15
frontend/pshared/lib/service/pfe/login.dart
Normal file
15
frontend/pshared/lib/service/pfe/login.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'login.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class LoginRequest {
|
||||
final String login;
|
||||
final String password;
|
||||
|
||||
const LoginRequest({required this.login, required this.password});
|
||||
|
||||
factory LoginRequest.fromJson(Map<String, dynamic> json) => _$LoginRequestFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$LoginRequestToJson(this);
|
||||
}
|
||||
29
frontend/pshared/lib/service/pfe/service.dart
Normal file
29
frontend/pshared/lib/service/pfe/service.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:pshared/service/pfe/login.dart';
|
||||
|
||||
|
||||
class PfeService {
|
||||
static final _logger = Logger('service.pfe');
|
||||
|
||||
static Future<String> login(String email, String password) async {
|
||||
_logger.fine('Logging in');
|
||||
|
||||
try {
|
||||
final res = await http.post(
|
||||
Uri.parse('http://localhost:3000/api/v1/auth/login'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode(LoginRequest(login: email, password: password).toJson()),
|
||||
);
|
||||
return res.toString();
|
||||
} catch (e) {
|
||||
_logger.warning(e.toString());
|
||||
rethrow;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
0
frontend/pshared/lib/service/pfe/services.dart
Normal file
0
frontend/pshared/lib/service/pfe/services.dart
Normal file
Reference in New Issue
Block a user