Sender Invitation
This commit is contained in:
56
frontend/pshared/lib/data/dto/invitation/invitation.dart
Normal file
56
frontend/pshared/lib/data/dto/invitation/invitation.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/date_time.dart';
|
||||
import 'package:pshared/data/dto/permissions/bound.dart';
|
||||
|
||||
part 'invitation.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class InvitationContentDTO {
|
||||
final String email;
|
||||
final String name;
|
||||
final String comment;
|
||||
|
||||
const InvitationContentDTO({
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.comment,
|
||||
});
|
||||
|
||||
factory InvitationContentDTO.fromJson(Map<String, dynamic> json) => _$InvitationContentDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$InvitationContentDTOToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class InvitationDTO extends PermissionBoundDTO {
|
||||
final String roleRef;
|
||||
final String inviterRef;
|
||||
final String status;
|
||||
|
||||
@UtcIso8601Converter()
|
||||
final DateTime expiresAt;
|
||||
|
||||
@JsonKey(name: 'description')
|
||||
final InvitationContentDTO content;
|
||||
|
||||
@JsonKey(defaultValue: false)
|
||||
final bool isArchived;
|
||||
|
||||
const InvitationDTO({
|
||||
required super.id,
|
||||
required super.createdAt,
|
||||
required super.updatedAt,
|
||||
required super.permissionRef,
|
||||
required super.organizationRef,
|
||||
required this.roleRef,
|
||||
required this.inviterRef,
|
||||
required this.status,
|
||||
required this.expiresAt,
|
||||
required this.content,
|
||||
this.isArchived = false,
|
||||
});
|
||||
|
||||
factory InvitationDTO.fromJson(Map<String, dynamic> json) => _$InvitationDTOFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$InvitationDTOToJson(this);
|
||||
}
|
||||
78
frontend/pshared/lib/data/mapper/invitation/invitation.dart
Normal file
78
frontend/pshared/lib/data/mapper/invitation/invitation.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:pshared/data/dto/invitation/invitation.dart';
|
||||
import 'package:pshared/models/invitation/invitation.dart';
|
||||
import 'package:pshared/models/invitation/status.dart';
|
||||
import 'package:pshared/models/organization/bound.dart';
|
||||
import 'package:pshared/models/permissions/bound.dart';
|
||||
import 'package:pshared/models/storable.dart';
|
||||
|
||||
|
||||
extension InvitationModelMapper on Invitation {
|
||||
InvitationDTO toDTO() => InvitationDTO(
|
||||
id: storable.id,
|
||||
createdAt: storable.createdAt,
|
||||
updatedAt: storable.updatedAt,
|
||||
permissionRef: permissionBound.permissionRef,
|
||||
organizationRef: permissionBound.organizationRef,
|
||||
roleRef: roleRef,
|
||||
inviterRef: inviterRef,
|
||||
status: _statusToValue(status),
|
||||
expiresAt: expiresAt,
|
||||
content: InvitationContentDTO(
|
||||
email: content.email,
|
||||
name: content.name,
|
||||
comment: content.comment,
|
||||
),
|
||||
isArchived: isArchived,
|
||||
);
|
||||
}
|
||||
|
||||
extension InvitationDTOMapper on InvitationDTO {
|
||||
Invitation toDomain() => Invitation(
|
||||
storable: newStorable(id: id, createdAt: createdAt, updatedAt: updatedAt),
|
||||
permissionBound: newPermissionBound(
|
||||
organizationBound: newOrganizationBound(organizationRef: organizationRef),
|
||||
permissionRef: permissionRef,
|
||||
),
|
||||
roleRef: roleRef,
|
||||
inviterRef: inviterRef,
|
||||
status: _statusFromValue(status),
|
||||
expiresAt: expiresAt.toUtc(),
|
||||
content: InvitationContent(
|
||||
email: content.email,
|
||||
name: content.name,
|
||||
comment: content.comment,
|
||||
),
|
||||
isArchived: isArchived,
|
||||
);
|
||||
}
|
||||
|
||||
InvitationStatus _statusFromValue(String value) {
|
||||
switch (value) {
|
||||
case 'sent':
|
||||
return InvitationStatus.sent;
|
||||
case 'accepted':
|
||||
return InvitationStatus.accepted;
|
||||
case 'declined':
|
||||
return InvitationStatus.declined;
|
||||
case 'revoked':
|
||||
return InvitationStatus.revoked;
|
||||
case 'created':
|
||||
default:
|
||||
return InvitationStatus.created;
|
||||
}
|
||||
}
|
||||
|
||||
String _statusToValue(InvitationStatus status) {
|
||||
switch (status) {
|
||||
case InvitationStatus.sent:
|
||||
return 'sent';
|
||||
case InvitationStatus.accepted:
|
||||
return 'accepted';
|
||||
case InvitationStatus.declined:
|
||||
return 'declined';
|
||||
case InvitationStatus.revoked:
|
||||
return 'revoked';
|
||||
case InvitationStatus.created:
|
||||
return 'created';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user