mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web,server): activity (#4682)
* feat: activity * regenerate api * fix: make asset owner unable to delete comment * fix: merge * fix: tests * feat: use textarea instead of input * fix: do actions only if the album is shared * fix: placeholder opacity * fix(web): improve messages UI * fix(web): improve input message UI * pr feedback * fix: tests * pr feedback * pr feedback * pr feedback * fix permissions * regenerate api * pr feedback * pr feedback * multiple improvements on web * fix: ui colors * WIP * chore: open api * pr feedback * fix: add comment * chore: clean up * pr feedback * refactor: endpoints * chore: open api * fix: filter by type * fix: e2e * feat: e2e remove own comment * fix: web tests * remove console.log * chore: cleanup * fix: ui tweaks * pr feedback * fix web test * fix: unit tests * chore: remove unused code * revert useless changes * fix: grouping messages * fix: remove nullable on updatedAt * fix: text overflow * styling --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
68f6446718
commit
ce5966c23d
66 changed files with 4487 additions and 38 deletions
140
mobile/openapi/lib/model/activity_create_dto.dart
generated
Normal file
140
mobile/openapi/lib/model/activity_create_dto.dart
generated
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class ActivityCreateDto {
|
||||
/// Returns a new [ActivityCreateDto] instance.
|
||||
ActivityCreateDto({
|
||||
required this.albumId,
|
||||
this.assetId,
|
||||
this.comment,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
String albumId;
|
||||
|
||||
///
|
||||
/// Please note: This property should have been non-nullable! Since the specification file
|
||||
/// does not include a default value (using the "default:" property), however, the generated
|
||||
/// source code must fall back to having a nullable type.
|
||||
/// Consider adding a "default:" property in the specification file to hide this note.
|
||||
///
|
||||
String? assetId;
|
||||
|
||||
///
|
||||
/// Please note: This property should have been non-nullable! Since the specification file
|
||||
/// does not include a default value (using the "default:" property), however, the generated
|
||||
/// source code must fall back to having a nullable type.
|
||||
/// Consider adding a "default:" property in the specification file to hide this note.
|
||||
///
|
||||
String? comment;
|
||||
|
||||
ReactionType type;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is ActivityCreateDto &&
|
||||
other.albumId == albumId &&
|
||||
other.assetId == assetId &&
|
||||
other.comment == comment &&
|
||||
other.type == type;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(albumId.hashCode) +
|
||||
(assetId == null ? 0 : assetId!.hashCode) +
|
||||
(comment == null ? 0 : comment!.hashCode) +
|
||||
(type.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'ActivityCreateDto[albumId=$albumId, assetId=$assetId, comment=$comment, type=$type]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
json[r'albumId'] = this.albumId;
|
||||
if (this.assetId != null) {
|
||||
json[r'assetId'] = this.assetId;
|
||||
} else {
|
||||
// json[r'assetId'] = null;
|
||||
}
|
||||
if (this.comment != null) {
|
||||
json[r'comment'] = this.comment;
|
||||
} else {
|
||||
// json[r'comment'] = null;
|
||||
}
|
||||
json[r'type'] = this.type;
|
||||
return json;
|
||||
}
|
||||
|
||||
/// Returns a new [ActivityCreateDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static ActivityCreateDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
return ActivityCreateDto(
|
||||
albumId: mapValueOfType<String>(json, r'albumId')!,
|
||||
assetId: mapValueOfType<String>(json, r'assetId'),
|
||||
comment: mapValueOfType<String>(json, r'comment'),
|
||||
type: ReactionType.fromJson(json[r'type'])!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<ActivityCreateDto> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <ActivityCreateDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = ActivityCreateDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, ActivityCreateDto> mapFromJson(dynamic json) {
|
||||
final map = <String, ActivityCreateDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = ActivityCreateDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of ActivityCreateDto-objects as value to a dart map
|
||||
static Map<String, List<ActivityCreateDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<ActivityCreateDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
// ignore: parameter_assignments
|
||||
json = json.cast<String, dynamic>();
|
||||
for (final entry in json.entries) {
|
||||
map[entry.key] = ActivityCreateDto.listFromJson(entry.value, growable: growable,);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'albumId',
|
||||
'type',
|
||||
};
|
||||
}
|
||||
|
||||
219
mobile/openapi/lib/model/activity_response_dto.dart
generated
Normal file
219
mobile/openapi/lib/model/activity_response_dto.dart
generated
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class ActivityResponseDto {
|
||||
/// Returns a new [ActivityResponseDto] instance.
|
||||
ActivityResponseDto({
|
||||
required this.assetId,
|
||||
this.comment,
|
||||
required this.createdAt,
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.user,
|
||||
});
|
||||
|
||||
String? assetId;
|
||||
|
||||
String? comment;
|
||||
|
||||
DateTime createdAt;
|
||||
|
||||
String id;
|
||||
|
||||
ActivityResponseDtoTypeEnum type;
|
||||
|
||||
UserDto user;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is ActivityResponseDto &&
|
||||
other.assetId == assetId &&
|
||||
other.comment == comment &&
|
||||
other.createdAt == createdAt &&
|
||||
other.id == id &&
|
||||
other.type == type &&
|
||||
other.user == user;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(assetId == null ? 0 : assetId!.hashCode) +
|
||||
(comment == null ? 0 : comment!.hashCode) +
|
||||
(createdAt.hashCode) +
|
||||
(id.hashCode) +
|
||||
(type.hashCode) +
|
||||
(user.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'ActivityResponseDto[assetId=$assetId, comment=$comment, createdAt=$createdAt, id=$id, type=$type, user=$user]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
if (this.assetId != null) {
|
||||
json[r'assetId'] = this.assetId;
|
||||
} else {
|
||||
// json[r'assetId'] = null;
|
||||
}
|
||||
if (this.comment != null) {
|
||||
json[r'comment'] = this.comment;
|
||||
} else {
|
||||
// json[r'comment'] = null;
|
||||
}
|
||||
json[r'createdAt'] = this.createdAt.toUtc().toIso8601String();
|
||||
json[r'id'] = this.id;
|
||||
json[r'type'] = this.type;
|
||||
json[r'user'] = this.user;
|
||||
return json;
|
||||
}
|
||||
|
||||
/// Returns a new [ActivityResponseDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static ActivityResponseDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
return ActivityResponseDto(
|
||||
assetId: mapValueOfType<String>(json, r'assetId'),
|
||||
comment: mapValueOfType<String>(json, r'comment'),
|
||||
createdAt: mapDateTime(json, r'createdAt', '')!,
|
||||
id: mapValueOfType<String>(json, r'id')!,
|
||||
type: ActivityResponseDtoTypeEnum.fromJson(json[r'type'])!,
|
||||
user: UserDto.fromJson(json[r'user'])!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<ActivityResponseDto> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <ActivityResponseDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = ActivityResponseDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, ActivityResponseDto> mapFromJson(dynamic json) {
|
||||
final map = <String, ActivityResponseDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = ActivityResponseDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of ActivityResponseDto-objects as value to a dart map
|
||||
static Map<String, List<ActivityResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<ActivityResponseDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
// ignore: parameter_assignments
|
||||
json = json.cast<String, dynamic>();
|
||||
for (final entry in json.entries) {
|
||||
map[entry.key] = ActivityResponseDto.listFromJson(entry.value, growable: growable,);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'assetId',
|
||||
'createdAt',
|
||||
'id',
|
||||
'type',
|
||||
'user',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
class ActivityResponseDtoTypeEnum {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const ActivityResponseDtoTypeEnum._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const comment = ActivityResponseDtoTypeEnum._(r'comment');
|
||||
static const like = ActivityResponseDtoTypeEnum._(r'like');
|
||||
|
||||
/// List of all possible values in this [enum][ActivityResponseDtoTypeEnum].
|
||||
static const values = <ActivityResponseDtoTypeEnum>[
|
||||
comment,
|
||||
like,
|
||||
];
|
||||
|
||||
static ActivityResponseDtoTypeEnum? fromJson(dynamic value) => ActivityResponseDtoTypeEnumTypeTransformer().decode(value);
|
||||
|
||||
static List<ActivityResponseDtoTypeEnum>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <ActivityResponseDtoTypeEnum>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = ActivityResponseDtoTypeEnum.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [ActivityResponseDtoTypeEnum] to String,
|
||||
/// and [decode] dynamic data back to [ActivityResponseDtoTypeEnum].
|
||||
class ActivityResponseDtoTypeEnumTypeTransformer {
|
||||
factory ActivityResponseDtoTypeEnumTypeTransformer() => _instance ??= const ActivityResponseDtoTypeEnumTypeTransformer._();
|
||||
|
||||
const ActivityResponseDtoTypeEnumTypeTransformer._();
|
||||
|
||||
String encode(ActivityResponseDtoTypeEnum data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a ActivityResponseDtoTypeEnum.
|
||||
///
|
||||
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||
///
|
||||
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||
/// and users are still using an old app with the old code.
|
||||
ActivityResponseDtoTypeEnum? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case r'comment': return ActivityResponseDtoTypeEnum.comment;
|
||||
case r'like': return ActivityResponseDtoTypeEnum.like;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [ActivityResponseDtoTypeEnumTypeTransformer] instance.
|
||||
static ActivityResponseDtoTypeEnumTypeTransformer? _instance;
|
||||
}
|
||||
|
||||
|
||||
98
mobile/openapi/lib/model/activity_statistics_response_dto.dart
generated
Normal file
98
mobile/openapi/lib/model/activity_statistics_response_dto.dart
generated
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class ActivityStatisticsResponseDto {
|
||||
/// Returns a new [ActivityStatisticsResponseDto] instance.
|
||||
ActivityStatisticsResponseDto({
|
||||
required this.comments,
|
||||
});
|
||||
|
||||
int comments;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is ActivityStatisticsResponseDto &&
|
||||
other.comments == comments;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(comments.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'ActivityStatisticsResponseDto[comments=$comments]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
json[r'comments'] = this.comments;
|
||||
return json;
|
||||
}
|
||||
|
||||
/// Returns a new [ActivityStatisticsResponseDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static ActivityStatisticsResponseDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
return ActivityStatisticsResponseDto(
|
||||
comments: mapValueOfType<int>(json, r'comments')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<ActivityStatisticsResponseDto> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <ActivityStatisticsResponseDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = ActivityStatisticsResponseDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, ActivityStatisticsResponseDto> mapFromJson(dynamic json) {
|
||||
final map = <String, ActivityStatisticsResponseDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = ActivityStatisticsResponseDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of ActivityStatisticsResponseDto-objects as value to a dart map
|
||||
static Map<String, List<ActivityStatisticsResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<ActivityStatisticsResponseDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
// ignore: parameter_assignments
|
||||
json = json.cast<String, dynamic>();
|
||||
for (final entry in json.entries) {
|
||||
map[entry.key] = ActivityStatisticsResponseDto.listFromJson(entry.value, growable: growable,);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'comments',
|
||||
};
|
||||
}
|
||||
|
||||
85
mobile/openapi/lib/model/reaction_type.dart
generated
Normal file
85
mobile/openapi/lib/model/reaction_type.dart
generated
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
|
||||
class ReactionType {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const ReactionType._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const comment = ReactionType._(r'comment');
|
||||
static const like = ReactionType._(r'like');
|
||||
|
||||
/// List of all possible values in this [enum][ReactionType].
|
||||
static const values = <ReactionType>[
|
||||
comment,
|
||||
like,
|
||||
];
|
||||
|
||||
static ReactionType? fromJson(dynamic value) => ReactionTypeTypeTransformer().decode(value);
|
||||
|
||||
static List<ReactionType>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <ReactionType>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = ReactionType.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [ReactionType] to String,
|
||||
/// and [decode] dynamic data back to [ReactionType].
|
||||
class ReactionTypeTypeTransformer {
|
||||
factory ReactionTypeTypeTransformer() => _instance ??= const ReactionTypeTypeTransformer._();
|
||||
|
||||
const ReactionTypeTypeTransformer._();
|
||||
|
||||
String encode(ReactionType data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a ReactionType.
|
||||
///
|
||||
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||
///
|
||||
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||
/// and users are still using an old app with the old code.
|
||||
ReactionType? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case r'comment': return ReactionType.comment;
|
||||
case r'like': return ReactionType.like;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [ReactionTypeTypeTransformer] instance.
|
||||
static ReactionTypeTypeTransformer? _instance;
|
||||
}
|
||||
|
||||
130
mobile/openapi/lib/model/user_dto.dart
generated
Normal file
130
mobile/openapi/lib/model/user_dto.dart
generated
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class UserDto {
|
||||
/// Returns a new [UserDto] instance.
|
||||
UserDto({
|
||||
required this.email,
|
||||
required this.firstName,
|
||||
required this.id,
|
||||
required this.lastName,
|
||||
required this.profileImagePath,
|
||||
});
|
||||
|
||||
String email;
|
||||
|
||||
String firstName;
|
||||
|
||||
String id;
|
||||
|
||||
String lastName;
|
||||
|
||||
String profileImagePath;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is UserDto &&
|
||||
other.email == email &&
|
||||
other.firstName == firstName &&
|
||||
other.id == id &&
|
||||
other.lastName == lastName &&
|
||||
other.profileImagePath == profileImagePath;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(email.hashCode) +
|
||||
(firstName.hashCode) +
|
||||
(id.hashCode) +
|
||||
(lastName.hashCode) +
|
||||
(profileImagePath.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'UserDto[email=$email, firstName=$firstName, id=$id, lastName=$lastName, profileImagePath=$profileImagePath]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
json[r'email'] = this.email;
|
||||
json[r'firstName'] = this.firstName;
|
||||
json[r'id'] = this.id;
|
||||
json[r'lastName'] = this.lastName;
|
||||
json[r'profileImagePath'] = this.profileImagePath;
|
||||
return json;
|
||||
}
|
||||
|
||||
/// Returns a new [UserDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static UserDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
return UserDto(
|
||||
email: mapValueOfType<String>(json, r'email')!,
|
||||
firstName: mapValueOfType<String>(json, r'firstName')!,
|
||||
id: mapValueOfType<String>(json, r'id')!,
|
||||
lastName: mapValueOfType<String>(json, r'lastName')!,
|
||||
profileImagePath: mapValueOfType<String>(json, r'profileImagePath')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<UserDto> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <UserDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = UserDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, UserDto> mapFromJson(dynamic json) {
|
||||
final map = <String, UserDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = UserDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of UserDto-objects as value to a dart map
|
||||
static Map<String, List<UserDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<UserDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
// ignore: parameter_assignments
|
||||
json = json.cast<String, dynamic>();
|
||||
for (final entry in json.entries) {
|
||||
map[entry.key] = UserDto.listFromJson(entry.value, growable: growable,);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'email',
|
||||
'firstName',
|
||||
'id',
|
||||
'lastName',
|
||||
'profileImagePath',
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue