mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
added project model
This commit is contained in:
27
lib/features/auth/model/project_model.dart
Normal file
27
lib/features/auth/model/project_model.dart
Normal file
@ -0,0 +1,27 @@
|
||||
class Project {
|
||||
final String uuid;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
const Project({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
factory Project.fromJson(Map<String, dynamic> json) {
|
||||
return Project(
|
||||
uuid: json['uuid'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'name': name,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
|
||||
class UserModel {
|
||||
@ -20,6 +21,7 @@ class UserModel {
|
||||
final bool? hasAcceptedAppAgreement;
|
||||
final DateTime? appAgreementAcceptedAt;
|
||||
final Role? role;
|
||||
final Project? project;
|
||||
|
||||
UserModel({
|
||||
required this.uuid,
|
||||
@ -38,6 +40,7 @@ class UserModel {
|
||||
required this.hasAcceptedAppAgreement,
|
||||
required this.appAgreementAcceptedAt,
|
||||
required this.role,
|
||||
required this.project,
|
||||
});
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
@ -62,33 +65,35 @@ class UserModel {
|
||||
? DateTime.parse(json['appAgreementAcceptedAt'])
|
||||
: null,
|
||||
role: json['role'] != null ? Role.fromJson(json['role']) : null,
|
||||
project:
|
||||
json['project'] != null ? Project.fromJson(json['project']) : null,
|
||||
);
|
||||
}
|
||||
|
||||
factory UserModel.fromToken(Token token) {
|
||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||
return UserModel(
|
||||
uuid: tempJson['uuid'].toString(),
|
||||
email: tempJson['email'],
|
||||
lastName: tempJson['lastName'],
|
||||
firstName: tempJson['firstName'],
|
||||
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
||||
phoneNumber: null,
|
||||
isEmailVerified: null,
|
||||
isAgreementAccepted: null,
|
||||
regionUuid: null,
|
||||
regionName: tempJson['region']?['regionName'],
|
||||
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
||||
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
||||
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
||||
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
||||
: null,
|
||||
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
||||
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
||||
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
||||
: null,
|
||||
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
||||
);
|
||||
uuid: tempJson['uuid'].toString(),
|
||||
email: tempJson['email'],
|
||||
lastName: tempJson['lastName'],
|
||||
firstName: tempJson['firstName'],
|
||||
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
||||
phoneNumber: null,
|
||||
isEmailVerified: null,
|
||||
isAgreementAccepted: null,
|
||||
regionUuid: null,
|
||||
regionName: tempJson['region']?['regionName'],
|
||||
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
||||
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
||||
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
||||
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
||||
: null,
|
||||
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
||||
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
||||
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
||||
: null,
|
||||
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
||||
project: null);
|
||||
}
|
||||
|
||||
static Uint8List? decodeBase64Image(String? base64String) {
|
||||
@ -137,8 +142,10 @@ class Role {
|
||||
factory Role.fromJson(Map<String, dynamic> json) {
|
||||
return Role(
|
||||
uuid: json['uuid'],
|
||||
createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
||||
updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
||||
createdAt:
|
||||
json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
||||
updatedAt:
|
||||
json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
||||
type: json['type'],
|
||||
);
|
||||
}
|
||||
|
19
lib/features/common/bloc/project_cubit.dart
Normal file
19
lib/features/common/bloc/project_cubit.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class ProjectCubit extends Cubit<String?> {
|
||||
final FlutterSecureStorage storage;
|
||||
static const String projectKey = "selected_project_uuid";
|
||||
|
||||
ProjectCubit(this.storage) : super(null);
|
||||
|
||||
Future<void> setProjectUUID(String newUUID) async {
|
||||
await storage.write(key: projectKey, value: newUUID);
|
||||
emit(newUUID);
|
||||
}
|
||||
|
||||
Future<void> clearProjectUUID() async {
|
||||
await storage.delete(key: projectKey);
|
||||
emit(null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user