Add topics API

This commit is contained in:
rubenwardy 2018-07-06 23:41:44 +01:00
parent 67a229b8a3
commit 73c65e3561
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
2 changed files with 22 additions and 0 deletions

View File

@ -790,6 +790,20 @@ class ForumTopic(db.Model):
return self.link.replace("repo.or.cz/w/", "repo.or.cz/")
def getAsDictionary(self):
return {
"author": self.author.username,
"name": self.name,
"type": self.type.toName(),
"title": self.title,
"id": self.topic_id,
"link": self.link,
"posts": self.posts,
"views": self.views,
"is_wip": self.wip,
"created_at": self.created_at.isoformat(),
}
# Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model

View File

@ -33,3 +33,11 @@ def api_packages_page():
@is_package_page
def api_package_page(package):
return jsonify(package.getAsDictionary(app.config["BASE_URL"]))
@app.route("/api/topics/")
def api_topics_page():
query = ForumTopic.query \
.order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
pkgs = [t.getAsDictionary() for t in query.all()]
return jsonify(pkgs)