summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorromangraef <roman.graef@gmail.com>2018-06-09 20:05:49 +0200
committerromangraef <roman.graef@gmail.com>2018-06-09 20:05:49 +0200
commitbf6800e7c7bb768d32dc214c4334ba164f081efb (patch)
tree8d5d893004edcb2bad0f5dca9997ea8c5ecf5a46
parente0d6c5ccdf6576aba56406455d9833de9626f7de (diff)
downloaddatapackmanagerapi-master.tar.gz
datapackmanagerapi-master.tar.bz2
datapackmanagerapi-master.zip
datapack remodel continuedHEADmaster
-rw-r--r--api/v1/db.py4
-rw-r--r--api/v1/server.py14
-rw-r--r--api/v1/util.py7
3 files changed, 20 insertions, 5 deletions
diff --git a/api/v1/db.py b/api/v1/db.py
index 1d9f469..f19f306 100644
--- a/api/v1/db.py
+++ b/api/v1/db.py
@@ -37,8 +37,8 @@ class DataPack(BaseModel):
class TagRelation(BaseModel):
- tags = ForeignKeyField(Tag)
- packs = ForeignKeyField(DataPack)
+ tag = ForeignKeyField(Tag)
+ pack = ForeignKeyField(DataPack)
class Comment(BaseModel):
diff --git a/api/v1/server.py b/api/v1/server.py
index 96ff8da..a5bf613 100644
--- a/api/v1/server.py
+++ b/api/v1/server.py
@@ -1,7 +1,7 @@
from flask import Blueprint, jsonify, abort, make_response, request
-from .db import Category, DataPack
-from .util import model_paginator, query_paginator, ConstrainFailed
+from .db import Category, DataPack, User, Tag, TagRelation
+from .util import model_paginator, query_paginator, ConstrainFailed, get_tags_for_datapack
bp = Blueprint("api v1", __name__)
@@ -36,13 +36,21 @@ def list_categories():
@bp.route('/list/datapacks')
def list_datapacks():
category = request.args.get('category', '')
- query = DataPack.select()
+ query = DataPack.select().join(User)
if category != '':
query = query.join(Category).where(DataPack.category.id == category)
return query_paginator(query, lambda dp: {
'name': dp.name,
'id': dp.id,
+ 'description': dp.description,
+ 'tags': get_tags_for_datapack(dp),
+ 'author': dp.author.id,
+ 'likes': dp.likes,
+ 'dislikes': dp.dislikes,
+ 'downloads': dp.downloads,
+ 'views': dp.views,
'category': dp.category.id,
+
})
diff --git a/api/v1/util.py b/api/v1/util.py
index f2dddad..3b79b82 100644
--- a/api/v1/util.py
+++ b/api/v1/util.py
@@ -3,6 +3,8 @@ import typing
from flask import jsonify, request
from peewee import Model, ModelSelect
+from api.v1.db import DataPack, Tag, TagRelation
+
_V = typing.TypeVar('_V', bound=Model)
@@ -59,3 +61,8 @@ def query_paginator(query: ModelSelect, mapping: typing.Callable[[_V], dict]):
'next': offset + size if more else None,
'results': res,
})
+
+
+def get_tags_for_datapack(datapack: DataPack):
+ return [tag.name for tag in
+ Tag.select().join(TagRelation).join(DataPack).where(TagRelation.pack.id == int(datapack.id))]