feat(users): add getById API and UserBasicInfo
This commit is contained in:
@@ -1,12 +1,33 @@
|
|||||||
import 'package:social_app/core/api/i_api_client.dart';
|
import 'package:social_app/core/api/i_api_client.dart';
|
||||||
import 'models/user_response.dart';
|
import 'models/user_response.dart';
|
||||||
|
|
||||||
|
class UserBasicInfo {
|
||||||
|
final String id;
|
||||||
|
final String username;
|
||||||
|
final String? avatarUrl;
|
||||||
|
|
||||||
|
UserBasicInfo({required this.id, required this.username, this.avatarUrl});
|
||||||
|
|
||||||
|
factory UserBasicInfo.fromJson(Map<String, dynamic> json) {
|
||||||
|
return UserBasicInfo(
|
||||||
|
id: json['id'] as String,
|
||||||
|
username: json['username'] as String,
|
||||||
|
avatarUrl: json['avatar_url'] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class UsersApi {
|
class UsersApi {
|
||||||
final IApiClient _client;
|
final IApiClient _client;
|
||||||
static const _prefix = '/api/v1/users';
|
static const _prefix = '/api/v1/users';
|
||||||
|
|
||||||
UsersApi(this._client);
|
UsersApi(this._client);
|
||||||
|
|
||||||
|
Future<UserBasicInfo> getById(String userId) async {
|
||||||
|
final response = await _client.get('$_prefix/$userId');
|
||||||
|
return UserBasicInfo.fromJson(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
Future<UserResponse> getMe() async {
|
Future<UserResponse> getMe() async {
|
||||||
final response = await _client.get('$_prefix/me');
|
final response = await _client.get('$_prefix/me');
|
||||||
return UserResponse.fromJson(response.data);
|
return UserResponse.fromJson(response.data);
|
||||||
|
|||||||
Reference in New Issue
Block a user