Implement whole ass "backend"
This commit is contained in:
64
lib/notes.dart
Normal file
64
lib/notes.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:journaler/db.dart';
|
||||
|
||||
class Note {
|
||||
final String date;
|
||||
String content;
|
||||
|
||||
Note({required this.date, required this.content});
|
||||
}
|
||||
|
||||
class Todo {
|
||||
final String date;
|
||||
final String content;
|
||||
|
||||
Todo({required this.date, required this.content});
|
||||
}
|
||||
|
||||
Future<Note?> getLatestNote() async {
|
||||
final note = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM notes ORDER BY date DESC LIMIT 1',
|
||||
);
|
||||
if (note.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Note(
|
||||
date: note[0]['date'] as String,
|
||||
content: note[0]['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createNote(String content) async {
|
||||
if (content.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await DB.db.insert('notes', {'content': content});
|
||||
}
|
||||
|
||||
Future<void> updateNote(Note note) async {
|
||||
await DB.db.update(
|
||||
'notes',
|
||||
{'content': note.content},
|
||||
where: 'date = ?',
|
||||
whereArgs: [note.date],
|
||||
);
|
||||
}
|
||||
|
||||
Future<Todo?> getLatestTodo() async {
|
||||
final todo = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM todos ORDER BY date DESC LIMIT 1',
|
||||
);
|
||||
if (todo.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Todo(
|
||||
date: todo[0]['date'] as String,
|
||||
content: todo[0]['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createTodo(String content) async {
|
||||
if (content.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await DB.db.insert('todos', {'content': content});
|
||||
}
|
Reference in New Issue
Block a user