-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from bounswe/mobile/note-taking
Mobile/note taking
- Loading branch information
Showing
12 changed files
with
167 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'note.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Note { | ||
@JsonKey(name: 'title') | ||
final String title; | ||
|
||
@JsonKey(name: 'body') | ||
String body; // body of a note may change | ||
|
||
@JsonKey(name: '_id') | ||
final String id; | ||
|
||
@JsonKey(name: 'resource') | ||
final String resourceId; | ||
|
||
Note(this.title, this.body, this.id, this.resourceId); | ||
factory Note.fromJson(Map<String, dynamic> json) => _$NoteFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$NoteToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import 'package:bucademy/classes/discussion/comment.dart'; | ||
import 'package:bucademy/classes/discussion/discussion.dart'; | ||
import 'package:bucademy/classes/note/note.dart'; | ||
import 'package:bucademy/services/locator.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
@lazySingleton | ||
class NoteService { | ||
Future<Note?> postNote({ | ||
required String title, | ||
required String body, | ||
required String resourceId, | ||
}) async { | ||
try { | ||
Response response = await dioService.dio.post( | ||
'/note', | ||
data: {"resource_id": resourceId, "title": title, "body": body}, | ||
); | ||
|
||
Map json = response.data; | ||
return Note.fromJson(json['note']); | ||
} catch (e) { | ||
print(e); | ||
} | ||
return null; | ||
} | ||
|
||
Future<Note?> getNote({ | ||
required String noteId, | ||
}) async { | ||
try { | ||
Response response = await dioService.dio.get('/note/$noteId'); | ||
if (response.statusCode != 200) { | ||
return null; | ||
} | ||
Map json = response.data; | ||
return Note.fromJson(json['note']); | ||
} catch (e) { | ||
print(e); | ||
} | ||
return null; | ||
} | ||
|
||
Future<List<Note>> notesOfSpace({ | ||
required String spaceId, | ||
}) async { | ||
if (userService.user == null) { | ||
return []; // cannot get notes if the user is not logged in | ||
} | ||
try { | ||
Response response = await dioService.dio.post( | ||
'/note/getNoteList', | ||
data: {"space_id": spaceId}, | ||
); | ||
Map json = response.data; | ||
return json['notes'].map<Note>((e) => Note.fromJson(e)).toList(); | ||
} catch (e) { | ||
print(e); | ||
} | ||
return []; | ||
} | ||
|
||
Future<Note?> updateNote({ | ||
required String noteId, | ||
required String body, | ||
}) async { | ||
try { | ||
Response response = await dioService.dio.put( | ||
'/note/update', | ||
data: {"note_id": noteId, "body": body}, | ||
); | ||
Map json = response.data; | ||
return Note.fromJson(json['note']); | ||
} catch (e) { | ||
print(e); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters