added delete_app_user and update_device use cases

This commit is contained in:
2026-02-04 12:45:11 +01:00
parent 3955fbf4bc
commit 54818ead25
29 changed files with 1392 additions and 137 deletions

View File

@@ -1,13 +1,20 @@
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:account/src/core/data/models/entities/user_entity.dart';
abstract class AccountRemoteDatasource {
Future<UserEntity> getLoggedUser({required String token});
Future<List<DeviceEntity>> getLinkedDevices({required String userId});
Future<UserEntity> getLoggedUser({required String token});
Future<void> deleteDevice({required String userId, required String deviceId});
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request});
Future<void> updateUser({required String userId, required UpdateUserRequestEntity request});
Future<List<UserEntity>> getAppUsers({required String userId});
Future<void> deleteAppUser({required String userId});
}

View File

@@ -1,10 +1,13 @@
import 'dart:convert';
import 'package:account/src/core/data/datasource/account_remote_datasource.dart';
import 'package:account/src/core/data/models/get_app_users_response_model.dart';
import 'package:account/src/core/data/models/get_linked_devices_response_model.dart';
import 'package:account/src/core/data/models/get_logged_user_response_model.dart';
import 'package:account/src/core/data/models/update_device_request_model.dart';
import 'package:account/src/core/data/models/update_user_request_model.dart';
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:account/src/core/data/models/entities/user_entity.dart';
import 'package:dio/dio.dart';
@@ -19,7 +22,7 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
@override
Future<List<DeviceEntity>> getLinkedDevices({required String userId}) async {
try {
/*final response = await _repository.get<Map<String, dynamic>>(
final response = await _repository.get<Map<String, dynamic>>(
'/$userId/devices',
);
final data = response.data!['items'];
@@ -27,8 +30,8 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
throw Exception('Empty response from /:userId/devices');
}
final model = GetLinkedDevicesResponseModel.fromJson(data);*/
final model = GetLinkedDevicesResponseModel(items: [
final model = GetLinkedDevicesResponseModel.fromJson(data);
/*final model = GetLinkedDevicesResponseModel(items: [
GetLinkedDevicesItemResponseModel(
identificator: '1111',
name: 'Carlos',
@@ -37,7 +40,7 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
identificator: '1112',
name: 'Ana',
number: '222222222'),
]);
]);*/
return model.toEntity();
} on DioException catch (error) {
throw _mapDioError(
@@ -50,7 +53,7 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
@override
Future<UserEntity> getLoggedUser({required String token}) async {
try {
/*final response = await _repository.get<Map<String, dynamic>>(
final response = await _repository.get<Map<String, dynamic>>(
'/users/api/auth/me',
);
final data = response.data!['item'];
@@ -58,23 +61,47 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
throw Exception('Empty response from /auth/me');
}
final model = GetUserResponseModel.fromJson(data);*/
final model = GetLoggedUserResponseModel(item:
final model = GetLoggedUserResponseModel.fromJson(data);
/*final model = GetLoggedUserResponseModel(item:
GetLoggedUserItemResponseModel(
id: '1111',
firstName: 'Juan',
email: 'juan@test.com',
phone: '111111111'));
print(model.toEntity());
phone: '111111111'));*/
return model.toEntity();
} on DioException catch (error) {
throw _mapDioError(
error,
defaultMessage: error.message ?? 'Error getting devices',
defaultMessage: error.message ?? 'Error getting logged user',
);
}
}
@override
Future<void> deleteDevice({required String userId, required String deviceId}) async {
try {
await _repository.put<void>(
'/users/$userId/devices/$deviceId',
);
} on DioException catch (error) {
throw _mapDioError(error, defaultMessage: 'Error to delete device');
}
}
@override
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request}) async {
throw UnimplementedError();
try {
final body = request.toModel().toJson();
await _repository.put<void>(
'/users/$userId/devices/$deviceId',
body: body,
);
} on DioException catch (error) {
throw _mapDioError(error, defaultMessage: 'Error to update device');
}
}
@override
Future<void> updateUser({required String userId, required UpdateUserRequestEntity request}) async {
try {
@@ -84,14 +111,15 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
body: body,
);
} on DioException catch (error) {
throw _mapDioError(error, defaultMessage: 'Error in verification code');
throw _mapDioError(error, defaultMessage: 'Error to update user');
}
}
@override
Future<List<UserEntity>> getAppUsers({required String userId}) async {
//try {
/*final response = await _repository.get<Map<String, dynamic>>(
throw UnimplementedError();
try {
final response = await _repository.get<Map<String, dynamic>>(
'/$userId/devices',
);
final data = response.data!['items'];
@@ -99,42 +127,58 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
throw Exception('Empty response from /:userId/devices');
}
final model = GetLinkedDevicesResponseModel.fromJson(data);*/
/*final model = GetLinkedDevicesResponseModel(items: [
GetLinkedDevicesItemResponseModel(
identificator: '1111',
name: 'Carlos',
number: '111111111'),
GetLinkedDevicesItemResponseModel(
identificator: '1112',
name: 'Ana',
number: '222222222'),
]);
final model = GetAppUsersResponseModel.fromJson(data);
/*final model = GetAppUsersResponseModel(items: [
GetAppUsersItemResponseModel(
id: 'id',
delegationId: 'delegationId',
email: 'carlos@test.com',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
status: 'status',
role: 'role',
lastLogin: 'lastLogin',
currentLogin: 'currentLogin',
language: 'language',
firstName: 'Carlos',
lastName: 'lastName',
hasApiKey: 'hasApiKey',
phone: 'phone',),
GetAppUsersItemResponseModel(
id: 'id',
delegationId: 'delegationId',
email: 'ana@test.com',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
status: 'status',
role: 'role',
lastLogin: 'lastLogin',
currentLogin: 'currentLogin',
language: 'language',
firstName: 'Ana',
lastName: 'lastName',
hasApiKey: 'hasApiKey',
phone: 'phone',),
]);*/
return model.toEntity();
} on DioException catch (error) {
throw _mapDioError(
error,
defaultMessage: error.message ?? 'Error getting devices',
);
}*/
return [
UserEntity(
id: 'id',
delegationId: 'delegationId',
email: 'email',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
status: 'status',
role: 'role',
lastLogin: 'lastLogin',
currentLogin: 'currentLogin',
language: 'language',
firstName: 'firstName',
lastName: 'lastName',
hasApiKey: 'hasApiKey',
phone: 'phone',
)
];
}
}
@override
Future<void> deleteAppUser({required String userId}) async {
throw UnimplementedError();
try {
await _repository.delete<void>(
'/users/$userId',
);
} on DioException catch (error) {
throw _mapDioError(error, defaultMessage: 'Error to delete device');
}
}
}

View File

@@ -0,0 +1,61 @@
import 'package:account/src/core/data/models/entities/user_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'get_app_users_response_model.freezed.dart';
part 'get_app_users_response_model.g.dart';
@freezed
abstract class GetAppUsersResponseModel with _$GetAppUsersResponseModel {
const factory GetAppUsersResponseModel({
required List<GetAppUsersItemResponseModel> items,
}) = _GetAppUsersResponseModel;
factory GetAppUsersResponseModel.fromJson(Map<String, dynamic> json) =>
_$GetAppUsersResponseModelFromJson(json);
}
@freezed
abstract class GetAppUsersItemResponseModel with _$GetAppUsersItemResponseModel {
const factory GetAppUsersItemResponseModel({
required String id,
required String delegationId,
required String email,
required String createdAt,
required String updatedAt,
required String status,
required String role,
required String lastLogin,
required String currentLogin,
required String language,
required String firstName,
required String lastName,
required String hasApiKey,
required String phone
}) =
_GetAppUsersItemResponseModel;
factory GetAppUsersItemResponseModel.fromJson(Map<String, dynamic> json) =>
_$GetAppUsersItemResponseModelFromJson(json);
}
extension GetUsersResponseModelMapper on GetAppUsersResponseModel {
List<UserEntity> toEntity() {
return items.map((GetAppUsersItemResponseModel item) => UserEntity(
id: item.id,
delegationId: item.delegationId,
email: item.email,
createdAt: item.createdAt,
updatedAt: item.updatedAt,
status: item.status,
role: item.role,
lastLogin: item.lastLogin,
currentLogin: item.currentLogin,
language: item.language,
firstName: item.firstName,
lastName: item.lastName,
hasApiKey: item.hasApiKey,
phone: item.phone,
)).toList();
}
}

View File

@@ -0,0 +1,585 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'get_app_users_response_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$GetAppUsersResponseModel {
List<GetAppUsersItemResponseModel> get items;
/// Create a copy of GetAppUsersResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetAppUsersResponseModelCopyWith<GetAppUsersResponseModel> get copyWith => _$GetAppUsersResponseModelCopyWithImpl<GetAppUsersResponseModel>(this as GetAppUsersResponseModel, _$identity);
/// Serializes this GetAppUsersResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetAppUsersResponseModel&&const DeepCollectionEquality().equals(other.items, items));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(items));
@override
String toString() {
return 'GetAppUsersResponseModel(items: $items)';
}
}
/// @nodoc
abstract mixin class $GetAppUsersResponseModelCopyWith<$Res> {
factory $GetAppUsersResponseModelCopyWith(GetAppUsersResponseModel value, $Res Function(GetAppUsersResponseModel) _then) = _$GetAppUsersResponseModelCopyWithImpl;
@useResult
$Res call({
List<GetAppUsersItemResponseModel> items
});
}
/// @nodoc
class _$GetAppUsersResponseModelCopyWithImpl<$Res>
implements $GetAppUsersResponseModelCopyWith<$Res> {
_$GetAppUsersResponseModelCopyWithImpl(this._self, this._then);
final GetAppUsersResponseModel _self;
final $Res Function(GetAppUsersResponseModel) _then;
/// Create a copy of GetAppUsersResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? items = null,}) {
return _then(_self.copyWith(
items: null == items ? _self.items : items // ignore: cast_nullable_to_non_nullable
as List<GetAppUsersItemResponseModel>,
));
}
}
/// Adds pattern-matching-related methods to [GetAppUsersResponseModel].
extension GetAppUsersResponseModelPatterns on GetAppUsersResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _GetAppUsersResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetAppUsersResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _GetAppUsersResponseModel value) $default,){
final _that = this;
switch (_that) {
case _GetAppUsersResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _GetAppUsersResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _GetAppUsersResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<GetAppUsersItemResponseModel> items)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetAppUsersResponseModel() when $default != null:
return $default(_that.items);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<GetAppUsersItemResponseModel> items) $default,) {final _that = this;
switch (_that) {
case _GetAppUsersResponseModel():
return $default(_that.items);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<GetAppUsersItemResponseModel> items)? $default,) {final _that = this;
switch (_that) {
case _GetAppUsersResponseModel() when $default != null:
return $default(_that.items);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetAppUsersResponseModel implements GetAppUsersResponseModel {
const _GetAppUsersResponseModel({required final List<GetAppUsersItemResponseModel> items}): _items = items;
factory _GetAppUsersResponseModel.fromJson(Map<String, dynamic> json) => _$GetAppUsersResponseModelFromJson(json);
final List<GetAppUsersItemResponseModel> _items;
@override List<GetAppUsersItemResponseModel> get items {
if (_items is EqualUnmodifiableListView) return _items;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_items);
}
/// Create a copy of GetAppUsersResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetAppUsersResponseModelCopyWith<_GetAppUsersResponseModel> get copyWith => __$GetAppUsersResponseModelCopyWithImpl<_GetAppUsersResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetAppUsersResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetAppUsersResponseModel&&const DeepCollectionEquality().equals(other._items, _items));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_items));
@override
String toString() {
return 'GetAppUsersResponseModel(items: $items)';
}
}
/// @nodoc
abstract mixin class _$GetAppUsersResponseModelCopyWith<$Res> implements $GetAppUsersResponseModelCopyWith<$Res> {
factory _$GetAppUsersResponseModelCopyWith(_GetAppUsersResponseModel value, $Res Function(_GetAppUsersResponseModel) _then) = __$GetAppUsersResponseModelCopyWithImpl;
@override @useResult
$Res call({
List<GetAppUsersItemResponseModel> items
});
}
/// @nodoc
class __$GetAppUsersResponseModelCopyWithImpl<$Res>
implements _$GetAppUsersResponseModelCopyWith<$Res> {
__$GetAppUsersResponseModelCopyWithImpl(this._self, this._then);
final _GetAppUsersResponseModel _self;
final $Res Function(_GetAppUsersResponseModel) _then;
/// Create a copy of GetAppUsersResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? items = null,}) {
return _then(_GetAppUsersResponseModel(
items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable
as List<GetAppUsersItemResponseModel>,
));
}
}
/// @nodoc
mixin _$GetAppUsersItemResponseModel {
String get id; String get delegationId; String get email; String get createdAt; String get updatedAt; String get status; String get role; String get lastLogin; String get currentLogin; String get language; String get firstName; String get lastName; String get hasApiKey; String get phone;
/// Create a copy of GetAppUsersItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetAppUsersItemResponseModelCopyWith<GetAppUsersItemResponseModel> get copyWith => _$GetAppUsersItemResponseModelCopyWithImpl<GetAppUsersItemResponseModel>(this as GetAppUsersItemResponseModel, _$identity);
/// Serializes this GetAppUsersItemResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetAppUsersItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.email, email) || other.email == email)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.status, status) || other.status == status)&&(identical(other.role, role) || other.role == role)&&(identical(other.lastLogin, lastLogin) || other.lastLogin == lastLogin)&&(identical(other.currentLogin, currentLogin) || other.currentLogin == currentLogin)&&(identical(other.language, language) || other.language == language)&&(identical(other.firstName, firstName) || other.firstName == firstName)&&(identical(other.lastName, lastName) || other.lastName == lastName)&&(identical(other.hasApiKey, hasApiKey) || other.hasApiKey == hasApiKey)&&(identical(other.phone, phone) || other.phone == phone));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,delegationId,email,createdAt,updatedAt,status,role,lastLogin,currentLogin,language,firstName,lastName,hasApiKey,phone);
@override
String toString() {
return 'GetAppUsersItemResponseModel(id: $id, delegationId: $delegationId, email: $email, createdAt: $createdAt, updatedAt: $updatedAt, status: $status, role: $role, lastLogin: $lastLogin, currentLogin: $currentLogin, language: $language, firstName: $firstName, lastName: $lastName, hasApiKey: $hasApiKey, phone: $phone)';
}
}
/// @nodoc
abstract mixin class $GetAppUsersItemResponseModelCopyWith<$Res> {
factory $GetAppUsersItemResponseModelCopyWith(GetAppUsersItemResponseModel value, $Res Function(GetAppUsersItemResponseModel) _then) = _$GetAppUsersItemResponseModelCopyWithImpl;
@useResult
$Res call({
String id, String delegationId, String email, String createdAt, String updatedAt, String status, String role, String lastLogin, String currentLogin, String language, String firstName, String lastName, String hasApiKey, String phone
});
}
/// @nodoc
class _$GetAppUsersItemResponseModelCopyWithImpl<$Res>
implements $GetAppUsersItemResponseModelCopyWith<$Res> {
_$GetAppUsersItemResponseModelCopyWithImpl(this._self, this._then);
final GetAppUsersItemResponseModel _self;
final $Res Function(GetAppUsersItemResponseModel) _then;
/// Create a copy of GetAppUsersItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? delegationId = null,Object? email = null,Object? createdAt = null,Object? updatedAt = null,Object? status = null,Object? role = null,Object? lastLogin = null,Object? currentLogin = null,Object? language = null,Object? firstName = null,Object? lastName = null,Object? hasApiKey = null,Object? phone = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,delegationId: null == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable
as String,email: null == email ? _self.email : email // ignore: cast_nullable_to_non_nullable
as String,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as String,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as String,status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as String,role: null == role ? _self.role : role // ignore: cast_nullable_to_non_nullable
as String,lastLogin: null == lastLogin ? _self.lastLogin : lastLogin // ignore: cast_nullable_to_non_nullable
as String,currentLogin: null == currentLogin ? _self.currentLogin : currentLogin // ignore: cast_nullable_to_non_nullable
as String,language: null == language ? _self.language : language // ignore: cast_nullable_to_non_nullable
as String,firstName: null == firstName ? _self.firstName : firstName // ignore: cast_nullable_to_non_nullable
as String,lastName: null == lastName ? _self.lastName : lastName // ignore: cast_nullable_to_non_nullable
as String,hasApiKey: null == hasApiKey ? _self.hasApiKey : hasApiKey // ignore: cast_nullable_to_non_nullable
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [GetAppUsersItemResponseModel].
extension GetAppUsersItemResponseModelPatterns on GetAppUsersItemResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _GetAppUsersItemResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _GetAppUsersItemResponseModel value) $default,){
final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _GetAppUsersItemResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String delegationId, String email, String createdAt, String updatedAt, String status, String role, String lastLogin, String currentLogin, String language, String firstName, String lastName, String hasApiKey, String phone)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel() when $default != null:
return $default(_that.id,_that.delegationId,_that.email,_that.createdAt,_that.updatedAt,_that.status,_that.role,_that.lastLogin,_that.currentLogin,_that.language,_that.firstName,_that.lastName,_that.hasApiKey,_that.phone);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String delegationId, String email, String createdAt, String updatedAt, String status, String role, String lastLogin, String currentLogin, String language, String firstName, String lastName, String hasApiKey, String phone) $default,) {final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel():
return $default(_that.id,_that.delegationId,_that.email,_that.createdAt,_that.updatedAt,_that.status,_that.role,_that.lastLogin,_that.currentLogin,_that.language,_that.firstName,_that.lastName,_that.hasApiKey,_that.phone);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String delegationId, String email, String createdAt, String updatedAt, String status, String role, String lastLogin, String currentLogin, String language, String firstName, String lastName, String hasApiKey, String phone)? $default,) {final _that = this;
switch (_that) {
case _GetAppUsersItemResponseModel() when $default != null:
return $default(_that.id,_that.delegationId,_that.email,_that.createdAt,_that.updatedAt,_that.status,_that.role,_that.lastLogin,_that.currentLogin,_that.language,_that.firstName,_that.lastName,_that.hasApiKey,_that.phone);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetAppUsersItemResponseModel implements GetAppUsersItemResponseModel {
const _GetAppUsersItemResponseModel({required this.id, required this.delegationId, required this.email, required this.createdAt, required this.updatedAt, required this.status, required this.role, required this.lastLogin, required this.currentLogin, required this.language, required this.firstName, required this.lastName, required this.hasApiKey, required this.phone});
factory _GetAppUsersItemResponseModel.fromJson(Map<String, dynamic> json) => _$GetAppUsersItemResponseModelFromJson(json);
@override final String id;
@override final String delegationId;
@override final String email;
@override final String createdAt;
@override final String updatedAt;
@override final String status;
@override final String role;
@override final String lastLogin;
@override final String currentLogin;
@override final String language;
@override final String firstName;
@override final String lastName;
@override final String hasApiKey;
@override final String phone;
/// Create a copy of GetAppUsersItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetAppUsersItemResponseModelCopyWith<_GetAppUsersItemResponseModel> get copyWith => __$GetAppUsersItemResponseModelCopyWithImpl<_GetAppUsersItemResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetAppUsersItemResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetAppUsersItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.email, email) || other.email == email)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.status, status) || other.status == status)&&(identical(other.role, role) || other.role == role)&&(identical(other.lastLogin, lastLogin) || other.lastLogin == lastLogin)&&(identical(other.currentLogin, currentLogin) || other.currentLogin == currentLogin)&&(identical(other.language, language) || other.language == language)&&(identical(other.firstName, firstName) || other.firstName == firstName)&&(identical(other.lastName, lastName) || other.lastName == lastName)&&(identical(other.hasApiKey, hasApiKey) || other.hasApiKey == hasApiKey)&&(identical(other.phone, phone) || other.phone == phone));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,delegationId,email,createdAt,updatedAt,status,role,lastLogin,currentLogin,language,firstName,lastName,hasApiKey,phone);
@override
String toString() {
return 'GetAppUsersItemResponseModel(id: $id, delegationId: $delegationId, email: $email, createdAt: $createdAt, updatedAt: $updatedAt, status: $status, role: $role, lastLogin: $lastLogin, currentLogin: $currentLogin, language: $language, firstName: $firstName, lastName: $lastName, hasApiKey: $hasApiKey, phone: $phone)';
}
}
/// @nodoc
abstract mixin class _$GetAppUsersItemResponseModelCopyWith<$Res> implements $GetAppUsersItemResponseModelCopyWith<$Res> {
factory _$GetAppUsersItemResponseModelCopyWith(_GetAppUsersItemResponseModel value, $Res Function(_GetAppUsersItemResponseModel) _then) = __$GetAppUsersItemResponseModelCopyWithImpl;
@override @useResult
$Res call({
String id, String delegationId, String email, String createdAt, String updatedAt, String status, String role, String lastLogin, String currentLogin, String language, String firstName, String lastName, String hasApiKey, String phone
});
}
/// @nodoc
class __$GetAppUsersItemResponseModelCopyWithImpl<$Res>
implements _$GetAppUsersItemResponseModelCopyWith<$Res> {
__$GetAppUsersItemResponseModelCopyWithImpl(this._self, this._then);
final _GetAppUsersItemResponseModel _self;
final $Res Function(_GetAppUsersItemResponseModel) _then;
/// Create a copy of GetAppUsersItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? delegationId = null,Object? email = null,Object? createdAt = null,Object? updatedAt = null,Object? status = null,Object? role = null,Object? lastLogin = null,Object? currentLogin = null,Object? language = null,Object? firstName = null,Object? lastName = null,Object? hasApiKey = null,Object? phone = null,}) {
return _then(_GetAppUsersItemResponseModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,delegationId: null == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable
as String,email: null == email ? _self.email : email // ignore: cast_nullable_to_non_nullable
as String,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as String,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as String,status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as String,role: null == role ? _self.role : role // ignore: cast_nullable_to_non_nullable
as String,lastLogin: null == lastLogin ? _self.lastLogin : lastLogin // ignore: cast_nullable_to_non_nullable
as String,currentLogin: null == currentLogin ? _self.currentLogin : currentLogin // ignore: cast_nullable_to_non_nullable
as String,language: null == language ? _self.language : language // ignore: cast_nullable_to_non_nullable
as String,firstName: null == firstName ? _self.firstName : firstName // ignore: cast_nullable_to_non_nullable
as String,lastName: null == lastName ? _self.lastName : lastName // ignore: cast_nullable_to_non_nullable
as String,hasApiKey: null == hasApiKey ? _self.hasApiKey : hasApiKey // ignore: cast_nullable_to_non_nullable
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View File

@@ -0,0 +1,59 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'get_app_users_response_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_GetAppUsersResponseModel _$GetAppUsersResponseModelFromJson(
Map<String, dynamic> json,
) => _GetAppUsersResponseModel(
items: (json['items'] as List<dynamic>)
.map(
(e) => GetAppUsersItemResponseModel.fromJson(e as Map<String, dynamic>),
)
.toList(),
);
Map<String, dynamic> _$GetAppUsersResponseModelToJson(
_GetAppUsersResponseModel instance,
) => <String, dynamic>{'items': instance.items};
_GetAppUsersItemResponseModel _$GetAppUsersItemResponseModelFromJson(
Map<String, dynamic> json,
) => _GetAppUsersItemResponseModel(
id: json['id'] as String,
delegationId: json['delegationId'] as String,
email: json['email'] as String,
createdAt: json['createdAt'] as String,
updatedAt: json['updatedAt'] as String,
status: json['status'] as String,
role: json['role'] as String,
lastLogin: json['lastLogin'] as String,
currentLogin: json['currentLogin'] as String,
language: json['language'] as String,
firstName: json['firstName'] as String,
lastName: json['lastName'] as String,
hasApiKey: json['hasApiKey'] as String,
phone: json['phone'] as String,
);
Map<String, dynamic> _$GetAppUsersItemResponseModelToJson(
_GetAppUsersItemResponseModel instance,
) => <String, dynamic>{
'id': instance.id,
'delegationId': instance.delegationId,
'email': instance.email,
'createdAt': instance.createdAt,
'updatedAt': instance.updatedAt,
'status': instance.status,
'role': instance.role,
'lastLogin': instance.lastLogin,
'currentLogin': instance.currentLogin,
'language': instance.language,
'firstName': instance.firstName,
'lastName': instance.lastName,
'hasApiKey': instance.hasApiKey,
'phone': instance.phone,
};

View File

@@ -1,4 +1,4 @@
/*
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'update_device_request_model.freezed.dart';
@@ -7,44 +7,17 @@ part 'update_device_request_model.g.dart';
@freezed
abstract class UpdateDeviceRequestModel with _$UpdateDeviceRequestModel {
const factory UpdateDeviceRequestModel({
required String deviceIdentificator,
required String lastName,
required String email,
required String phone,
required String language,
required String password,
required List<AddressModel> taxResidences,
required List<AddressModel> addresses,
// ignore: invalid_annotation_target
@JsonKey(name: 'document') required String documentNumber,
required String documentType,
// ignore: invalid_annotation_target
@JsonKey(name: 'relationType') required String relationship,
required String identificator,
required String name,
}) = _UpdateDeviceRequestModel;
factory UpdateDeviceRequestModel.fromCsv(Map<String, dynamic> json) =>
_$UpdateDeviceRequestModelFromCsv(csv);
@override
@JsonKey(name: 'document')
String get documentNumber;
@override
@JsonKey(name: 'relationType')
String get relationship;
factory UpdateDeviceRequestModel.fromJson(Map<String, dynamic> json) =>
_$UpdateDeviceRequestModelFromJson(json);
}
extension UpdateDeviceRequestModelMapper on UpdateDeviceRequestEntity {
UpdateDeviceRequestModel toModel() => UpdateDeviceRequestModel(
firstName: firstName,
lastName: lastName,
email: email,
phone: phone,
language: language,
password: password,
taxResidences: taxResidences
.map((e) => e.toModel())
.toList(growable: false),
addresses: addresses.map((e) => e.toModel()).toList(growable: false),
identificator: identificator,
name: name,
);
}
*/

View File

@@ -0,0 +1,280 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'update_device_request_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$UpdateDeviceRequestModel {
String get identificator; String get name;
/// Create a copy of UpdateDeviceRequestModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$UpdateDeviceRequestModelCopyWith<UpdateDeviceRequestModel> get copyWith => _$UpdateDeviceRequestModelCopyWithImpl<UpdateDeviceRequestModel>(this as UpdateDeviceRequestModel, _$identity);
/// Serializes this UpdateDeviceRequestModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is UpdateDeviceRequestModel&&(identical(other.identificator, identificator) || other.identificator == identificator)&&(identical(other.name, name) || other.name == name));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,identificator,name);
@override
String toString() {
return 'UpdateDeviceRequestModel(identificator: $identificator, name: $name)';
}
}
/// @nodoc
abstract mixin class $UpdateDeviceRequestModelCopyWith<$Res> {
factory $UpdateDeviceRequestModelCopyWith(UpdateDeviceRequestModel value, $Res Function(UpdateDeviceRequestModel) _then) = _$UpdateDeviceRequestModelCopyWithImpl;
@useResult
$Res call({
String identificator, String name
});
}
/// @nodoc
class _$UpdateDeviceRequestModelCopyWithImpl<$Res>
implements $UpdateDeviceRequestModelCopyWith<$Res> {
_$UpdateDeviceRequestModelCopyWithImpl(this._self, this._then);
final UpdateDeviceRequestModel _self;
final $Res Function(UpdateDeviceRequestModel) _then;
/// Create a copy of UpdateDeviceRequestModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? identificator = null,Object? name = null,}) {
return _then(_self.copyWith(
identificator: null == identificator ? _self.identificator : identificator // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [UpdateDeviceRequestModel].
extension UpdateDeviceRequestModelPatterns on UpdateDeviceRequestModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _UpdateDeviceRequestModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _UpdateDeviceRequestModel value) $default,){
final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _UpdateDeviceRequestModel value)? $default,){
final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String identificator, String name)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel() when $default != null:
return $default(_that.identificator,_that.name);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String identificator, String name) $default,) {final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel():
return $default(_that.identificator,_that.name);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String identificator, String name)? $default,) {final _that = this;
switch (_that) {
case _UpdateDeviceRequestModel() when $default != null:
return $default(_that.identificator,_that.name);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _UpdateDeviceRequestModel implements UpdateDeviceRequestModel {
const _UpdateDeviceRequestModel({required this.identificator, required this.name});
factory _UpdateDeviceRequestModel.fromJson(Map<String, dynamic> json) => _$UpdateDeviceRequestModelFromJson(json);
@override final String identificator;
@override final String name;
/// Create a copy of UpdateDeviceRequestModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$UpdateDeviceRequestModelCopyWith<_UpdateDeviceRequestModel> get copyWith => __$UpdateDeviceRequestModelCopyWithImpl<_UpdateDeviceRequestModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$UpdateDeviceRequestModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _UpdateDeviceRequestModel&&(identical(other.identificator, identificator) || other.identificator == identificator)&&(identical(other.name, name) || other.name == name));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,identificator,name);
@override
String toString() {
return 'UpdateDeviceRequestModel(identificator: $identificator, name: $name)';
}
}
/// @nodoc
abstract mixin class _$UpdateDeviceRequestModelCopyWith<$Res> implements $UpdateDeviceRequestModelCopyWith<$Res> {
factory _$UpdateDeviceRequestModelCopyWith(_UpdateDeviceRequestModel value, $Res Function(_UpdateDeviceRequestModel) _then) = __$UpdateDeviceRequestModelCopyWithImpl;
@override @useResult
$Res call({
String identificator, String name
});
}
/// @nodoc
class __$UpdateDeviceRequestModelCopyWithImpl<$Res>
implements _$UpdateDeviceRequestModelCopyWith<$Res> {
__$UpdateDeviceRequestModelCopyWithImpl(this._self, this._then);
final _UpdateDeviceRequestModel _self;
final $Res Function(_UpdateDeviceRequestModel) _then;
/// Create a copy of UpdateDeviceRequestModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? identificator = null,Object? name = null,}) {
return _then(_UpdateDeviceRequestModel(
identificator: null == identificator ? _self.identificator : identificator // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View File

@@ -1 +1,21 @@
part of 'update_device_request_model.dart';
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'update_device_request_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_UpdateDeviceRequestModel _$UpdateDeviceRequestModelFromJson(
Map<String, dynamic> json,
) => _UpdateDeviceRequestModel(
identificator: json['identificator'] as String,
name: json['name'] as String,
);
Map<String, dynamic> _$UpdateDeviceRequestModelToJson(
_UpdateDeviceRequestModel instance,
) => <String, dynamic>{
'identificator': instance.identificator,
'name': instance.name,
};

View File

@@ -1,6 +1,7 @@
import 'package:account/src/core/data/datasource/account_remote_datasource.dart';
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:account/src/core/data/models/entities/user_entity.dart';
@@ -14,6 +15,16 @@ class AccountRepositoryImpl implements AccountRepository {
return _remote.getLinkedDevices(userId: userId);
}
@override
Future<void> deleteDevice({required String userId, required String deviceId}) {
return _remote.deleteDevice(userId: userId, deviceId: deviceId);
}
@override
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request}) {
return _remote.updateDevice(userId: userId, deviceId: deviceId, request: request);
}
@override
Future<UserEntity> getLoggedUser({required String token}) {
return _remote.getLoggedUser(token: token);
@@ -28,4 +39,9 @@ class AccountRepositoryImpl implements AccountRepository {
Future<List<UserEntity>> getAppUsers({required String userId}) {
return _remote.getAppUsers(userId: userId);
}
@override
Future<void> deleteAppUser({required String userId}) {
return _remote.deleteAppUser(userId: userId);
}
}

View File

@@ -1,13 +1,20 @@
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:account/src/core/data/models/entities/user_entity.dart';
abstract class AccountRepository {
Future<List<DeviceEntity>> getLinkedDevices({required String userId});
Future<void> updateUser({required String userId, required UpdateUserRequestEntity request});
Future<void> deleteDevice({required String userId, required String deviceId});
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request});
Future<UserEntity> getLoggedUser({required String token});
Future<void> updateUser({required String userId, required UpdateUserRequestEntity request});
Future<List<UserEntity>> getAppUsers({required String userId});
Future<void> deleteAppUser({required String userId});
}

View File

@@ -0,0 +1,4 @@
abstract class DeleteAppUserUseCase {
Future<void> deleteAppUser({required String userId});
}

View File

@@ -0,0 +1,13 @@
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/features/app_users/domain/delete_app_user_use_case.dart';
class DeleteAppUserUseCaseImpl implements DeleteAppUserUseCase {
DeleteAppUserUseCaseImpl(this._repository);
final AccountRepository _repository;
@override
Future<void> deleteAppUser({required String userId}) {
return _repository.deleteAppUser(userId: userId);
}
}

View File

@@ -0,0 +1,9 @@
import 'package:account/src/core/providers/account_repository_provider.dart';
import 'package:account/src/features/app_users/domain/delete_app_user_use_case.dart';
import 'package:account/src/features/app_users/domain/delete_app_user_use_case_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final deleteAppUserUseCaseProvider = Provider.autoDispose<DeleteAppUserUseCase>((ref) {
final authRepository = ref.read(accountRepositoryProvider);
return DeleteAppUserUseCaseImpl(authRepository);
});

View File

@@ -1,7 +1,11 @@
import 'package:account/src/core/data/models/entities/user_entity.dart';
import 'package:account/src/features/app_users/domain/delete_app_user_use_case.dart';
import 'package:account/src/features/app_users/domain/get_app_users_use_case.dart';
import 'package:account/src/features/app_users/presentation/providers/delete_app_user_use_case_provider.dart';
import 'package:account/src/features/app_users/presentation/providers/get_app_users_use_case_provider.dart';
import 'package:account/src/features/app_users/presentation/state/app_users_view_state.dart';
import 'package:account/src/features/personal_data/domain/get_logged_user_use_case.dart';
import 'package:account/src/features/personal_data/presentation/providers/get_logged_user_use_case_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:sf_localizations/sf_localizations.dart';
@@ -11,23 +15,40 @@ NotifierProvider.autoDispose<AppUsersViewModel, AppUsersViewState>(
);
class AppUsersViewModel extends Notifier<AppUsersViewState> {
late final GetLoggedUserUseCase _getLoggedUserUseCase;
late final GetAppUsersUseCase _getAppUsersUseCase;
late final DeleteAppUserUseCase _deleteAppUserUseCase;
@override
AppUsersViewState build() {
_getLoggedUserUseCase = ref.read(getLoggedUserUseCaseProvider);
_getAppUsersUseCase = ref.read(getAppUsersUseCaseProvider);
_deleteAppUserUseCase = ref.read(deleteAppUserUseCaseProvider);
_getAppUsersUseCase.getAppUsers(userId: 'test')
.then(setAppUsers);
_getLoggedUserUseCase.getLoggedUser(token: 'test').then((user){
setUser(user);
return _getAppUsersUseCase.getAppUsers(userId: user.id);
}).then(setAppUsers);
return const AppUsersViewState();
}
void setUser(UserEntity user) {
state = state.copyWith(loggedUser: user);
}
void setAppUsers(List<UserEntity> appUsers) {
state = state.copyWith(appUsers: appUsers);
state = state.copyWith(
appUsers: appUsers,
isLoading: false,
);
}
void toggleIsEditing() {
state = state.copyWith(isEditing: !state.isEditing);
}
void deleteAppUser() {
_deleteAppUserUseCase.deleteAppUser(userId: state.loggedUser!.id);
}
}

View File

@@ -7,6 +7,7 @@ part 'app_users_view_state.freezed.dart';
abstract class AppUsersViewState with _$AppUsersViewState {
const factory AppUsersViewState({
@Default(false) bool isLoading,
@Default(null) UserEntity? loggedUser,
@Default([]) List<UserEntity> appUsers,
@Default(false) bool isEditing,
@Default('') String errorMessage

View File

@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$AppUsersViewState {
bool get isLoading; List<UserEntity> get appUsers; bool get isEditing; String get errorMessage;
bool get isLoading; UserEntity? get loggedUser; List<UserEntity> get appUsers; bool get isEditing; String get errorMessage;
/// Create a copy of AppUsersViewState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -25,16 +25,16 @@ $AppUsersViewStateCopyWith<AppUsersViewState> get copyWith => _$AppUsersViewStat
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppUsersViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&const DeepCollectionEquality().equals(other.appUsers, appUsers)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is AppUsersViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&const DeepCollectionEquality().equals(other.appUsers, appUsers)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,isLoading,const DeepCollectionEquality().hash(appUsers),isEditing,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,loggedUser,const DeepCollectionEquality().hash(appUsers),isEditing,errorMessage);
@override
String toString() {
return 'AppUsersViewState(isLoading: $isLoading, appUsers: $appUsers, isEditing: $isEditing, errorMessage: $errorMessage)';
return 'AppUsersViewState(isLoading: $isLoading, loggedUser: $loggedUser, appUsers: $appUsers, isEditing: $isEditing, errorMessage: $errorMessage)';
}
@@ -45,11 +45,11 @@ abstract mixin class $AppUsersViewStateCopyWith<$Res> {
factory $AppUsersViewStateCopyWith(AppUsersViewState value, $Res Function(AppUsersViewState) _then) = _$AppUsersViewStateCopyWithImpl;
@useResult
$Res call({
bool isLoading, List<UserEntity> appUsers, bool isEditing, String errorMessage
bool isLoading, UserEntity? loggedUser, List<UserEntity> appUsers, bool isEditing, String errorMessage
});
$UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -62,16 +62,29 @@ class _$AppUsersViewStateCopyWithImpl<$Res>
/// Create a copy of AppUsersViewState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? appUsers = null,Object? isEditing = null,Object? errorMessage = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? loggedUser = freezed,Object? appUsers = null,Object? isEditing = null,Object? errorMessage = null,}) {
return _then(_self.copyWith(
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
as bool,appUsers: null == appUsers ? _self.appUsers : appUsers // ignore: cast_nullable_to_non_nullable
as bool,loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,appUsers: null == appUsers ? _self.appUsers : appUsers // ignore: cast_nullable_to_non_nullable
as List<UserEntity>,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
as bool,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of AppUsersViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
@@ -153,10 +166,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, List<UserEntity> appUsers, bool isEditing, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, UserEntity? loggedUser, List<UserEntity> appUsers, bool isEditing, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _AppUsersViewState() when $default != null:
return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
return orElse();
}
@@ -174,10 +187,10 @@ return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessag
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, List<UserEntity> appUsers, bool isEditing, String errorMessage) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, UserEntity? loggedUser, List<UserEntity> appUsers, bool isEditing, String errorMessage) $default,) {final _that = this;
switch (_that) {
case _AppUsersViewState():
return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
throw StateError('Unexpected subclass');
}
@@ -194,10 +207,10 @@ return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessag
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, List<UserEntity> appUsers, bool isEditing, String errorMessage)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, UserEntity? loggedUser, List<UserEntity> appUsers, bool isEditing, String errorMessage)? $default,) {final _that = this;
switch (_that) {
case _AppUsersViewState() when $default != null:
return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.appUsers,_that.isEditing,_that.errorMessage);case _:
return null;
}
@@ -209,10 +222,11 @@ return $default(_that.isLoading,_that.appUsers,_that.isEditing,_that.errorMessag
class _AppUsersViewState implements AppUsersViewState {
const _AppUsersViewState({this.isLoading = false, final List<UserEntity> appUsers = const [], this.isEditing = false, this.errorMessage = ''}): _appUsers = appUsers;
const _AppUsersViewState({this.isLoading = false, this.loggedUser = null, final List<UserEntity> appUsers = const [], this.isEditing = false, this.errorMessage = ''}): _appUsers = appUsers;
@override@JsonKey() final bool isLoading;
@override@JsonKey() final UserEntity? loggedUser;
final List<UserEntity> _appUsers;
@override@JsonKey() List<UserEntity> get appUsers {
if (_appUsers is EqualUnmodifiableListView) return _appUsers;
@@ -233,16 +247,16 @@ _$AppUsersViewStateCopyWith<_AppUsersViewState> get copyWith => __$AppUsersViewS
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppUsersViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&const DeepCollectionEquality().equals(other._appUsers, _appUsers)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppUsersViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&const DeepCollectionEquality().equals(other._appUsers, _appUsers)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,isLoading,const DeepCollectionEquality().hash(_appUsers),isEditing,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,loggedUser,const DeepCollectionEquality().hash(_appUsers),isEditing,errorMessage);
@override
String toString() {
return 'AppUsersViewState(isLoading: $isLoading, appUsers: $appUsers, isEditing: $isEditing, errorMessage: $errorMessage)';
return 'AppUsersViewState(isLoading: $isLoading, loggedUser: $loggedUser, appUsers: $appUsers, isEditing: $isEditing, errorMessage: $errorMessage)';
}
@@ -253,11 +267,11 @@ abstract mixin class _$AppUsersViewStateCopyWith<$Res> implements $AppUsersViewS
factory _$AppUsersViewStateCopyWith(_AppUsersViewState value, $Res Function(_AppUsersViewState) _then) = __$AppUsersViewStateCopyWithImpl;
@override @useResult
$Res call({
bool isLoading, List<UserEntity> appUsers, bool isEditing, String errorMessage
bool isLoading, UserEntity? loggedUser, List<UserEntity> appUsers, bool isEditing, String errorMessage
});
@override $UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -270,17 +284,30 @@ class __$AppUsersViewStateCopyWithImpl<$Res>
/// Create a copy of AppUsersViewState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? appUsers = null,Object? isEditing = null,Object? errorMessage = null,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? loggedUser = freezed,Object? appUsers = null,Object? isEditing = null,Object? errorMessage = null,}) {
return _then(_AppUsersViewState(
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
as bool,appUsers: null == appUsers ? _self._appUsers : appUsers // ignore: cast_nullable_to_non_nullable
as bool,loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,appUsers: null == appUsers ? _self._appUsers : appUsers // ignore: cast_nullable_to_non_nullable
as List<UserEntity>,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
as bool,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of AppUsersViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
// dart format on

View File

@@ -0,0 +1,4 @@
abstract class DeleteDeviceUseCase {
Future<void> deleteDevice({required String userId, required String deviceId});
}

View File

@@ -0,0 +1,13 @@
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/features/linked_devices/domain/delete_device_use_case.dart';
class DeleteDeviceUseCaseImpl implements DeleteDeviceUseCase {
DeleteDeviceUseCaseImpl(this._repository);
final AccountRepository _repository;
@override
Future<void> deleteDevice({required String userId, required String deviceId}) async {
return _repository.deleteDevice(userId: userId, deviceId: deviceId);
}
}

View File

@@ -0,0 +1,11 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'update_device_request_entity.freezed.dart';
@freezed
abstract class UpdateDeviceRequestEntity with _$UpdateDeviceRequestEntity {
const factory UpdateDeviceRequestEntity({
required String identificator,
required String name,
}) = _UpdateDeviceRequestEntity;
}

View File

@@ -0,0 +1 @@
part of 'update_device_request_entity.dart';

View File

@@ -1,4 +1,6 @@
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
abstract class UpdateDeviceUseCase {
Future<void> updateDevice({required String userId});
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request});
}

View File

@@ -1,4 +1,5 @@
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
// import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
// import 'package:account/src/features/linked_devices/domain/get_linked_devices_use_case.dart';
import 'package:account/src/features/linked_devices/domain/update_device_use_case.dart';
@@ -9,7 +10,7 @@ class UpdateDeviceUseCaseImpl implements UpdateDeviceUseCase {
final AccountRepository _repository;
@override
Future<void> updateDevice({required String userId}) async {
/*return _repository.updateDevice(userId: userId);*/
Future<void> updateDevice({required String userId, required String deviceId, required UpdateDeviceRequestEntity request}) async {
return _repository.updateDevice(userId: userId, deviceId: deviceId, request: request);
}
}

View File

@@ -71,6 +71,7 @@ class LinkedDevicesScreen extends ConsumerWidget {
itemBuilder: (BuildContext context, int index)=>LinkedDeviceCard(
device: state.linkedDevices[index],
isEditing: state.isEditing,
onDelete: ()=>vm.deleteDevice(state.linkedDevices[index]),
),
separatorBuilder: (BuildContext context, int index)=>SizedBox(
height: SizeUtils.getByScreen(small: 18, big: 17)
@@ -89,10 +90,12 @@ class LinkedDeviceCard extends ConsumerWidget {
final DeviceEntity device;
final bool isEditing;
final Function onDelete;
const LinkedDeviceCard({
required this.device,
required this.isEditing,
required this.onDelete,
});
@override
@@ -175,7 +178,15 @@ class LinkedDeviceCard extends ConsumerWidget {
)),
SizedBox(width: SizeUtils.getByScreen(small: 4, big: 16)),
Expanded(child: PrimaryButton(
onPressed: (){
onPressed: () async {
if (!await onDelete()) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: CustomSnackBar(
message: 'AAAAAAAAA',
type: MessageType.warning,
).build(context))
);
}
Navigator.pop(context);
},
text: 'Delete',

View File

@@ -0,0 +1,9 @@
import 'package:account/src/core/providers/account_repository_provider.dart';
import 'package:account/src/features/linked_devices/domain/delete_device_use_case.dart';
import 'package:account/src/features/linked_devices/domain/delete_device_use_case_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final deleteDeviceUseCaseProvider = Provider.autoDispose<DeleteDeviceUseCase>((ref) {
final accountRepository = ref.read(accountRepositoryProvider);
return DeleteDeviceUseCaseImpl(accountRepository);
});

View File

@@ -4,6 +4,6 @@ import 'package:account/src/features/linked_devices/domain/get_linked_devices_us
import 'package:flutter_riverpod/flutter_riverpod.dart';
final getLinkedDevicesUseCaseProvider = Provider.autoDispose<GetLinkedDevicesUseCase>((ref) {
final authRepository = ref.read(accountRepositoryProvider);
return GetLinkedDevicesUseCaseImpl(authRepository);
final accountRepository = ref.read(accountRepositoryProvider);
return GetLinkedDevicesUseCaseImpl(accountRepository);
});

View File

@@ -4,6 +4,6 @@ import 'package:account/src/features/linked_devices/domain/update_device_use_cas
import 'package:flutter_riverpod/flutter_riverpod.dart';
final updateDeviceUseCaseProvider = Provider.autoDispose<UpdateDeviceUseCase>((ref) {
final authRepository = ref.read(accountRepositoryProvider);
return UpdateDeviceUseCaseImpl(authRepository);
final accountRepository = ref.read(accountRepositoryProvider);
return UpdateDeviceUseCaseImpl(accountRepository);
});

View File

@@ -1,9 +1,15 @@
import 'package:account/src/core/data/models/entities/user_entity.dart';
import 'package:account/src/features/linked_devices/domain/delete_device_use_case.dart';
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/linked_devices/domain/get_linked_devices_use_case.dart';
import 'package:account/src/features/linked_devices/domain/update_device_use_case.dart';
import 'package:account/src/features/linked_devices/presentation/providers/delete_device_use_case_provider.dart';
import 'package:account/src/features/linked_devices/presentation/providers/get_linked_devices_use_case_provider.dart';
import 'package:account/src/features/linked_devices/presentation/providers/update_device_use_case_provider.dart';
import 'package:account/src/features/linked_devices/presentation/state/linked_devices_view_state.dart';
import 'package:account/src/features/personal_data/domain/get_logged_user_use_case.dart';
import 'package:account/src/features/personal_data/presentation/providers/get_logged_user_use_case_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:sf_localizations/sf_localizations.dart';
@@ -14,20 +20,28 @@ NotifierProvider.autoDispose<LinkedDevicesViewModel, LinkedDevicesViewState>(
);
class LinkedDevicesViewModel extends Notifier<LinkedDevicesViewState> {
late final GetLoggedUserUseCase _getLoggedUserUseCase;
late final GetLinkedDevicesUseCase _getLinkedDevicesUseCase;
late final UpdateDeviceUseCase _updateDeviceUseCase;
late final DeleteDeviceUseCase _deleteDeviceUseCase;
late final TextEditingController deviceNameController;
@override
LinkedDevicesViewState build() {
_getLoggedUserUseCase = ref.read(getLoggedUserUseCaseProvider);
_getLinkedDevicesUseCase = ref.read(getLinkedDevicesUseCaseProvider);
_updateDeviceUseCase = ref.read(updateDeviceUseCaseProvider);
_deleteDeviceUseCase = ref.read(deleteDeviceUseCaseProvider);
deviceNameController = TextEditingController();
deviceNameController.addListener(_onDeviceNameChanged);
_getLinkedDevicesUseCase.getLinkedDevices(userId: 'test')
_getLoggedUserUseCase.getLoggedUser(token: 'test')
.then((UserEntity user){
setUser(user);
return _getLinkedDevicesUseCase.getLinkedDevices(userId: user.id);
})
.then(setLinkedDevices);
ref.onDispose(disposeControllers);
@@ -35,6 +49,10 @@ class LinkedDevicesViewModel extends Notifier<LinkedDevicesViewState> {
return const LinkedDevicesViewState();
}
void setUser(UserEntity user) {
state = state.copyWith(loggedUser: user);
}
void setLinkedDevices(List<DeviceEntity> linkedDevices) {
state = state.copyWith(linkedDevices: linkedDevices);
}
@@ -53,6 +71,31 @@ class LinkedDevicesViewModel extends Notifier<LinkedDevicesViewState> {
);
}
Future<bool> deleteDevice(DeviceEntity device) async {
try {
await _deleteDeviceUseCase.deleteDevice(userId: state.loggedUser!.id, deviceId: device.identificator);
List<DeviceEntity> newList = state.linkedDevices;
newList.remove(device);
state = state.copyWith(
linkedDevices: newList
);
return true;
} catch (e) {
return false;
}
}
UpdateDeviceRequestEntity _toRequest(DeviceEntity device) {
return UpdateDeviceRequestEntity(
identificator: device.identificator,
name: state.deviceName.trim(),
// phone: /*state.dialCode.trim() + */state.phoneNumber.trim(),
);
}
void updateDevice(DeviceEntity device) {
final deviceName = state.deviceName;
@@ -62,7 +105,11 @@ class LinkedDevicesViewModel extends Notifier<LinkedDevicesViewState> {
);
return;
}
final userId = 'test';
_updateDeviceUseCase.updateDevice(
userId: userId,
deviceId: device.identificator,
request: _toRequest(device));
}

View File

@@ -1,3 +1,4 @@
import 'package:account/src/core/data/models/entities/user_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/device_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -7,6 +8,7 @@ part 'linked_devices_view_state.freezed.dart';
abstract class LinkedDevicesViewState with _$LinkedDevicesViewState {
const factory LinkedDevicesViewState({
@Default(false) bool isLoading,
@Default(null) UserEntity? loggedUser,
@Default([]) List<DeviceEntity> linkedDevices,
@Default(false) bool isEditing,
@Default('') String deviceName,

View File

@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$LinkedDevicesViewState {
bool get isLoading; List<DeviceEntity> get linkedDevices; bool get isEditing; String get deviceName; String get errorMessage;
bool get isLoading; UserEntity? get loggedUser; List<DeviceEntity> get linkedDevices; bool get isEditing; String get deviceName; String get errorMessage;
/// Create a copy of LinkedDevicesViewState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -25,16 +25,16 @@ $LinkedDevicesViewStateCopyWith<LinkedDevicesViewState> get copyWith => _$Linked
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is LinkedDevicesViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&const DeepCollectionEquality().equals(other.linkedDevices, linkedDevices)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is LinkedDevicesViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&const DeepCollectionEquality().equals(other.linkedDevices, linkedDevices)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,isLoading,const DeepCollectionEquality().hash(linkedDevices),isEditing,deviceName,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,loggedUser,const DeepCollectionEquality().hash(linkedDevices),isEditing,deviceName,errorMessage);
@override
String toString() {
return 'LinkedDevicesViewState(isLoading: $isLoading, linkedDevices: $linkedDevices, isEditing: $isEditing, deviceName: $deviceName, errorMessage: $errorMessage)';
return 'LinkedDevicesViewState(isLoading: $isLoading, loggedUser: $loggedUser, linkedDevices: $linkedDevices, isEditing: $isEditing, deviceName: $deviceName, errorMessage: $errorMessage)';
}
@@ -45,11 +45,11 @@ abstract mixin class $LinkedDevicesViewStateCopyWith<$Res> {
factory $LinkedDevicesViewStateCopyWith(LinkedDevicesViewState value, $Res Function(LinkedDevicesViewState) _then) = _$LinkedDevicesViewStateCopyWithImpl;
@useResult
$Res call({
bool isLoading, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage
bool isLoading, UserEntity? loggedUser, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage
});
$UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -62,17 +62,30 @@ class _$LinkedDevicesViewStateCopyWithImpl<$Res>
/// Create a copy of LinkedDevicesViewState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? linkedDevices = null,Object? isEditing = null,Object? deviceName = null,Object? errorMessage = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? loggedUser = freezed,Object? linkedDevices = null,Object? isEditing = null,Object? deviceName = null,Object? errorMessage = null,}) {
return _then(_self.copyWith(
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
as bool,linkedDevices: null == linkedDevices ? _self.linkedDevices : linkedDevices // ignore: cast_nullable_to_non_nullable
as bool,loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,linkedDevices: null == linkedDevices ? _self.linkedDevices : linkedDevices // ignore: cast_nullable_to_non_nullable
as List<DeviceEntity>,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
as bool,deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of LinkedDevicesViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
@@ -154,10 +167,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, UserEntity? loggedUser, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _LinkedDevicesViewState() when $default != null:
return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
return orElse();
}
@@ -175,10 +188,10 @@ return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.device
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, UserEntity? loggedUser, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage) $default,) {final _that = this;
switch (_that) {
case _LinkedDevicesViewState():
return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
throw StateError('Unexpected subclass');
}
@@ -195,10 +208,10 @@ return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.device
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, UserEntity? loggedUser, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage)? $default,) {final _that = this;
switch (_that) {
case _LinkedDevicesViewState() when $default != null:
return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
return $default(_that.isLoading,_that.loggedUser,_that.linkedDevices,_that.isEditing,_that.deviceName,_that.errorMessage);case _:
return null;
}
@@ -210,10 +223,11 @@ return $default(_that.isLoading,_that.linkedDevices,_that.isEditing,_that.device
class _LinkedDevicesViewState implements LinkedDevicesViewState {
const _LinkedDevicesViewState({this.isLoading = false, final List<DeviceEntity> linkedDevices = const [], this.isEditing = false, this.deviceName = '', this.errorMessage = ''}): _linkedDevices = linkedDevices;
const _LinkedDevicesViewState({this.isLoading = false, this.loggedUser = null, final List<DeviceEntity> linkedDevices = const [], this.isEditing = false, this.deviceName = '', this.errorMessage = ''}): _linkedDevices = linkedDevices;
@override@JsonKey() final bool isLoading;
@override@JsonKey() final UserEntity? loggedUser;
final List<DeviceEntity> _linkedDevices;
@override@JsonKey() List<DeviceEntity> get linkedDevices {
if (_linkedDevices is EqualUnmodifiableListView) return _linkedDevices;
@@ -235,16 +249,16 @@ _$LinkedDevicesViewStateCopyWith<_LinkedDevicesViewState> get copyWith => __$Lin
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LinkedDevicesViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&const DeepCollectionEquality().equals(other._linkedDevices, _linkedDevices)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LinkedDevicesViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&const DeepCollectionEquality().equals(other._linkedDevices, _linkedDevices)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,isLoading,const DeepCollectionEquality().hash(_linkedDevices),isEditing,deviceName,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,loggedUser,const DeepCollectionEquality().hash(_linkedDevices),isEditing,deviceName,errorMessage);
@override
String toString() {
return 'LinkedDevicesViewState(isLoading: $isLoading, linkedDevices: $linkedDevices, isEditing: $isEditing, deviceName: $deviceName, errorMessage: $errorMessage)';
return 'LinkedDevicesViewState(isLoading: $isLoading, loggedUser: $loggedUser, linkedDevices: $linkedDevices, isEditing: $isEditing, deviceName: $deviceName, errorMessage: $errorMessage)';
}
@@ -255,11 +269,11 @@ abstract mixin class _$LinkedDevicesViewStateCopyWith<$Res> implements $LinkedDe
factory _$LinkedDevicesViewStateCopyWith(_LinkedDevicesViewState value, $Res Function(_LinkedDevicesViewState) _then) = __$LinkedDevicesViewStateCopyWithImpl;
@override @useResult
$Res call({
bool isLoading, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage
bool isLoading, UserEntity? loggedUser, List<DeviceEntity> linkedDevices, bool isEditing, String deviceName, String errorMessage
});
@override $UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -272,10 +286,11 @@ class __$LinkedDevicesViewStateCopyWithImpl<$Res>
/// Create a copy of LinkedDevicesViewState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? linkedDevices = null,Object? isEditing = null,Object? deviceName = null,Object? errorMessage = null,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? loggedUser = freezed,Object? linkedDevices = null,Object? isEditing = null,Object? deviceName = null,Object? errorMessage = null,}) {
return _then(_LinkedDevicesViewState(
isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
as bool,linkedDevices: null == linkedDevices ? _self._linkedDevices : linkedDevices // ignore: cast_nullable_to_non_nullable
as bool,loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,linkedDevices: null == linkedDevices ? _self._linkedDevices : linkedDevices // ignore: cast_nullable_to_non_nullable
as List<DeviceEntity>,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
as bool,deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
@@ -283,7 +298,19 @@ as String,
));
}
/// Create a copy of LinkedDevicesViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
// dart format on