Skip to content

Commit

Permalink
Feat: Fundraising Campaigns (GSoC) (#2635)
Browse files Browse the repository at this point in the history
* Fundraising Campaigns

* adding tests

* adding tests

* adding tests

* adding tests

* adding tests

* adding tests

* adding tests
  • Loading branch information
Dante291 authored Nov 20, 2024
1 parent 48c349b commit 6e33d49
Show file tree
Hide file tree
Showing 40 changed files with 6,140 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Count lines of code in each file
run: chmod +x ./.github/workflows/countline.py
- name: Running count lines
run: ./.github/workflows/countline.py --exclude_directories test/ --exclude_files lib/custom_painters/talawa_logo.dart lib/custom_painters/language_icon.dart lib/custom_painters/whatsapp_logo.dart lib/utils/queries.dart lib/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart lib/view_model/pre_auth_view_models/select_organization_view_model.dart lib/views/after_auth_screens/profile/profile_page.dart lib/view_model/main_screen_view_model.dart lib/views/after_auth_screens/events/create_event_page.dart lib/views/after_auth_screens/org_info_screen.dart lib/views/after_auth_screens/events/manage_volunteer_group.dart lib/views/after_auth_screens/events/create_agenda_item_page.dart lib/views/after_auth_screens/events/edit_agenda_item_page.dart lib/utils/event_queries.dart
run: ./.github/workflows/countline.py --exclude_directories test/ --exclude_files lib/custom_painters/talawa_logo.dart lib/custom_painters/language_icon.dart lib/custom_painters/whatsapp_logo.dart lib/utils/queries.dart lib/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart lib/view_model/pre_auth_view_models/select_organization_view_model.dart lib/views/after_auth_screens/profile/profile_page.dart lib/view_model/main_screen_view_model.dart lib/views/after_auth_screens/events/create_event_page.dart lib/views/after_auth_screens/org_info_screen.dart lib/views/after_auth_screens/events/manage_volunteer_group.dart lib/views/after_auth_screens/events/create_agenda_item_page.dart lib/views/after_auth_screens/events/edit_agenda_item_page.dart lib/utils/event_queries.dart lib/views/after_auth_screens/funds/fundraising_campaigns_screen.dart lib/views/after_auth_screens/funds/fund_pledges_screen.dart lib/widgets/update_pledge_dialogue_box.dart
- name: setup python
uses: actions/setup-python@v5
- name: Check for presence of ignore directives corresponding to custom lints
Expand Down
7 changes: 7 additions & 0 deletions lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:talawa/services/chat_service.dart';
import 'package:talawa/services/comment_service.dart';
import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/services/event_service.dart';
import 'package:talawa/services/fund_service.dart';
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/image_service.dart';
import 'package:talawa/services/navigation_service.dart';
Expand All @@ -33,6 +34,7 @@ import 'package:talawa/view_model/after_auth_view_models/event_view_models/event
import 'package:talawa/view_model/after_auth_view_models/event_view_models/explore_events_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/event_view_models/manage_volunteer_group_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/feed_view_models/organization_feed_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/funds_view_models/fund_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/edit_profile_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart';
Expand Down Expand Up @@ -90,6 +92,9 @@ final imageService = locator<ImageService>();
///GetIt for SessionManager.
final sessionManager = locator<SessionManager>();

///GetIt for FundService.
final fundServcie = locator<FundService>();

///GetIt for ActonHandlerService.
final actionHandlerService = locator<ActionHandlerService>();

Expand Down Expand Up @@ -122,6 +127,7 @@ Future<void> setupLocator() async {

//Services
locator.registerLazySingleton(() => PostService());
locator.registerLazySingleton(() => FundService());
locator.registerLazySingleton(() => EventService());
locator.registerLazySingleton(() => CommentService());
locator.registerLazySingleton(() => OrganizationService());
Expand Down Expand Up @@ -151,6 +157,7 @@ Future<void> setupLocator() async {
locator.registerFactory(() => OrganizationFeedViewModel());
locator.registerFactory(() => SetUrlViewModel());
locator.registerFactory(() => LoginViewModel());
locator.registerFactory(() => FundViewModel());
locator.registerFactory(() => ManageVolunteerGroupViewModel());
locator.registerFactory(() => EditAgendaItemViewModel());
locator.registerFactory(() => SelectOrganizationViewModel());
Expand Down
91 changes: 91 additions & 0 deletions lib/models/funds/fund.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'package:talawa/models/funds/fund_campaign.dart';
import 'package:talawa/models/user/user_info.dart';

/// The `Fund` class represents a fund in the application.
class Fund {
/// Constructs a `Fund` instance.
///
/// [id] is the unique identifier of the fund.
/// [organizationId] is the identifier of the organization to which the fund belongs.
/// [name] is the name of the fund.
/// [taxDeductible] indicates whether the fund is tax-deductible.
/// [isDefault] indicates whether the fund is the default fund.
/// [isArchived] indicates whether the fund is archived.
/// [creatorId] is the identifier of the user who created the fund.
/// [campaigns] is a list of campaign identifiers associated with the fund.
/// [createdAt] is the timestamp of when the fund was created.
/// [updatedAt] is the timestamp of when the fund was last updated.
Fund({
this.id,
this.organizationId,
this.name,
this.taxDeductible,
this.isDefault,
this.isArchived,
this.creator,
this.campaigns,
this.createdAt,
this.updatedAt,
});

/// Creates a `Fund` instance from a JSON object.
///
/// The [json] parameter is a map containing the fund data.
///
/// Returns an instance of `Fund`.
factory Fund.fromJson(Map<String, dynamic> json) {
return Fund(
id: json['_id'] as String?,
organizationId: json['organizationId'] as String?,
name: json['name'] as String?,
taxDeductible: json['taxDeductible'] as bool?,
isDefault: json['isDefault'] as bool?,
isArchived: json['isArchived'] as bool?,
creator: json['creator'] == null
? null
: User.fromJson(
json['creator'] as Map<String, dynamic>,
fromOrg: true,
),
campaigns: (json['campaigns'] as List<dynamic>?)
?.map((e) => e as Campaign)
.toList(),
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: null,
updatedAt: json['updatedAt'] != null
? DateTime.parse(json['updatedAt'] as String)
: null,
);
}

/// The unique identifier of the fund.
final String? id;

/// The identifier of the organization to which the fund belongs.
final String? organizationId;

/// The name of the fund.
final String? name;

/// Indicates whether the fund is tax-deductible.
final bool? taxDeductible;

/// Indicates whether the fund is the default fund.
final bool? isDefault;

/// Indicates whether the fund is archived.
final bool? isArchived;

/// The identifier of the user who created the fund.
final User? creator;

/// A list of campaign identifiers associated with the fund.
final List<Campaign>? campaigns;

/// The timestamp of when the fund was created.
final DateTime? createdAt;

/// The timestamp of when the fund was last updated.
final DateTime? updatedAt;
}
90 changes: 90 additions & 0 deletions lib/models/funds/fund_campaign.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:talawa/models/funds/fund_pledges.dart';

/// The `Campaign` class represents a fundraising campaign in the application.
class Campaign {
/// Constructs a `FundraisingCampaign` instance.
///
/// [id] is the unique identifier of the campaign.
/// [fundId] is the identifier of the fund to which the campaign belongs.
/// [name] is the name of the campaign.
/// [startDate] is the start date of the campaign.
/// [endDate] is the end date of the campaign.
/// [fundingGoal] is the funding goal of the campaign.
/// [currency] is the currency used for the campaign.
/// [pledges] is a list of pledge identifiers associated with the campaign.
/// [createdAt] is the timestamp of when the campaign was created.
/// [updatedAt] is the timestamp of when the campaign was last updated.
Campaign({
this.id,
this.fundId,
this.name,
this.startDate,
this.endDate,
this.fundingGoal,
this.currency,
this.pledges,
this.createdAt,
this.updatedAt,
});

/// Creates a `Campaign` instance from a JSON object.
///
/// The [json] parameter is a map containing the campaign data.
///
/// Returns an instance of `Campaign`.
factory Campaign.fromJson(Map<String, dynamic> json) {
return Campaign(
id: json['_id'] as String?,
fundId: json['fundId'] as String?,
name: json['name'] as String?,
startDate: json['startDate'] != null
? DateTime.parse(json['startDate'] as String)
: null,
endDate: json['endDate'] != null
? DateTime.parse(json['endDate'] as String)
: null,
fundingGoal: (json['fundingGoal'] is int)
? (json['fundingGoal'] as int).toDouble()
: json['fundingGoal'] as double?,
currency: json['currency'] as String?,
pledges:
(json['pledges'] as List<dynamic>?)?.map((e) => e as Pledge).toList(),
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: null,
updatedAt: json['updatedAt'] != null
? DateTime.parse(json['updatedAt'] as String)
: null,
);
}

/// The unique identifier of the campaign.
final String? id;

/// The identifier of the fund to which the campaign belongs.
final String? fundId;

/// The name of the campaign.
final String? name;

/// The start date of the campaign.
final DateTime? startDate;

/// The end date of the campaign.
final DateTime? endDate;

/// The funding goal of the campaign.
final double? fundingGoal;

/// The currency used for the campaign.
final String? currency;

/// A list of pledge identifiers associated with the campaign.
final List<Pledge>? pledges;

/// The timestamp of when the campaign was created.
final DateTime? createdAt;

/// The timestamp of when the campaign was last updated.
final DateTime? updatedAt;
}
90 changes: 90 additions & 0 deletions lib/models/funds/fund_pledges.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:talawa/models/funds/fund_campaign.dart';
import 'package:talawa/models/user/user_info.dart';

/// The `Pledge` class represents a pledge for a fundraising campaign in the application.
class Pledge {
/// Constructs a `Pledge` instance.
///
/// [id] is the unique identifier of the pledge.
/// [campaigns] is a list of campaign identifiers associated with the pledge.
/// [users] is a list of user identifiers associated with the pledge.
/// [startDate] is the start date of the pledge.
/// [endDate] is the end date of the pledge.
/// [amount] is the amount pledged.
/// [currency] is the currency of the pledged amount.
/// [createdAt] is the timestamp of when the pledge was created.
/// [updatedAt] is the timestamp of when the pledge was last updated.
Pledge({
this.id,
this.campaigns,
this.pledgers,
this.startDate,
this.endDate,
this.amount,
this.currency,
this.createdAt,
this.updatedAt,
});

/// Creates a `Pledge` instance from a JSON object.
///
/// The [json] parameter is a map containing the pledge data.
///
/// Returns an instance of `Pledge`.
factory Pledge.fromJson(Map<String, dynamic> json) {
return Pledge(
id: json['_id'] as String?,
campaigns: (json['campaigns'] as List<dynamic>?)
?.map((e) => e as Campaign)
.toList(),
pledgers: json['users'] == null
? null
: (json['users'] as List<dynamic>?)
?.map(
(e) => User.fromJson(e as Map<String, dynamic>, fromOrg: true),
)
.toList(),
startDate: json['startDate'] != null
? DateTime.parse(json['startDate'] as String)
: null,
endDate: json['endDate'] != null
? DateTime.parse(json['endDate'] as String)
: null,
amount: json['amount'] as int?,
currency: json['currency'] as String?,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: null,
updatedAt: json['updatedAt'] != null
? DateTime.parse(json['updatedAt'] as String)
: null,
);
}

/// The unique identifier of the pledge.
final String? id;

/// A list of campaign identifiers associated with the pledge.
final List<Campaign>? campaigns;

/// A list of user identifiers associated with the pledge.
final List<User>? pledgers;

/// The start date of the pledge.
final DateTime? startDate;

/// The end date of the pledge.
final DateTime? endDate;

/// The amount pledged.
final int? amount;

/// The currency of the pledged amount.
final String? currency;

/// The timestamp of when the pledge was created.
final DateTime? createdAt;

/// The timestamp of when the pledge was last updated.
final DateTime? updatedAt;
}
2 changes: 1 addition & 1 deletion lib/services/event_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EventService extends BaseFeedManager<Event> {
final String currentOrgID = _currentOrg.id!;
// mutation to fetch the events
final String mutation = EventQueries().fetchOrgEvents(currentOrgID);
final result = await _dbFunctions.gqlAuthQuery(mutation);
final result = await _dbFunctions.gqlAuthMutation(mutation);

if (result.data == null) {
throw Exception('unable to fetch data');
Expand Down
Loading

0 comments on commit 6e33d49

Please sign in to comment.