summaryrefslogtreecommitdiff
path: root/archivist/server/tag.py
blob: 8142cd172c868271f3f7ac9402067bcb5437fa73 (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
from flask import request
from flask_restplus import Resource, fields, Namespace

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(201, "Tag created")
    @api.response(409, "Tag already exists")
    def put(self):
        """Create a new tag."""
        data = request.get_json()
        tag, created = bl.PrefixTag(**data).create()
        if created:
            return '',201
        else:
            return '',409