Init login feature add data layer
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class UserIdConverter implements JsonConverter<UserId, String> {
|
||||
const UserIdConverter();
|
||||
|
||||
@override
|
||||
UserId fromJson(String json) => UserId(json);
|
||||
|
||||
@override
|
||||
String toJson(UserId object) => jsonEncode(object.id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class AccountRequest with EquatableMixin {
|
||||
final UserName userName;
|
||||
final Password password;
|
||||
|
||||
AccountRequest(this.userName, this.password);
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'username': userName.userName,
|
||||
'password': password.value,
|
||||
};
|
||||
|
||||
@override
|
||||
List<Object> get props => [userName, password];
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/converter/user_id_converter.dart';
|
||||
|
||||
part 'user_response.g.dart';
|
||||
|
||||
@UserIdConverter()
|
||||
@JsonSerializable()
|
||||
class UserResponse with EquatableMixin {
|
||||
|
||||
@JsonKey(name: Constant.userId)
|
||||
final UserId userId;
|
||||
@JsonKey(name: Constant.firstName)
|
||||
final String firstName;
|
||||
@JsonKey(name: Constant.lastName)
|
||||
final String lastName;
|
||||
|
||||
UserResponse(
|
||||
this.userId,
|
||||
this.firstName,
|
||||
this.lastName
|
||||
);
|
||||
|
||||
factory UserResponse.fromJson(Map<String, dynamic> json) => _$UserResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserResponseToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
userId,
|
||||
firstName,
|
||||
lastName,
|
||||
];
|
||||
}
|
||||
|
||||
extension UserResponseExtension on UserResponse {
|
||||
User toUser() {
|
||||
return User(
|
||||
userId,
|
||||
firstName,
|
||||
lastName,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user