feat: legacy mobile apps created
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/core/application/clients/api/api_client.dart';
|
||||
import 'package:krow/core/data/models/pagination_wrapper/pagination_wrapper.dart';
|
||||
import 'package:krow/features/profile/certificates/data/models/certificate_model.dart';
|
||||
import 'package:krow/features/profile/certificates/data/models/staff_certificate.dart';
|
||||
|
||||
import 'certificates_gql.dart';
|
||||
|
||||
@injectable
|
||||
class CertificatesApiProvider {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
CertificatesApiProvider(this._apiClient);
|
||||
|
||||
Future<List<CertificateModel>> fetchCertificates() async {
|
||||
var result = await _apiClient.query(schema: getCertificatesQuery);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
|
||||
return result.data!['certificates'].map<CertificateModel>((e) {
|
||||
return CertificateModel.fromJson(e);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
Future<PaginationWrapper<StaffCertificate>> fetchStaffCertificates() async {
|
||||
var result = await _apiClient.query(schema: getStaffCertificatesQuery);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
|
||||
return PaginationWrapper.fromJson(result.data!['staff_certificates'],
|
||||
(json) => StaffCertificate.fromJson(json));
|
||||
}
|
||||
|
||||
Future<StaffCertificate> putStaffCertificate(
|
||||
String certificateId, String imagePath, String certificateDate) async {
|
||||
var byteData = File(imagePath).readAsBytesSync();
|
||||
|
||||
var multipartFile = MultipartFile.fromBytes(
|
||||
'file',
|
||||
byteData,
|
||||
filename: '${DateTime.now().millisecondsSinceEpoch}.jpg',
|
||||
contentType: MediaType('image', 'jpg'),
|
||||
);
|
||||
|
||||
final Map<String, dynamic> variables = {
|
||||
'certificate_id': certificateId,
|
||||
'expiration_date': certificateDate,
|
||||
'file': multipartFile,
|
||||
};
|
||||
var result = await _apiClient.mutate(
|
||||
schema: putStaffCertificateMutation, body: {'input': variables});
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
} else {
|
||||
return StaffCertificate.fromJson(
|
||||
result.data!['upload_staff_certificate']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteStaffCertificate(String certificateId) async {
|
||||
final Map<String, dynamic> variables = {
|
||||
'id': certificateId,
|
||||
};
|
||||
var result = await _apiClient.mutate(
|
||||
schema: deleteStaffCertificateMutation, body: variables);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
const String getCertificatesQuery = '''
|
||||
{
|
||||
certificates {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String getStaffCertificatesQuery = '''
|
||||
query fetchStaffCertificates () {
|
||||
staff_certificates(first: 10) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
startCursor
|
||||
endCursor
|
||||
}
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
id
|
||||
expiration_date
|
||||
status
|
||||
file
|
||||
certificate {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String putStaffCertificateMutation = '''
|
||||
mutation UploadStaffCertificate(\$input: UploadStaffCertificateInput!) {
|
||||
upload_staff_certificate(input: \$input) {
|
||||
id
|
||||
expiration_date
|
||||
status
|
||||
file
|
||||
certificate {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String deleteStaffCertificateMutation = '''
|
||||
mutation DeleteStaffCertificate(\$id: ID!) {
|
||||
delete_staff_certificate(id: \$id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
''';
|
||||
@@ -0,0 +1,24 @@
|
||||
class CertificateModel {
|
||||
final String id;
|
||||
final String name;
|
||||
|
||||
|
||||
CertificateModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
factory CertificateModel.fromJson(Map<String, dynamic> json) {
|
||||
return CertificateModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/features/profile/certificates/data/certificates_api_provider.dart';
|
||||
import 'package:krow/features/profile/certificates/domain/certificates_repository.dart';
|
||||
import 'package:krow/features/profile/certificates/data/models/certificate_model.dart';
|
||||
import 'package:krow/features/profile/certificates/data/models/staff_certificate.dart';
|
||||
|
||||
@Injectable(as: CertificatesRepository)
|
||||
class CertificatesRepositoryImpl extends CertificatesRepository {
|
||||
final CertificatesApiProvider _certificatesApiProvider;
|
||||
|
||||
CertificatesRepositoryImpl(this._certificatesApiProvider);
|
||||
|
||||
@override
|
||||
Future<List<CertificateModel>> getCertificates() async {
|
||||
return _certificatesApiProvider.fetchCertificates();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StaffCertificate> putStaffCertificate(
|
||||
String certificateId, String imagePath, String certificateDate) {
|
||||
return _certificatesApiProvider.putStaffCertificate(
|
||||
certificateId, imagePath, certificateDate);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<StaffCertificate>> getStaffCertificates() async{
|
||||
return (await _certificatesApiProvider.fetchStaffCertificates()).edges.map((e) => e.node).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStaffCertificate(String certificateId) {
|
||||
return _certificatesApiProvider.deleteStaffCertificate(certificateId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:krow/features/profile/certificates/data/models/certificate_model.dart';
|
||||
|
||||
part 'staff_certificate.g.dart';
|
||||
|
||||
enum CertificateStatus {
|
||||
verified,
|
||||
pending,
|
||||
declined,
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class StaffCertificate {
|
||||
final String id;
|
||||
CertificateModel certificate;
|
||||
final String expirationDate;
|
||||
final CertificateStatus status;
|
||||
final String file;
|
||||
|
||||
StaffCertificate(
|
||||
{required this.id,
|
||||
required this.certificate,
|
||||
required this.expirationDate,
|
||||
required this.status,
|
||||
required this.file});
|
||||
|
||||
factory StaffCertificate.fromJson(Map<String, dynamic> json) {
|
||||
return _$StaffCertificateFromJson(json);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => _$StaffCertificateToJson(this);
|
||||
}
|
||||
Reference in New Issue
Block a user