forked from firka/student-legacy
added self notes thing to db
This commit is contained in:
parent
697c003678
commit
f5ad70fb28
@ -58,6 +58,8 @@ const userDataDB = DatabaseStruct("user_data", {
|
|||||||
"goal_averages": String,
|
"goal_averages": String,
|
||||||
"goal_befores": String,
|
"goal_befores": String,
|
||||||
"goal_pin_dates": String,
|
"goal_pin_dates": String,
|
||||||
|
// todo and notes
|
||||||
|
"todo_items": String, "self_notes": String,
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> createTable(Database db, DatabaseStruct struct) =>
|
Future<void> createTable(Database db, DatabaseStruct struct) =>
|
||||||
@ -115,6 +117,8 @@ Future<Database> initDB(DatabaseProvider database) async {
|
|||||||
"goal_averages": "{}",
|
"goal_averages": "{}",
|
||||||
"goal_befores": "{}",
|
"goal_befores": "{}",
|
||||||
"goal_pin_dates": "{}",
|
"goal_pin_dates": "{}",
|
||||||
|
// todo and notes
|
||||||
|
"todo_items": "{}", "self_notes": "[]"
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print("ERROR: migrateDB: $error");
|
print("ERROR: migrateDB: $error");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||||
|
import 'package:filcnaplo/models/self_note.dart';
|
||||||
import 'package:filcnaplo/models/subject_lesson_count.dart';
|
import 'package:filcnaplo/models/subject_lesson_count.dart';
|
||||||
import 'package:filcnaplo/models/user.dart';
|
import 'package:filcnaplo/models/user.dart';
|
||||||
import 'package:filcnaplo_kreta_api/models/week.dart';
|
import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||||
@ -281,4 +282,27 @@ class UserDatabaseQuery {
|
|||||||
return (jsonDecode(goalPinDatesJson) as Map)
|
return (jsonDecode(goalPinDatesJson) as Map)
|
||||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get todo items and notes
|
||||||
|
Future<Map<String, bool>> toDoItems({required String userId}) async {
|
||||||
|
List<Map> userData =
|
||||||
|
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||||
|
if (userData.isEmpty) return {};
|
||||||
|
String? toDoItemsJson = userData.elementAt(0)["todo_items"] as String?;
|
||||||
|
if (toDoItemsJson == null) return {};
|
||||||
|
return (jsonDecode(toDoItemsJson) as Map).map((key, value) =>
|
||||||
|
MapEntry(key.toString(), value.toString().toLowerCase() == 'true'));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<SelfNote>> getSelfNotes({required String userId}) async {
|
||||||
|
List<Map> userData =
|
||||||
|
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||||
|
if (userData.isEmpty) return [];
|
||||||
|
String? selfNotesJson = userData.elementAt(0)["self_notes"] as String?;
|
||||||
|
if (selfNotesJson == null) return [];
|
||||||
|
List<SelfNote> selfNotes = (jsonDecode(selfNotesJson) as List)
|
||||||
|
.map((e) => SelfNote.fromJson(e))
|
||||||
|
.toList();
|
||||||
|
return selfNotes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:filcnaplo/models/self_note.dart';
|
||||||
import 'package:filcnaplo/models/subject_lesson_count.dart';
|
import 'package:filcnaplo/models/subject_lesson_count.dart';
|
||||||
import 'package:filcnaplo_kreta_api/models/week.dart';
|
import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||||
// ignore: depend_on_referenced_packages
|
// ignore: depend_on_referenced_packages
|
||||||
@ -177,4 +178,19 @@ class UserDatabaseStore {
|
|||||||
await db.update("user_data", {"goal_pin_dates": goalPinDatesJson},
|
await db.update("user_data", {"goal_pin_dates": goalPinDatesJson},
|
||||||
where: "id = ?", whereArgs: [userId]);
|
where: "id = ?", whereArgs: [userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo and notes
|
||||||
|
Future<void> storeToDoItem(Map<String, bool> items,
|
||||||
|
{required String userId}) async {
|
||||||
|
String toDoItemsJson = jsonEncode(items);
|
||||||
|
await db.update("user_data", {"todo_items": toDoItemsJson},
|
||||||
|
where: "id = ?", whereArgs: [userId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> storeSelfNotes(List<SelfNote> absences,
|
||||||
|
{required String userId}) async {
|
||||||
|
String selfNotesJson = jsonEncode(absences.map((e) => e.json).toList());
|
||||||
|
await db.update("user_data", {"self_notes": selfNotesJson},
|
||||||
|
where: "id = ?", whereArgs: [userId]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user