Skip to content

Commit 5d981b7

Browse files
committed
Refactored so endpoint details are managed in-controller
This changes the setup of things so that controllers manage meta-details like the endpoint category name and the methods provided, rather than those being managed in other parts of the app. This prevents the need of managing references of these details across other files in the app, since these details can be accessed dynamically and programatically via the controllers. An Endpoints class handles references to all controllers and the high level actions to access the information of these.
1 parent 082e1a6 commit 5d981b7

15 files changed

+262
-258
lines changed

lib/controller/api_controller.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../service/endpoints.dart';
2+
3+
abstract class ApiController {
4+
/// Get details of the endpoints within this controller.
5+
EndpointControllerInfo info();
6+
7+
/// Placeholder endpoint function for not-yet-supported endpoints
8+
Future<String> notImplemented() async{
9+
return "THIS METHOD IS CURRENTLY NOT SUPPORTED";
10+
}
11+
}

lib/controller/attachments.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
35
import 'dart:convert';
46

5-
class Attachments {
7+
class Attachments extends ApiController {
8+
9+
@override
10+
EndpointControllerInfo info() {
11+
return EndpointControllerInfo(label: 'Attachments', endpoints: {
12+
'list': list,
13+
'create': create,
14+
'read': read,
15+
'update': update,
16+
'delete': delete,
17+
});
18+
}
619

720
Future<String> list() async{
821
print('Trying List');

lib/controller/books.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
35
import 'dart:convert';
46

5-
class Books {
7+
class Books extends ApiController {
8+
9+
@override
10+
EndpointControllerInfo info() {
11+
return EndpointControllerInfo(label: 'Books', endpoints: {
12+
'list': list,
13+
'create': create,
14+
'read': read,
15+
'update': update,
16+
'delete': delete,
17+
'export-html': exportHtml,
18+
'export-pdf': exportPdf,
19+
'export-plain-text': exportPlain,
20+
'export-markdown': exportMarkdown,
21+
});
22+
}
623

724
Future<String> list() async{
825
print('Trying List');

lib/controller/chapters.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
35
import 'dart:convert';
46

5-
class Chapters {
7+
class Chapters extends ApiController {
8+
9+
@override
10+
EndpointControllerInfo info() {
11+
return EndpointControllerInfo(label: 'Chapters', endpoints: {
12+
'list': list,
13+
'create': create,
14+
'read': read,
15+
'update': update,
16+
'delete': delete,
17+
'export-html': exportHtml,
18+
'export-pdf': exportPdf,
19+
'export-plain-text': exportPlain,
20+
'export-markdown': exportMarkdown,
21+
});
22+
}
623

724
Future<String> list() async{
825
String url = '$urlFull/api/image-gallery';

lib/controller/content_permissions.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
3-
import 'dart:convert';
45

5-
class ContentPermissions {
6+
class ContentPermissions extends ApiController {
7+
8+
@override
9+
EndpointControllerInfo info() {
10+
return EndpointControllerInfo(label: 'Content Permissions', endpoints: {
11+
'read': read,
12+
'update': notImplemented,
13+
});
14+
}
615

716
Future<String> read() async{
817
String contentType = 'page';

lib/controller/image_gallery.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
3-
import 'dart:convert';
45
import 'dart:io';
56

6-
import 'package:http_parser/http_parser.dart';
7-
8-
class image_gallery {
7+
class ImageGallery extends ApiController {
8+
9+
@override
10+
EndpointControllerInfo info() {
11+
return EndpointControllerInfo(label: 'Image Gallery', endpoints: {
12+
'list': list,
13+
'create': create,
14+
'read': read,
15+
'update': update,
16+
'delete': delete,
17+
});
18+
}
919

1020
Future<String> list() async{
1121
String url = '$urlFull/api/image-gallery';

lib/controller/methodshandler.dart

Lines changed: 0 additions & 187 deletions
This file was deleted.

lib/controller/pages.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
35
import 'dart:convert';
46

5-
class Pages {
7+
class Pages extends ApiController {
8+
9+
@override
10+
EndpointControllerInfo info() {
11+
return EndpointControllerInfo(label: 'Pages', endpoints: {
12+
'list': list,
13+
'create': create,
14+
'read': read,
15+
'update': update,
16+
'delete': delete,
17+
'export-html': exportHtml,
18+
'export-pdf': exportPdf,
19+
'export-plain-text': exportPlain,
20+
'export-markdown': exportMarkdown,
21+
});
22+
}
623

724
Future<String> list() async{
825
String url = '$urlFull/api/pages';

lib/controller/reycle_bin.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
import '../service/endpoints.dart';
2+
import 'api_controller.dart';
13
import 'server_info.dart';
24
import 'package:http/http.dart' as http;
3-
import 'dart:convert';
45

5-
class RecycleBin {
6+
class RecycleBin extends ApiController {
7+
8+
@override
9+
EndpointControllerInfo info() {
10+
return EndpointControllerInfo(label: 'Recycle Bin', endpoints: {
11+
'list': list,
12+
'restore': notImplemented,
13+
'destroy': destroy,
14+
});
15+
}
616

717
Future<String> list() async{
818
print('Trying List');
@@ -12,15 +22,6 @@ class RecycleBin {
1222
return response.body;
1323
}
1424

15-
Future<String> restore() async{
16-
17-
String deletionID= '121';
18-
19-
String url = '$urlFull/api/recycle-bin/$deletionID';
20-
var response = await http.get(Uri.parse(url), headers: headers);
21-
return response.body;
22-
}
23-
2425

2526
Future<String> destroy() async{
2627

0 commit comments

Comments
 (0)