Skip to content

Commit

Permalink
Merge pull request #324 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Resolved the conflicts
  • Loading branch information
YujithIsura authored Jan 19, 2024
2 parents a6e857e + b91bc78 commit e62773b
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 18 deletions.
13 changes: 13 additions & 0 deletions campus/bffs/attendance/api/attendance_client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,17 @@ log:printInfo("Formatted Response: " + formattedJson);
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetDailyStudentsAttendanceByParentOrgResponse> check performDataBinding(graphqlResponse, GetDailyStudentsAttendanceByParentOrgResponse);
}

remote isolated function getTotalAttendanceCountByDateByOrg(string from_date, string to_date, int organization_id) returns GetTotalAttendanceCountByDateByOrgResponse|graphql:ClientError {
string query = string `query getTotalAttendanceCountByDateByOrg($organization_id:Int!,$from_date:String!,$to_date:String!) {total_attendance_count_by_date(organization_id:$organization_id,from_date:$from_date,to_date:$to_date) {attendance_date daily_total}}`;
map<anydata> variables = {"from_date": from_date, "to_date": to_date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetTotalAttendanceCountByDateByOrgResponse> check performDataBinding(graphqlResponse, GetTotalAttendanceCountByDateByOrgResponse);
}
remote isolated function getTotalAttendanceCountByParentOrg(string from_date, string to_date, int parent_organization_id) returns GetTotalAttendanceCountByParentOrgResponse|graphql:ClientError {
string query = string `query getTotalAttendanceCountByParentOrg($parent_organization_id:Int!,$from_date:String!,$to_date:String!) {total_attendance_count_by_date(parent_organization_id:$parent_organization_id,from_date:$from_date,to_date:$to_date) {attendance_date daily_total}}`;
map<anydata> variables = {"from_date": from_date, "to_date": to_date, "parent_organization_id": parent_organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetTotalAttendanceCountByParentOrgResponse> check performDataBinding(graphqlResponse, GetTotalAttendanceCountByParentOrgResponse);
}
}
48 changes: 48 additions & 0 deletions campus/bffs/attendance/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,52 @@ service / on new http:Listener(9091) {
}
}

resource function get total_attendance_count_by_date_by_org/[int organization_id]/[string from_date]/[string to_date]() returns TotalAttendanceCountByDate[]|error {
GetTotalAttendanceCountByDateByOrgResponse|graphql:ClientError getTotalAttendanceCountResponse = globalDataClient->getTotalAttendanceCountByDateByOrg(from_date, to_date, organization_id);
if(getTotalAttendanceCountResponse is GetTotalAttendanceCountByDateByOrgResponse) {
TotalAttendanceCountByDate[] totalAttendances = [];
foreach var total_attendance_record in getTotalAttendanceCountResponse.total_attendance_count_by_date {
TotalAttendanceCountByDate|error totalAttendanceRecord = total_attendance_record.cloneWithType(TotalAttendanceCountByDate);
if(totalAttendanceRecord is TotalAttendanceCountByDate) {
totalAttendances.push(totalAttendanceRecord);
} else {
log:printError("Error while processing Application record received", totalAttendanceRecord);
return error("Error while processing Application record received: " + totalAttendanceRecord.message() +
":: Detail: " + totalAttendanceRecord.detail().toString());
}
}

return totalAttendances;

} else {
log:printError("Error while creating application", getTotalAttendanceCountResponse);
return error("Error while creating application: " + getTotalAttendanceCountResponse.message() +
":: Detail: " + getTotalAttendanceCountResponse.detail().toString());
}
}

resource function get total_attendance_count_by_date_by_parent_org/[int parent_organization_id]/[string from_date]/[string to_date]() returns TotalAttendanceCountByDate[]|error {
GetTotalAttendanceCountByParentOrgResponse|graphql:ClientError getTotalAttendanceCountResponse = globalDataClient->getTotalAttendanceCountByParentOrg(from_date,to_date,parent_organization_id);
if(getTotalAttendanceCountResponse is GetTotalAttendanceCountByParentOrgResponse) {
TotalAttendanceCountByDate[] totalAttendances = [];
foreach var total_attendance_record in getTotalAttendanceCountResponse.total_attendance_count_by_date {
TotalAttendanceCountByDate|error totalAttendanceRecord = total_attendance_record.cloneWithType(TotalAttendanceCountByDate);
if(totalAttendanceRecord is TotalAttendanceCountByDate) {
totalAttendances.push(totalAttendanceRecord);
} else {
log:printError("Error while processing Application record received", totalAttendanceRecord);
return error("Error while processing Application record received: " + totalAttendanceRecord.message() +
":: Detail: " + totalAttendanceRecord.detail().toString());
}
}

return totalAttendances;

} else {
log:printError("Error while creating application", getTotalAttendanceCountResponse);
return error("Error while creating application: " + getTotalAttendanceCountResponse.message() +
":: Detail: " + getTotalAttendanceCountResponse.detail().toString());
}
}

}
22 changes: 22 additions & 0 deletions campus/bffs/attendance/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ public type DailyActivityParticipantAttendanceByParentOrg record {
int? total_student_count;
};

public type TotalAttendanceCountByDate record {
string? attendance_date;
int? daily_total;
string? record_type?;
};

public type GetAvinyaTypesResponse record {|
map<json?> __extensions?;
record {|
Expand Down Expand Up @@ -745,3 +751,19 @@ public type GetDailyStudentsAttendanceByParentOrgResponse record {|
string? color;
|}[] daily_students_attendance_by_parent_org;
|};

public type GetTotalAttendanceCountByDateByOrgResponse record {|
map<json?> __extensions?;
record {|
string? attendance_date;
int? daily_total;
|}[] total_attendance_count_by_date;
|};

public type GetTotalAttendanceCountByParentOrgResponse record {|
map<json?> __extensions?;
record {|
string? attendance_date;
int? daily_total;
|}[] total_attendance_count_by_date;
|};
14 changes: 14 additions & 0 deletions campus/bffs/attendance/graphql_client/activity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,17 @@ query getDailyStudentsAttendanceByParentOrg($parent_organization_id: Int!) {
color
}
}

query getTotalAttendanceCountByDateByOrg($organization_id: Int!, $from_date: String!, $to_date: String!) {
total_attendance_count_by_date(organization_id:$organization_id, from_date: $from_date, to_date: $to_date) {
attendance_date
daily_total
}
}

query getTotalAttendanceCountByParentOrg($parent_organization_id: Int!, $from_date: String!, $to_date: String!) {
total_attendance_count_by_date(parent_organization_id: $parent_organization_id, from_date: $from_date, to_date: $to_date) {
attendance_date
daily_total
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,16 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetDailyStudentsAttendanceByParentOrgResponse> check performDataBinding(graphqlResponse, GetDailyStudentsAttendanceByParentOrgResponse);
}
remote isolated function getTotalAttendanceCountByDateByOrg(string from_date, string to_date, int organization_id) returns GetTotalAttendanceCountByDateByOrgResponse|graphql:ClientError {
string query = string `query getTotalAttendanceCountByDateByOrg($organization_id:Int!,$from_date:String!,$to_date:String!) {total_attendance_count_by_date(organization_id:$organization_id,from_date:$from_date,to_date:$to_date) {attendance_date daily_total}}`;
map<anydata> variables = {"from_date": from_date, "to_date": to_date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetTotalAttendanceCountByDateByOrgResponse> check performDataBinding(graphqlResponse, GetTotalAttendanceCountByDateByOrgResponse);
}
remote isolated function getTotalAttendanceCountByParentOrg(string from_date, string to_date, int parent_organization_id) returns GetTotalAttendanceCountByParentOrgResponse|graphql:ClientError {
string query = string `query getTotalAttendanceCountByParentOrg($parent_organization_id:Int!,$from_date:String!,$to_date:String!) {total_attendance_count_by_date(parent_organization_id:$parent_organization_id,from_date:$from_date,to_date:$to_date) {attendance_date daily_total}}`;
map<anydata> variables = {"from_date": from_date, "to_date": to_date, "parent_organization_id": parent_organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetTotalAttendanceCountByParentOrgResponse> check performDataBinding(graphqlResponse, GetTotalAttendanceCountByParentOrgResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,19 @@ public type GetDailyStudentsAttendanceByParentOrgResponse record {|
string? color;
|}[]? daily_students_attendance_by_parent_org;
|};

public type GetTotalAttendanceCountByDateByOrgResponse record {|
map<json?> __extensions?;
record {|
string? attendance_date;
int? daily_total;
|}[]? total_attendance_count_by_date;
|};

public type GetTotalAttendanceCountByParentOrgResponse record {|
map<json?> __extensions?;
record {|
string? attendance_date;
int? daily_total;
|}[]? total_attendance_count_by_date;
|};
6 changes: 6 additions & 0 deletions campus/bffs/attendance/graphql_client/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ type Query {
attendance_dashboard_data_by_date(organization_id: Int, parent_organization_id: Int, activity_id: Int, from_date: String = "", to_date: String = ""): [AttendanceDashboardDataMain!]
attendance_missed_by_security(organization_id: Int, parent_organization_id: Int, from_date: String = "", to_date: String = ""): [ActivityParticipantAttendanceMissedBySecurityData!]
daily_students_attendance_by_parent_org(parent_organization_id: Int): [DailyActivityParticipantAttendanceByParentOrgData!]
total_attendance_count_by_date(organization_id: Int, parent_organization_id: Int, from_date: String = "", to_date: String = ""): [TotalActivityParticipantAttendanceCountByDateData!]
}

input ResourceAllocation {
Expand Down Expand Up @@ -962,6 +963,11 @@ type SupplyData {
updated: String
}

type TotalActivityParticipantAttendanceCountByDateData {
attendance_date: String
daily_total: Int
}

input Vacancy {
record_type: String = ""
id: Int
Expand Down
88 changes: 88 additions & 0 deletions campus/bffs/attendance/graphql_client/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,62 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "total_attendance_count_by_date",
"args": [
{
"name": "organization_id",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "parent_organization_id",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "from_date",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": "\"\""
},
{
"name": "to_date",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": "\"\""
}
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "TotalActivityParticipantAttendanceCountByDateData",
"ofType": null
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -3515,6 +3571,38 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "TotalActivityParticipantAttendanceCountByDateData",
"fields": [
{
"name": "attendance_date",
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "daily_total",
"args": [],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "AttendanceDashboardData",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,32 @@ class ActivityAttendance {
String? svg_src;
Color? color;
int? total_student_count;
int? daily_total;
String? attendance_date;

ActivityAttendance(
{this.id,
this.activity_instance_id,
this.person_id,
this.created,
this.updated,
this.sign_in_time,
this.sign_out_time,
this.in_marked_by,
this.out_marked_by,
this.person,
this.description,
this.preferred_name,
this.digital_id,
this.present_count,
this.svg_src,
this.color,
this.total_student_count});


ActivityAttendance({
this.id,
this.activity_instance_id,
this.person_id,
this.created,
this.updated,
this.sign_in_time,
this.sign_out_time,
this.in_marked_by,
this.out_marked_by,
this.person,
this.description,
this.preferred_name,
this.digital_id,
this.present_count,
this.svg_src,
this.color,
this.total_student_count,
this.daily_total,
this.attendance_date
});

factory ActivityAttendance.fromJson(Map<String, dynamic> json) {
return ActivityAttendance(
Expand All @@ -64,6 +71,8 @@ class ActivityAttendance {
svg_src: json['svg_src'],
color: _parseColor(json['color']),
total_student_count: json['total_student_count'],
daily_total: json['daily_total'],
attendance_date: json['attendance_date']
);
}

Expand Down Expand Up @@ -465,3 +474,53 @@ Future<List<ActivityAttendance>> getDailyStudentsAttendanceByParentOrg(
'Failed to get Activity Participant Attendances by parent org');
}
}

Future<List<ActivityAttendance>> getTotalAttendanceCountByDateByOrg(
int organization_id,
String from_date,
String to_date) async {
final response = await http.get(
Uri.parse(
'${AppConfig.campusAttendanceBffApiUrl}/total_attendance_count_by_date_by_org/$organization_id/$from_date/$to_date'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'accept': 'application/json',
'Authorization': 'Bearer ${AppConfig.campusBffApiKey}',
},
);
if (response.statusCode > 199 && response.statusCode < 300) {
var resultsJson = json.decode(response.body).cast<Map<String, dynamic>>();
List<ActivityAttendance> activityAttendances = await resultsJson
.map<ActivityAttendance>((json) => ActivityAttendance.fromJson(json))
.toList();
return activityAttendances;
} else {
throw Exception(
'Failed to get Total Activity Participant Attendances Count');
}
}

Future<List<ActivityAttendance>> getTotalAttendanceCountByParentOrg(
int parent_organization_id,
String from_date,
String to_date) async {
final response = await http.get(
Uri.parse(
'${AppConfig.campusAttendanceBffApiUrl}/total_attendance_count_by_date_by_parent_org/$parent_organization_id/$from_date/$to_date'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'accept': 'application/json',
'Authorization': 'Bearer ${AppConfig.campusBffApiKey}',
},
);
if (response.statusCode > 199 && response.statusCode < 300) {
var resultsJson = json.decode(response.body).cast<Map<String, dynamic>>();
List<ActivityAttendance> activityAttendances = await resultsJson
.map<ActivityAttendance>((json) => ActivityAttendance.fromJson(json))
.toList();
return activityAttendances;
} else {
throw Exception(
'Failed to get Total Activity Participant Attendances Count');
}
}

0 comments on commit e62773b

Please sign in to comment.