diff --git a/lib/controllers/post_editor_controller.dart b/lib/controllers/post_editor_controller.dart index 71c4558..b9971cc 100644 --- a/lib/controllers/post_editor_controller.dart +++ b/lib/controllers/post_editor_controller.dart @@ -94,6 +94,7 @@ class PostEditorController extends GetxController { 'repost_to': repostTo.value?.toJson(), 'edit_to': editTo.value?.toJson(), 'realm': realmZone.value?.toJson(), + 'type': type, }), ); } @@ -131,6 +132,7 @@ class PostEditorController extends GetxController { return; } + type = value.type; editTo.value = value; isDraft.value = value.isDraft ?? false; titleController.text = value.body['title'] ?? ''; @@ -142,6 +144,37 @@ class PostEditorController extends GetxController { contentLength.value = contentController.text.length; } + String get typeEndpoint { + switch(mode.value) { + case 0: + return 'stories'; + case 1: + return 'articles'; + default: + return 'stories'; + } + } + + String get type { + switch(mode.value) { + case 0: + return 'story'; + case 1: + return 'article'; + default: + return 'story'; + } + } + + set type(String value) { + switch (value) { + case 'story': + mode.value = 0; + case 'article': + mode.value = 1; + } + } + String? get title { if (titleController.text.isEmpty) return null; return titleController.text; @@ -168,6 +201,7 @@ class PostEditorController extends GetxController { } set payload(Map value) { + type = value['type']; titleController.text = value['title'] ?? ''; descriptionController.text = value['description'] ?? ''; contentController.text = value['content'] ?? ''; diff --git a/lib/models/post.dart b/lib/models/post.dart index a321229..bf813f5 100755 --- a/lib/models/post.dart +++ b/lib/models/post.dart @@ -12,6 +12,7 @@ class Post { List? tags; List? categories; List? replies; + String type; int? replyId; int? repostId; int? realmId; @@ -31,6 +32,7 @@ class Post { required this.updatedAt, required this.editedAt, required this.deletedAt, + required this.type, required this.body, required this.tags, required this.categories, @@ -56,6 +58,7 @@ class Post { deletedAt: json['deleted_at'] != null ? DateTime.parse(json['deleted_at']) : null, + type: json['type'], body: json['body'], tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast(), categories: json['categories'] @@ -93,6 +96,7 @@ class Post { 'updated_at': updatedAt.toIso8601String(), 'edited_at': editedAt?.toIso8601String(), 'deleted_at': deletedAt?.toIso8601String(), + 'type': type, 'body': body, 'tags': tags, 'categories': categories, diff --git a/lib/screens/posts/post_editor.dart b/lib/screens/posts/post_editor.dart index 40138fd..f7cf90f 100644 --- a/lib/screens/posts/post_editor.dart +++ b/lib/screens/posts/post_editor.dart @@ -59,12 +59,12 @@ class _PostPublishScreenState extends State { Response resp; if (widget.edit != null) { resp = await client.put( - '/stories/${widget.edit!.id}', + '/${_editorController.typeEndpoint}/${widget.edit!.id}', _editorController.payload, ); } else { resp = await client.post( - '/stories', + '/${_editorController.typeEndpoint}', _editorController.payload, ); }