diff --git a/lib/data/api/notes_api.dart b/lib/data/api/notes_api.dart index 048cdf7..0f3dfd1 100644 --- a/lib/data/api/notes_api.dart +++ b/lib/data/api/notes_api.dart @@ -32,12 +32,14 @@ class NotesApi { String body, { List tags = const [], int? projectId, + String noteType = 'note', }) async { try { final response = await _dio.post('/api/notes', data: { 'title': title, 'body': body, 'tags': tags, + 'note_type': noteType, if (projectId != null) 'project_id': projectId, }); return Note.fromJson(response.data as Map); @@ -53,12 +55,14 @@ class NotesApi { List tags = const [], int? projectId, bool clearProject = false, + String noteType = 'note', }) async { try { final response = await _dio.put('/api/notes/$id', data: { 'title': title, 'body': body, 'tags': tags, + 'note_type': noteType, if (clearProject) 'project_id': null else if (projectId != null) 'project_id': projectId, }); return Note.fromJson(response.data as Map); diff --git a/lib/data/models/note.dart b/lib/data/models/note.dart index 4f36379..7e1218d 100644 --- a/lib/data/models/note.dart +++ b/lib/data/models/note.dart @@ -3,6 +3,7 @@ class Note { final String title; final String body; final List tags; + final String noteType; final int? projectId; final int? milestoneId; final DateTime createdAt; @@ -13,6 +14,7 @@ class Note { required this.title, required this.body, required this.tags, + this.noteType = 'note', this.projectId, this.milestoneId, required this.createdAt, @@ -27,6 +29,7 @@ class Note { ?.map((e) => e as String) .toList() ?? [], + noteType: json['note_type'] as String? ?? 'note', projectId: json['project_id'] as int?, milestoneId: json['milestone_id'] as int?, createdAt: DateTime.parse(json['created_at'] as String), @@ -37,6 +40,7 @@ class Note { 'title': title, 'body': body, 'tags': tags, + 'note_type': noteType, 'project_id': projectId, 'milestone_id': milestoneId, }; @@ -45,6 +49,7 @@ class Note { String? title, String? body, List? tags, + String? noteType, Object? projectId = _undefined, Object? milestoneId = _undefined, }) => @@ -53,6 +58,7 @@ class Note { title: title ?? this.title, body: body ?? this.body, tags: tags ?? this.tags, + noteType: noteType ?? this.noteType, projectId: identical(projectId, _undefined) ? this.projectId : projectId as int?, diff --git a/lib/data/repositories/notes_repository.dart b/lib/data/repositories/notes_repository.dart index 6fb1b44..681d4f8 100644 --- a/lib/data/repositories/notes_repository.dart +++ b/lib/data/repositories/notes_repository.dart @@ -13,8 +13,10 @@ class NotesRepository { String body, { List tags = const [], int? projectId, + String noteType = 'note', }) => - _api.create(title, body, tags: tags, projectId: projectId); + _api.create(title, body, + tags: tags, projectId: projectId, noteType: noteType); Future update( int id, @@ -23,9 +25,13 @@ class NotesRepository { List tags = const [], int? projectId, bool clearProject = false, + String noteType = 'note', }) => _api.update(id, title, body, - tags: tags, projectId: projectId, clearProject: clearProject); + tags: tags, + projectId: projectId, + clearProject: clearProject, + noteType: noteType); Future delete(int id) => _api.delete(id); } diff --git a/lib/providers/notes_provider.dart b/lib/providers/notes_provider.dart index fcbaa14..f611158 100644 --- a/lib/providers/notes_provider.dart +++ b/lib/providers/notes_provider.dart @@ -17,10 +17,14 @@ class NotesNotifier extends AsyncNotifier> { String body, { List tags = const [], int? projectId, + String noteType = 'note', }) async { - final note = await ref - .read(notesRepositoryProvider) - .create(title, body, tags: tags, projectId: projectId); + final note = await ref.read(notesRepositoryProvider).create( + title, body, + tags: tags, + projectId: projectId, + noteType: noteType, + ); state = AsyncData([...state.value ?? [], note]); return note; } @@ -32,6 +36,7 @@ class NotesNotifier extends AsyncNotifier> { List tags = const [], int? projectId, bool clearProject = false, + String noteType = 'note', }) async { final updated = await ref.read(notesRepositoryProvider).update( id, @@ -40,6 +45,7 @@ class NotesNotifier extends AsyncNotifier> { tags: tags, projectId: projectId, clearProject: clearProject, + noteType: noteType, ); state = AsyncData([ for (final n in state.value ?? []) diff --git a/test/widget_test.dart b/test/widget_test.dart index 2ebd3e2..ae0761c 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -1,8 +1,33 @@ -// Placeholder — integration tests go here once the app is running on device. +import 'package:fabled_app/data/models/note.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - test('placeholder', () { - expect(true, isTrue); + group('Note.fromJson', () { + test('parses noteType when present', () { + final json = { + 'id': 1, + 'title': 'Alice', + 'body': '', + 'tags': [], + 'note_type': 'person', + 'created_at': '2024-01-01T00:00:00', + 'updated_at': '2024-01-01T00:00:00', + }; + final note = Note.fromJson(json); + expect(note.noteType, equals('person')); + }); + + test('defaults noteType to note when absent', () { + final json = { + 'id': 2, + 'title': 'My note', + 'body': '', + 'tags': [], + 'created_at': '2024-01-01T00:00:00', + 'updated_at': '2024-01-01T00:00:00', + }; + final note = Note.fromJson(json); + expect(note.noteType, equals('note')); + }); }); }