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

Adds clubs models #86

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion lib/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export "src/models/data/reminders.dart";
export "src/models/data/schedule.dart";
export "src/models/data/sports.dart";
export "src/models/data/user.dart";

export "src/models/data/clubs/clubs.dart";
export "src/models/data/clubs/club_captains.dart";
export "src/models/data/clubs/club_admin.dart";
// view models
export "src/models/view/admin_schedules.dart";
export "src/models/view/builders/day_builder.dart";
Expand Down
14 changes: 11 additions & 3 deletions lib/src/data/clubs/club.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class Club {
/// The name of the club.
final String name;

/// The random id assigned to the club to identify it.
final String id;

/// Approval status of the club.
bool? isApproved;

/// A short description of the club.
final String shortDescription;

Expand All @@ -31,17 +37,19 @@ class Club {
final List<Message> messages;

/// A list of attendance for each member of the club.
final Map<String, int> attendance;
final Map<ContactInfo, int> attendance;

/// The captains of the club.
final List<ContactInfo> captains;
final List<ContactInfo?> captains;
todesj marked this conversation as resolved.
Show resolved Hide resolved

/// The faculty advisor for this club.
final ContactInfo facultyAdvisor;
final List<ContactInfo?> facultyAdvisor;
todesj marked this conversation as resolved.
Show resolved Hide resolved

/// Creates a new club.
Club({
required this.name,
required this.isApproved,
required this.id,
required this.shortDescription,
required this.description,
required this.phoneNumberRequested,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/data/contact_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ContactInfo {
///
/// This is filled in voluntary by the user, and cannot be retrieved from the
/// database. So this field will start off null, and be populated over time.
final String? phoneNumber;
late final String? phoneNumber;
todesj marked this conversation as resolved.
Show resolved Hide resolved

/// Bundles personal info about the user.
ContactInfo({
Expand Down
30 changes: 30 additions & 0 deletions lib/src/models/data/clubs/club_admin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "package:ramaz/models.dart";
import "package:ramaz/data.dart";
import "package:ramaz/services.dart";
import "package:ramaz/src/data/contact_info.dart";
import "../model.dart";
todesj marked this conversation as resolved.
Show resolved Hide resolved

/// Handles all the actions a admin may need to do
class ClubAdmins extends Model{
@override
Future<void> init() {
// TODO: implement init
throw UnimplementedError();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pseudo-code (like what you would do, maybe in comments) would be nice here instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I put there though? because I don't think we need anything in init() for Club Admins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe this doesn't need to be a data model (ie, it shouldn't be included in the Models collection). You can remove this function and extends Model. Then it'll just be a view model -- something the UI can use to make specific actions easier, but doesn't need to provide the underlying data.

}

/// Allows clubs admin to approve a club to be shown to all the users
Future<void> approveClub(Club club) async{
club.isApproved=true;
Services.instance.database.clubs.save(club.id, club.toJson());
}

/// Allows a clubs admin to delete a club.
Future<void> deleteClub(Club club) async{
Services.instance.database.clubs.delete(club.toJson());
todesj marked this conversation as resolved.
Show resolved Hide resolved
}

Future<void> addFacultyAdvisor(Club club, ContactInfo facultyAdvisor){
club.facultyAdvisor.add(facultyAdvisor);
Services.instance.database.clubs.update(club.toJson());
}
}
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 65 additions & 0 deletions lib/src/models/data/clubs/club_captains.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import "package:ramaz/models.dart";
import "package:ramaz/data.dart";
import "package:ramaz/services.dart";
import "package:ramaz/src/data/contact_info.dart";
todesj marked this conversation as resolved.
Show resolved Hide resolved
import "../model.dart";

/// A model which handles all the actions which a captain may need.
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
class ClubCaptains extends Model {

@override
Future<void> init() async{
}

/// Checks if a user is a captain.
bool isCaptain(Club club) =>
club.captains.contains(Models.instance.user.data.contactInfo);
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved

/// Checks if a user is a faculty advisor.
bool? isFacultyAdvisor(Club club) =>
club.facultyAdvisor.contains(Models.instance.user.data.contactInfo);
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved

/// Allows user to upload a club.
Future<void> uploadClub(Club newClub) async {
if((Models.instance.user.adminScopes ?? []).contains(AdminScope.clubs)){
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
newClub.isApproved = true;
}else{
newClub.isApproved = null;
}
todesj marked this conversation as resolved.
Show resolved Hide resolved
Services.instance.database.clubs.admin.create(newClub.toJson());
}

/// Allows admin or club captain to remove a member from a club.
Future<void> removeMember(Club club, ContactInfo member) async {
Models.instance.user.data.registeredClubs.remove(club.id);
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
club.members.remove(member);
Services.instance.database.clubs.memberRemove(
club.id, member.toJson()
);
club.attendance.remove(Models.instance.user.data.contactInfo);
}

/// Allows captain to post message.
Future<void>? postMessage(Club club, Message message) async {
todesj marked this conversation as resolved.
Show resolved Hide resolved
Services.instance.database.clubs.postMessage(club.id, message.toJson());
}

/// Allows captains to edit a club.
Future<void> editClub(Club club) async {
if((Models.instance.user.data.adminScopes ?? []).contains(
AdminScope.clubs)){
club.isApproved = true;
}else{
club.isApproved = null;
}
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
Services.instance.database.clubs.update(club.toJson());
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
}

/// Allows a captain to take attendance.
Future<void> takeAttendance(
ContactInfo member, Club club, bool attend) async{
todesj marked this conversation as resolved.
Show resolved Hide resolved
attend ? club.attendance[member]= (club.attendance[member]!) + 1
:club.attendance[member] = club.attendance[member]!;
todesj marked this conversation as resolved.
Show resolved Hide resolved
Services.instance.database.clubs.update(club.toJson());
}
}
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions lib/src/models/data/clubs/clubs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import "package:ramaz/models.dart";
import "package:ramaz/data.dart";
import "package:ramaz/services.dart";
import "../model.dart";

/// A model which handles all the club actions for users.
class Clubs extends Model{

/// List of all the clubs.
late List<Club> getAllClubs;
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved

///Returns a list of all the clubs that have been created.
@override
Future<void> init() async {
getAllClubs = [
for(final Map json in await Services.instance.database.clubs.getAll()){
Club.fromjson(json)
}
];
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
}

/// Allows a user to register
Future<void> registerForClub(Club club) async {
Models.instance.user.data.registeredClubs.add(club.id);
club.members.add(Models.instance.user.data.contactInfo);
Services.instance.database.clubs.register(
club.id, Models.instance.user.data.contactInfo.toJson()
);
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
club.attendance[(Models.instance.user.data.contactInfo)]=0;
todesj marked this conversation as resolved.
Show resolved Hide resolved
}

///Allows User to unregister from a club
Future<void> unregisterFromClub(Club club) async {
Models.instance.user.data.registeredClubs.remove(club.id);
club.members.remove(Models.instance.user.data.contactInfo);
Services.instance.database.clubs.unregister(
club.id, Models.instance.user.data.contactInfo.toJson()
);
club.attendance.remove(Models.instance.user.data.contactInfo);
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved
}

///Adds the User's phone number to contactInfo.phoneNumber
Future<void> addPhoneNumber(String number) async {
Models.instance.user.data.contactInfo.phoneNumber=number;
}
}
Levi-Lesches marked this conversation as resolved.
Show resolved Hide resolved