From bfd0cd8fdf233fd2ecbfcdf4997de2de1a07df9a Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Tue, 25 Apr 2023 19:17:07 -0400 Subject: [PATCH] sachet/server/views_common.py: split off POST from ModelAPI Now it's in ModelListAPI --- sachet/server/files/views.py | 4 ++-- sachet/server/views_common.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sachet/server/files/views.py b/sachet/server/files/views.py index e3336cb..bf6e4b7 100644 --- a/sachet/server/files/views.py +++ b/sachet/server/files/views.py @@ -3,7 +3,7 @@ import io from flask import Blueprint, request, jsonify, send_file from flask.views import MethodView from sachet.server.models import Share, Permissions -from sachet.server.views_common import ModelAPI, auth_required +from sachet.server.views_common import ModelAPI, ModelListAPI, auth_required from sachet.server import storage, db files_blueprint = Blueprint("files_blueprint", __name__) @@ -38,7 +38,7 @@ files_blueprint.add_url_rule( ) -class FilesAPI(ModelAPI): +class FilesAPI(ModelListAPI): @auth_required(required_permissions=(Permissions.CREATE,)) def post(self, auth_user=None): data = request.get_json() diff --git a/sachet/server/views_common.py b/sachet/server/views_common.py index 91d7b68..48a13da 100644 --- a/sachet/server/views_common.py +++ b/sachet/server/views_common.py @@ -94,7 +94,7 @@ def patch(orig, diff): class ModelAPI(MethodView): - """Generic REST API for interacting with models.""" + """Generic REST API for the representation of a model instance.""" def get(self, model): if not model: @@ -190,6 +190,10 @@ class ModelAPI(MethodView): return jsonify({"status": "success"}) + +class ModelListAPI(MethodView): + """Generic API for representing all instances of a given model.""" + def post(self, ModelClass, data={}): """Create new instance of a class.