Frontend first draft
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
class AuthorizationFailed implements Exception {
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
class ErrorFailedToReadImage implements Exception {
|
||||
}
|
||||
2
frontend/pshared/lib/api/errors/unauthorized.dart
Normal file
2
frontend/pshared/lib/api/errors/unauthorized.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
class ErrorUnauthorized implements Exception {
|
||||
}
|
||||
2
frontend/pshared/lib/api/errors/upload_failed.dart
Normal file
2
frontend/pshared/lib/api/errors/upload_failed.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
class ErrorUploadFailed implements Exception {
|
||||
}
|
||||
18
frontend/pshared/lib/api/requests/change_password.dart
Normal file
18
frontend/pshared/lib/api/requests/change_password.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'change_password.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ChangePassword {
|
||||
@JsonKey(name: 'old')
|
||||
final String oldPassword;
|
||||
|
||||
@JsonKey(name: 'new')
|
||||
final String newPassword;
|
||||
|
||||
const ChangePassword({required this.oldPassword, required this.newPassword});
|
||||
|
||||
factory ChangePassword.fromJson(Map<String, dynamic> json) => _$ChangePasswordFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ChangePasswordToJson(this);
|
||||
}
|
||||
18
frontend/pshared/lib/api/requests/change_role.dart
Normal file
18
frontend/pshared/lib/api/requests/change_role.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'change_role.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ChangeRole {
|
||||
final String accountRef;
|
||||
final String newRoleDescriptionRef;
|
||||
|
||||
const ChangeRole({
|
||||
required this.accountRef,
|
||||
required this.newRoleDescriptionRef,
|
||||
});
|
||||
|
||||
factory ChangeRole.fromJson(Map<String, dynamic> json) => _$ChangeRoleFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ChangeRoleToJson(this);
|
||||
}
|
||||
15
frontend/pshared/lib/api/requests/file_upload.dart
Normal file
15
frontend/pshared/lib/api/requests/file_upload.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'file_upload.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class FileUpload {
|
||||
|
||||
final String objRef;
|
||||
|
||||
const FileUpload({ required this.objRef });
|
||||
|
||||
factory FileUpload.fromJson(Map<String, dynamic> json) => _$FileUploadFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$FileUploadToJson(this);
|
||||
}
|
||||
24
frontend/pshared/lib/api/requests/login.dart
Normal file
24
frontend/pshared/lib/api/requests/login.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'login.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class LoginRequest {
|
||||
final String login;
|
||||
final String password;
|
||||
final String locale;
|
||||
final String clientId;
|
||||
final String deviceId;
|
||||
|
||||
const LoginRequest({
|
||||
required this.login,
|
||||
required this.password,
|
||||
required this.locale,
|
||||
required this.clientId,
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
factory LoginRequest.fromJson(Map<String, dynamic> json) => _$LoginRequestFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$LoginRequestToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/permissions/data/policy.dart';
|
||||
import 'package:pshared/data/mapper/permissions/data/policy.dart';
|
||||
import 'package:pshared/models/permissions/data/policy.dart';
|
||||
|
||||
part 'change_policies.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class PoliciesChangeRequest {
|
||||
final List<PolicyDTO>? add;
|
||||
final List<PolicyDTO>? remove;
|
||||
|
||||
const PoliciesChangeRequest({
|
||||
this.add,
|
||||
this.remove,
|
||||
});
|
||||
|
||||
factory PoliciesChangeRequest.add({required List<Policy> policies}) => PoliciesChangeRequest(
|
||||
add: policies.map((policy) => policy.toDTO()).toList(),
|
||||
);
|
||||
|
||||
factory PoliciesChangeRequest.remove({required List<Policy> policies}) => PoliciesChangeRequest(
|
||||
remove: policies.map((policy) => policy.toDTO()).toList(),
|
||||
);
|
||||
|
||||
factory PoliciesChangeRequest.change({
|
||||
required List<Policy> add,
|
||||
required List<Policy> remove,
|
||||
}) => PoliciesChangeRequest(
|
||||
add: add.map((policy) => policy.toDTO()).toList(),
|
||||
remove: remove.map((policy) => policy.toDTO()).toList(),
|
||||
);
|
||||
|
||||
factory PoliciesChangeRequest.fromJson(Map<String, dynamic> json) => _$PoliciesChangeRequestFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PoliciesChangeRequestToJson(this);
|
||||
}
|
||||
42
frontend/pshared/lib/api/requests/signup.dart
Normal file
42
frontend/pshared/lib/api/requests/signup.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'signup.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class SignupRequest {
|
||||
final String name;
|
||||
final String login;
|
||||
final String password;
|
||||
final String locale;
|
||||
final String organizationName;
|
||||
final String organizationTimeZone;
|
||||
|
||||
const SignupRequest({
|
||||
required this.name,
|
||||
required this.login,
|
||||
required this.password,
|
||||
required this.locale,
|
||||
required this.organizationName,
|
||||
required this.organizationTimeZone,
|
||||
});
|
||||
|
||||
factory SignupRequest.build({
|
||||
required String name,
|
||||
required String login,
|
||||
required String password,
|
||||
required String locale,
|
||||
required String organizationName,
|
||||
required String organizationTimeZone,
|
||||
}) => SignupRequest(
|
||||
name: name,
|
||||
login: login,
|
||||
password: password,
|
||||
locale: locale,
|
||||
organizationName: organizationName,
|
||||
organizationTimeZone: organizationTimeZone,
|
||||
);
|
||||
|
||||
factory SignupRequest.fromJson(Map<String, dynamic> json) => _$SignupRequestFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SignupRequestToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import 'package:pshared/api/requests/tokens/refresh_rotate.dart';
|
||||
|
||||
|
||||
typedef AccessTokenRefreshRequest = RotateRefreshTokenRequest;
|
||||
21
frontend/pshared/lib/api/requests/tokens/refresh_rotate.dart
Normal file
21
frontend/pshared/lib/api/requests/tokens/refresh_rotate.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/requests/tokens/session_id.dart';
|
||||
|
||||
part 'refresh_rotate.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class RotateRefreshTokenRequest extends SessionID {
|
||||
final String token;
|
||||
|
||||
const RotateRefreshTokenRequest({
|
||||
required this.token,
|
||||
required super.clientId,
|
||||
required super.deviceId,
|
||||
});
|
||||
|
||||
factory RotateRefreshTokenRequest.fromJson(Map<String, dynamic> json) => _$RotateRefreshTokenRequestFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$RotateRefreshTokenRequestToJson(this);
|
||||
}
|
||||
18
frontend/pshared/lib/api/requests/tokens/session_id.dart
Normal file
18
frontend/pshared/lib/api/requests/tokens/session_id.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'session_id.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class SessionID {
|
||||
final String clientId;
|
||||
final String deviceId;
|
||||
|
||||
const SessionID({
|
||||
required this.clientId,
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
factory SessionID.fromJson(Map<String, dynamic> json) => _$SessionIDFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SessionIDToJson(this);
|
||||
}
|
||||
18
frontend/pshared/lib/api/responses/account.dart
Normal file
18
frontend/pshared/lib/api/responses/account.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/account/account.dart';
|
||||
|
||||
part 'account.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class AccountResponse {
|
||||
final AccountDTO account;
|
||||
final TokenData accessToken;
|
||||
|
||||
const AccountResponse({required this.accessToken, required this.account});
|
||||
|
||||
factory AccountResponse.fromJson(Map<String, dynamic> json) => _$AccountResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AccountResponseToJson(this);
|
||||
}
|
||||
16
frontend/pshared/lib/api/responses/base.dart
Normal file
16
frontend/pshared/lib/api/responses/base.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
|
||||
part 'base.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class BaseAuthorizedResponse {
|
||||
final TokenData accessToken;
|
||||
|
||||
const BaseAuthorizedResponse({required this.accessToken});
|
||||
|
||||
factory BaseAuthorizedResponse.fromJson(Map<String, dynamic> json) => _$BaseAuthorizedResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$BaseAuthorizedResponseToJson(this);
|
||||
}
|
||||
18
frontend/pshared/lib/api/responses/employees.dart
Normal file
18
frontend/pshared/lib/api/responses/employees.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/account/account.dart';
|
||||
|
||||
part 'employees.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class EmployeesResponse {
|
||||
final List<AccountDTO> accounts;
|
||||
final TokenData accessToken;
|
||||
|
||||
const EmployeesResponse({required this.accessToken, required this.accounts});
|
||||
|
||||
factory EmployeesResponse.fromJson(Map<String, dynamic> json) => _$EmployeesResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$EmployeesResponseToJson(this);
|
||||
}
|
||||
13
frontend/pshared/lib/api/responses/error/connectivity.dart
Normal file
13
frontend/pshared/lib/api/responses/error/connectivity.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
class ConnectivityError implements Exception {
|
||||
final int? code;
|
||||
final String message;
|
||||
|
||||
const ConnectivityError({this.code, required this.message});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return code == null
|
||||
? 'Error response, message: $message)'
|
||||
: 'Error response (code: $code, message: $message)';
|
||||
}
|
||||
}
|
||||
43
frontend/pshared/lib/api/responses/error/server.dart
Normal file
43
frontend/pshared/lib/api/responses/error/server.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'server.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class ErrorResponse implements Exception {
|
||||
final int code;
|
||||
final String details;
|
||||
final String source;
|
||||
final String error;
|
||||
|
||||
const ErrorResponse({
|
||||
required this.code,
|
||||
required this.details,
|
||||
required this.error,
|
||||
required this.source,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final buffer = StringBuffer('Error response (code: $code');
|
||||
|
||||
if (details.isNotEmpty) {
|
||||
buffer.write(', details: $details');
|
||||
}
|
||||
|
||||
if (error.isNotEmpty) {
|
||||
buffer.write(', error: $error');
|
||||
}
|
||||
|
||||
if (source.isNotEmpty) {
|
||||
buffer.write(', source: $source');
|
||||
}
|
||||
|
||||
buffer.write(')');
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
factory ErrorResponse.fromJson(Map<String, dynamic> json) => _$ErrorResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ErrorResponseToJson(this);
|
||||
}
|
||||
15
frontend/pshared/lib/api/responses/file_uploaded.dart
Normal file
15
frontend/pshared/lib/api/responses/file_uploaded.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'file_uploaded.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class FileUploaded {
|
||||
|
||||
final String url;
|
||||
|
||||
const FileUploaded({ required this.url });
|
||||
|
||||
factory FileUploaded.fromJson(Map<String, dynamic> json) => _$FileUploadedFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$FileUploadedToJson(this);
|
||||
}
|
||||
19
frontend/pshared/lib/api/responses/login.dart
Normal file
19
frontend/pshared/lib/api/responses/login.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/account.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/account/account.dart';
|
||||
|
||||
part 'login.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class LoginResponse extends AccountResponse {
|
||||
final TokenData refreshToken;
|
||||
|
||||
const LoginResponse({required super.accessToken, required super.account, required this.refreshToken});
|
||||
|
||||
factory LoginResponse.fromJson(Map<String, dynamic> json) => _$LoginResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$LoginResponseToJson(this);
|
||||
}
|
||||
19
frontend/pshared/lib/api/responses/message.dart
Normal file
19
frontend/pshared/lib/api/responses/message.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/type.dart';
|
||||
|
||||
part 'message.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class HTTPMessage {
|
||||
|
||||
@JsonKey(fromJson: MessageTypeExtension.fromJson, toJson: MessageTypeExtension.toJson)
|
||||
final MessageType status;
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
const HTTPMessage({ required this.data, required this.status });
|
||||
|
||||
factory HTTPMessage.fromJson(Map<String, dynamic> json) => _$HTTPMessageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$HTTPMessageToJson(this);
|
||||
}
|
||||
19
frontend/pshared/lib/api/responses/organization.dart
Normal file
19
frontend/pshared/lib/api/responses/organization.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/base.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/organization.dart';
|
||||
|
||||
part 'organization.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class OrganizationResponse extends BaseAuthorizedResponse {
|
||||
final List<OrganizationDTO> organizations;
|
||||
|
||||
const OrganizationResponse({required super.accessToken, required this.organizations});
|
||||
|
||||
factory OrganizationResponse.fromJson(Map<String, dynamic> json) => _$OrganizationResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$OrganizationResponseToJson(this);
|
||||
}
|
||||
21
frontend/pshared/lib/api/responses/policies.dart
Normal file
21
frontend/pshared/lib/api/responses/policies.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/base.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/permissions/data/permissions.dart';
|
||||
import 'package:pshared/data/dto/permissions/description/description.dart';
|
||||
|
||||
part 'policies.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class PoliciesResponse extends BaseAuthorizedResponse {
|
||||
final PermissionsDescriptionDTO descriptions;
|
||||
final PermissionsDataDTO permissions;
|
||||
|
||||
const PoliciesResponse({required this.descriptions, required this.permissions, required super.accessToken});
|
||||
|
||||
factory PoliciesResponse.fromJson(Map<String, dynamic> json) => _$PoliciesResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$PoliciesResponseToJson(this);
|
||||
}
|
||||
15
frontend/pshared/lib/api/responses/token.dart
Normal file
15
frontend/pshared/lib/api/responses/token.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'token.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class TokenData {
|
||||
final String token;
|
||||
final DateTime expiration;
|
||||
|
||||
const TokenData({required this.token, required this.expiration});
|
||||
|
||||
factory TokenData.fromJson(Map<String, dynamic> json) => _$TokenDataFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TokenDataToJson(this);
|
||||
}
|
||||
32
frontend/pshared/lib/api/responses/type.dart
Normal file
32
frontend/pshared/lib/api/responses/type.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
enum MessageType {
|
||||
success,
|
||||
error,
|
||||
request
|
||||
}
|
||||
|
||||
extension MessageTypeExtension on MessageType {
|
||||
static String toJson(MessageType value) {
|
||||
switch (value) {
|
||||
case MessageType.success:
|
||||
return 'success';
|
||||
case MessageType.error:
|
||||
return 'error';
|
||||
case MessageType.request:
|
||||
return 'request';
|
||||
}
|
||||
}
|
||||
|
||||
static MessageType fromJson(String json) {
|
||||
switch (json) {
|
||||
case 'success':
|
||||
return MessageType.success;
|
||||
case 'error':
|
||||
return MessageType.error;
|
||||
case 'request':
|
||||
return MessageType.request;
|
||||
default:
|
||||
throw ArgumentError('Unknown HTTPMType string: $json');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user