Frontend first draft
This commit is contained in:
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