Skip to content

Commit

Permalink
Merge pull request #2 from it-goats/feature/ITG-31
Browse files Browse the repository at this point in the history
[ITG-31] Dodać obsługę buttona delete z API
  • Loading branch information
bkulawska committed Apr 2, 2022
2 parents 3607707 + 58dfb0f commit 712ad31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bode/bode/models/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm.exc import NoResultFound

from bode.app import db

Expand All @@ -19,5 +20,16 @@ def create(**kwargs):

return task

def delete(task_id):
task = Task.query.get(task_id)

if task is None:
raise NoResultFound

db.session.delete(task)
db.session.commit()

return task

def __repr__(self):
return f'<Task {self.id} \n title="{self.title}">'
12 changes: 12 additions & 0 deletions bode/bode/resources/tasks/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import abort
from flask.views import MethodView
from flask_smorest import Blueprint
from sqlalchemy.orm.exc import NoResultFound

from bode.models.task import Task
from bode.resources.tasks.schemas import TaskSchema
Expand All @@ -17,3 +19,13 @@ def get(self):
@blueprint.response(201, TaskSchema)
def post(self, task_data):
return Task.create(**task_data)


@blueprint.route("/<task_id>")
class TasksById(MethodView):
@blueprint.response(201, TaskSchema)
def delete(self, task_id):
try:
return Task.delete(task_id)
except NoResultFound:
abort(404, message="Item not found.")

0 comments on commit 712ad31

Please sign in to comment.