23 lines
596 B
Dart
23 lines
596 B
Dart
import 'dart:convert';
|
|
import 'package:afterwork/data/models/user_model.dart';
|
|
import 'package:afterwork/core/constants/urls.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../../core/errors/exceptions.dart';
|
|
|
|
class UserRemoteDataSource {
|
|
final http.Client client;
|
|
|
|
UserRemoteDataSource(this.client);
|
|
|
|
Future<UserModel> getUser(String id) async {
|
|
final response = await client.get(Uri.parse('${Urls.baseUrl}/user/$id'));
|
|
|
|
if (response.statusCode == 200) {
|
|
return UserModel.fromJson(json.decode(response.body));
|
|
} else {
|
|
throw ServerException();
|
|
}
|
|
}
|
|
}
|