Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organisation model update #2739

Open
wants to merge 4 commits into
base: develop-postgres
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 86 additions & 47 deletions lib/models/organization/org_info.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:hive/hive.dart';
import 'package:talawa/models/organization/org_info_address.dart';
import 'package:talawa/models/user/user_info.dart';

part 'org_info.g.dart';

/// This class creates an organization-information model and returns an OrgInfo instance.
@HiveType(typeId: 2)

///This class creates an organization-information model and returns an OrgInfo instance.
class OrgInfo {
/// Constructs an OrgInfo object.
OrgInfo({
this.admins,
this.members,
Expand All @@ -17,22 +16,52 @@
this.image,
this.userRegistrationRequired,
this.name,
this.address,
this.city,
this.countryCode,
this.line1,
this.line2,
this.postalCode,
this.state,
});

factory OrgInfo.fromJson(
Map<String, dynamic> json1, {
bool memberRequest = false,
}) {
Map<String, dynamic> json;
if (memberRequest) {
json = json1['organization'] as Map<String, dynamic>;
} else {
json = json1;
}
/// Factory method to construct an OrgInfo from a JSON object.
///
/// **params**:
/// * `json1`: The JSON object containing the organization data.
/// * `memberRequest`: A boolean flag to indicate if the request is from a member.
///
/// **returns**:
/// * `OrgInfo`: Returns an instance of OrgInfo containing the parsed data.
factory OrgInfo.fromJson(Map<String, dynamic> json) {
final membersJson = json['members'] as Map<String, dynamic>?;
final List<dynamic> edgesDynamic =
membersJson?['edges'] as List<dynamic>? ?? [];

final List<Map<String, dynamic>> memberEdges =
edgesDynamic.map((e) => e as Map<String, dynamic>).toList();

final List<User> members = memberEdges
.map(
(e) =>
User.fromJson(e['node'] as Map<String, dynamic>, fromOrg: true),

Check warning on line 46 in lib/models/organization/org_info.dart

View check run for this annotation

Codecov / codecov/patch

lib/models/organization/org_info.dart#L45-L46

Added lines #L45 - L46 were not covered by tests
)
.toList();

final List<User> admins = memberEdges
.map((e) {
final Map<String, dynamic> user = e['node'] as Map<String, dynamic>;
if (user['role'] == 'administrator') {
return User.fromJson(user, fromOrg: true);

Check warning on line 54 in lib/models/organization/org_info.dart

View check run for this annotation

Codecov / codecov/patch

lib/models/organization/org_info.dart#L52-L54

Added lines #L52 - L54 were not covered by tests
}
return null;
})
.where((user) => user != null)
.cast<User>()
.toList();

return OrgInfo(
id: json['_id'] != null ? json['_id'] as String : null,
image: json['image'] != null ? json['image'] as String? : null,
id: json['id'] != null ? json['id'] as String : null,
image: json['avatarURL'] != null ? json['avatarURL'] as String? : null,
name: json['name'] != null ? json['name'] as String? : null,
description:
json['description'] != null ? json['description'] as String? : null,
Expand All @@ -45,34 +74,24 @@
fromOrg: true,
)
: null,
members: json['members'] != null
? (json['members'] as List<dynamic>?)
?.map(
(e) => User.fromJson(e as Map<String, dynamic>, fromOrg: true),
)
.toList()
: null,
admins: json['admins'] != null
? (json['admins'] as List<dynamic>?)
?.map(
(e) => User.fromJson(e as Map<String, dynamic>, fromOrg: true),
)
.toList()
: null,
address: json['address'] != null
? Address.fromJson(json['address'] as Map<String, dynamic>)
: null,
members: members,
admins: admins,
city: json['city'] as String?,
countryCode: json['countryCode'] as String?,
line1: json['addressLine1'] as String?,
line2: json['addressLine2'] as String?,
postalCode: json['postalCode'] as String?,
state: json['state'] as String?,
);
}

/// The conventional function to parse json, check flutter docs to know more.
///
/// Converts a JSON array to a list of OrgInfo instances.
///
/// **params**:
/// * `json`: Passing the json to be parsed.
/// * `json`: The JSON array to be parsed.
///
/// **returns**:
/// * `List<OrgInfo>`: returning the OrgInfo object containing the json data
/// * `List<OrgInfo>`: A list of OrgInfo objects containing the parsed data.
List<OrgInfo> fromJsonToList(dynamic json) {
final List<OrgInfo> orgList = [];

Expand All @@ -95,39 +114,59 @@
return orgList;
}

/// contains the Image url.
/// The URL of the organization's image.
@HiveField(0)
String? image;

/// The org id.
/// The ID of the organization.
@HiveField(1)
String? id;

/// The org name.
/// The name of the organization.
@HiveField(2)
String? name;

/// The org admins.
/// The administrators of the organization.
@HiveField(3)
List<User>? admins;

/// The org name.
/// The members of the organization.
@HiveField(4)
List<User>? members;

/// The org descriptions.
/// The description of the organization.
@HiveField(5)
String? description;

/// The org registration is required.
/// Indicates if user registration is required for the organization.
@HiveField(6)
bool? userRegistrationRequired;

/// The org creatorInfo.
/// Information about the creator of the organization.
@HiveField(7)
User? creatorInfo;

/// Address of the Organisation.
/// The city of the organization's address.
@HiveField(8)
Address? address;
String? city;

/// The country code of the organization's address.
@HiveField(9)
String? countryCode;

/// The first line of the organization's address.
@HiveField(10)
String? line1;

/// The second line of the organization's address.
@HiveField(11)
String? line2;

/// The postal code of the organization's address.
@HiveField(12)
String? postalCode;

/// The state of the organization's address.
@HiveField(13)
String? state;
}
21 changes: 18 additions & 3 deletions lib/models/organization/org_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 0 additions & 52 deletions lib/models/organization/org_info_address.dart

This file was deleted.

12 changes: 8 additions & 4 deletions lib/models/user/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
final String? lastName = nameParts != null && nameParts.length > 1
? nameParts.sublist(1).join(' ')
: null;

final Map<String, dynamic>? org =
userData['organizationsWhereMember'] as Map<String, dynamic>?;
final List<dynamic>? edges = org?['edges'] as List<dynamic>?;

Check warning on line 39 in lib/models/user/user_info.dart

View check run for this annotation

Codecov / codecov/patch

lib/models/user/user_info.dart#L39

Added line #L39 was not covered by tests
final List<Map<String, dynamic>>? orgList =
edges?.map((e) => e as Map<String, dynamic>).toList();

Check warning on line 41 in lib/models/user/user_info.dart

View check run for this annotation

Codecov / codecov/patch

lib/models/user/user_info.dart#L41

Added line #L41 was not covered by tests
return User(
authToken: json['authenticationToken'] != null
? json['authenticationToken'] as String?
Expand All @@ -49,9 +53,9 @@
image: userData['avatarURL'] != null
? userData['avatarURL'] as String?
: null,
joinedOrganizations: userData['joinedOrganizations'] != null
? (userData['joinedOrganizations'] as List<dynamic>)
.map((e) => OrgInfo.fromJson(e as Map<String, dynamic>))
joinedOrganizations: orgList != null
? orgList
.map((e) => OrgInfo.fromJson(e["node"] as Map<String, dynamic>))

Check warning on line 58 in lib/models/user/user_info.dart

View check run for this annotation

Codecov / codecov/patch

lib/models/user/user_info.dart#L58

Added line #L58 was not covered by tests
.toList()
: [],
);
Expand Down
47 changes: 46 additions & 1 deletion lib/utils/queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,29 @@ class Queries {
name,
avatarURL,
emailAddress,

organizationsWhereMember(first:32){
edges{
node{
id,
name,
addressLine1,
addressLine2,
avatarMimeType,
avatarURL,
postalCode,
countryCode,
description,
members(first:32){
edges{
node{
name
role
}
}
}
}
}
}
}

}
Expand Down Expand Up @@ -63,6 +85,29 @@ class Queries {
emailAddress,
name,
avatarURL,
organizationsWhereMember(first:32){
edges{
node{
id,
name,
addressLine1,
addressLine2,
avatarMimeType,
avatarURL,
postalCode,
countryCode,
description,
members(first:32){
edges{
node{
name
role
}
}
}
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/views/after_auth_screens/org_info_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@
color: Colors.white,
),
),
if (orgInfo.address != null)
if (orgInfo.city != null && orgInfo.countryCode != null)

Check warning on line 124 in lib/views/after_auth_screens/org_info_screen.dart

View check run for this annotation

Codecov / codecov/patch

lib/views/after_auth_screens/org_info_screen.dart#L124

Added line #L124 was not covered by tests
Padding(
padding: const EdgeInsets.only(top: 8, left: 8),
child: Center(
child: Text(
'${orgInfo.address?.city}, ${orgInfo.address?.countryCode}',
'${orgInfo.city}, ${orgInfo.countryCode}',

Check warning on line 129 in lib/views/after_auth_screens/org_info_screen.dart

View check run for this annotation

Codecov / codecov/patch

lib/views/after_auth_screens/org_info_screen.dart#L129

Added line #L129 was not covered by tests
style: const TextStyle(
fontSize: 16.0,
color: Color.fromARGB(255, 179, 168, 168),
Expand Down
Loading
Loading