Add topics API
This commit is contained in:
parent
67a229b8a3
commit
73c65e3561
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue