blob: 4573c558ff3bc71c00e8a26f8389636d4acefb39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
from flask import request
from flask_restplus import Resource, fields, Namespace
from http import HTTPStatus
from .. import model as m
from .. import bl
api = Namespace('tag', description = 'Operations on tags')
tag = api.model('Tag', {
'name' : fields.String(required=True),
'prefix' : fields.String,
'description' : fields.String
})
@api.route('/')
class TagList(Resource):
@api.marshal_list_with(tag)
def get(self):
"""List all available tags."""
return list(m.Tag.select().where(~m.Tag.default).dicts().iterator())
@api.expect(tag, validate=True)
@api.response(HTTPStatus.CREATED, "Tag created")
@api.response(HTTPStatus.CONFLICT, "Tag already exists")
def put(self):
"""Create a new tag."""
data = request.get_json()
tag, created = bl.PrefixTag(**data).create()
if created:
return '', HTTPStatus.CREATED
else:
return '', HTTPStatus.CONFLICT
|