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

Task creation form #47

Merged
merged 3 commits into from
May 26, 2024
Merged
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
18 changes: 9 additions & 9 deletions lib/config/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import 'package:flutter/material.dart';

class AppColors {
// dark theme colors
static const Color primaryDark = Colors.green;
static Color primaryDark500 = Colors.green.shade500;
static Color primaryDark800 = Colors.green.shade800;
static const Color primaryDark = Colors.purple;
static Color primaryDark500 = Colors.purple.shade500;
static Color primaryDark800 = Colors.purple.shade800;
static const Color backgroundDark = Colors.black;
static Color scaffoldBackgroundDark = Colors.grey.shade900;
static Color scaffoldBackgroundDark = Color.fromARGB(255, 7, 8, 12);
static const Color cardDark = Colors.black12;
static const Color shadowDark = Colors.black;
static const Color drawerBackgroundDark = Colors.black87;
static const Color dialogBackgroundDark = Colors.grey;

// light colors
static const Color primaryLight = Colors.green;
static Color primaryLight400 = Colors.green.shade400;
static Color primaryLight50 = Colors.green.shade50;
static const Color primaryLight = Colors.purple;
static Color primaryLight400 = Colors.purple.shade400;
static Color primaryLight50 = Colors.purple.shade50;
static const Color backgroundLight = Colors.white;
static const Color scaffoldBackgroundLight = Colors.white;
static Color cardLight = Colors.grey.shade200;
static Color shadowLight = Colors.grey.shade200;
static Color drawerBackgroundLight = Colors.green.shade50;
static Color dialogBackgroundLight = Colors.green.shade50;
static Color drawerBackgroundLight = Colors.purple.shade50;
static Color dialogBackgroundLight = Colors.purple.shade50;
}
1 change: 1 addition & 0 deletions lib/controllers/auth/signup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SignUpController {
final FirebaseAuth _auth = FirebaseAuth.instance;
final ValueNotifier<bool> isLoading = ValueNotifier<bool>(false);


Future<Either<String, User?>> signUp(
BuildContext context, String email, String password) async {
try {
Expand Down
87 changes: 69 additions & 18 deletions lib/controllers/common/event_controller.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,80 @@
import 'package:Organiser/models/common/event.dart';
import 'package:flutter/material.dart';
import 'package:Organiser/models/common/event_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class EventModel extends ChangeNotifier {
List<Event> events = [];
class EventController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;

void addEvent(Event newEvent) {
events.add(newEvent);
notifyListeners();
EventController(this._parentCollection);

Future<void> addEvent(String documentId, Event event) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('events')
.add(event.toMap());
} catch (e) {
print('Error adding event: $e');
rethrow;
}
}

Future<void> updateEvent(String documentId, Event event) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('events')
.doc(event.id)
.set(event.toMap());
} catch (e) {
print('Error updating event: $e');
rethrow;
}
}

void updateEvent(Event updatedEvent) {
final index = events.indexWhere((event) => event.id == updatedEvent.id);
if (index != -1) {
events[index] = updatedEvent;
notifyListeners();
Future<void> deleteEvent(String documentId, String eventId) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('events')
.doc(eventId)
.delete();
} catch (e) {
print('Error deleting event: $e');
rethrow;
}
}

void deleteEvent(String eventId) {
events.removeWhere((event) => event.id == eventId);
notifyListeners();
Stream<List<Event>> getAllEvents(String documentId) {
return _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('events')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Event.fromMap(doc.data(), doc.id))
.toList());
}

Event? getEventById(String eventId) {
return events.firstWhere((event) => event.id == eventId);
Future<Event?> getEventById(String documentId, String eventId) async {
try {
var docSnapshot = await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('events')
.doc(eventId)
.get();
if (docSnapshot.exists) {
return Event.fromMap(
docSnapshot.data() as Map<String, dynamic>, eventId);
}
return null;
} catch (e) {
print('Error fetching event: $e');
rethrow;
}
}

}
98 changes: 98 additions & 0 deletions lib/controllers/common/food_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'package:Organiser/models/common/food_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class FoodController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;

Future<Food?> getFood(String marketId, String foodId) async {
try {
var docSnapshot = await _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.doc(foodId)
.get();
if (docSnapshot.exists) {
return Food.fromJson(docSnapshot.data() as Map<String, dynamic>);
}
return null;
} catch (e) {
print('Error getting food: $e');
rethrow;
}
}

Future<List<Food>> getAllFoods(String marketId) async {
try {
var querySnapshot = await _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.get();
return querySnapshot.docs
.map((doc) => Food.fromJson(doc.data()))
.toList();
} catch (e) {
print('Error getting all foods: $e');
rethrow;
}
}

Stream<List<Food>> listenToFoods(String marketId) {
try {
return _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Food.fromJson(doc.data()))
.toList());
} catch (e) {
print('Error listening to foods: $e');
rethrow;
}
}

Future<void> addFood(String marketId, Food food) async {
try {
await _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.doc(food.id)
.set(food.toJson());
} catch (e) {
print('Error adding food: $e');
rethrow;
}
}

Future<void> updateFood(String marketId, Food food) async {
try {
await _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.doc(food.id)
.update(food.toJson());
} catch (e) {
print('Error updating food: $e');
rethrow;
}
}

Future<void> deleteFood(String marketId, String foodId) async {
try {
await _firestore
.collection('markets')
.doc(marketId)
.collection('foods')
.doc(foodId)
.delete();
} catch (e) {
print('Error deleting food: $e');
rethrow;
}
}
}
79 changes: 79 additions & 0 deletions lib/controllers/common/goal_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:Organiser/models/common/goal_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class GoalController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;

GoalController(this._parentCollection);

Future<void> addGoal(String documentId, Goal goal) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('goals')
.add(goal.toMap());
} catch (e) {
print('Error adding goal: $e');
rethrow;
}
}

Future<void> updateGoal(String documentId, Goal goal) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('goals')
.doc(goal.id)
.set(goal.toMap());
} catch (e) {
print('Error updating goal: $e');
rethrow;
}
}

Future<void> deleteGoal(String documentId, String goalId) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('goals')
.doc(goalId)
.delete();
} catch (e) {
print('Error deleting goal: $e');
rethrow;
}
}

Stream<List<Goal>> getAllGoals(String documentId) {
return _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('goals')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Goal.fromMap(doc.data(), doc.id))
.toList());
}

Future<Goal?> getGoalById(String documentId, String goalId) async {
try {
var docSnapshot = await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('goals')
.doc(goalId)
.get();
if (docSnapshot.exists) {
return Goal.fromMap(docSnapshot.data() as Map<String, dynamic>, goalId);
}
return null;
} catch (e) {
print('Error fetching goal: $e');
rethrow;
}
}
}
79 changes: 79 additions & 0 deletions lib/controllers/common/meal_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:Organiser/models/common/meal_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class MealController {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
String _parentCollection;

MealController(this._parentCollection);

Future<void> addMeal(String documentId, Meal meal) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('meals')
.add(meal.toMap());
} catch (e) {
print('Error adding meal: $e');
rethrow;
}
}

Future<void> updateMeal(String documentId, Meal meal) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('meals')
.doc(meal.id)
.set(meal.toMap());
} catch (e) {
print('Error updating meal: $e');
rethrow;
}
}

Future<void> deleteMeal(String documentId, String mealId) async {
try {
await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('meals')
.doc(mealId)
.delete();
} catch (e) {
print('Error deleting meal: $e');
rethrow;
}
}

Stream<List<Meal>> getAllMeals(String documentId) {
return _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('meals')
.snapshots()
.map((snapshot) => snapshot.docs
.map((doc) => Meal.fromMap(doc.data(), doc.id))
.toList());
}

Future<Meal?> getMealById(String documentId, String mealId) async {
try {
var docSnapshot = await _firestore
.collection(_parentCollection)
.doc(documentId)
.collection('meals')
.doc(mealId)
.get();
if (docSnapshot.exists) {
return Meal.fromMap(docSnapshot.data() as Map<String, dynamic>, mealId);
}
return null;
} catch (e) {
print('Error fetching meal: $e');
rethrow;
}
}
}
Loading