-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API upgraded for tags fontman/fontman-desktop#39
- Loading branch information
1 parent
8cc99e3
commit 6691ae4
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" Tags controller | ||
REST blueprint for font tags. | ||
Created by Lahiru Pathirage @ Mooniak <lpsandaruwan@gmail.com> on 8/2/2017 | ||
""" | ||
|
||
from flask import Blueprint, jsonify, request | ||
|
||
from service import TagService | ||
|
||
tags_blueprint = Blueprint("tags_blueprint", __name__) | ||
|
||
|
||
@tags_blueprint.route("/tags/<font_id>") | ||
def find_tags_by_font_id(font_id): | ||
response_data = [] | ||
tags = TagService().find_by_font_id(font_id) | ||
|
||
for tag in tags: | ||
response_data.append( | ||
{ | ||
"tag_id": tag.tag_id, | ||
"font_id": tag.font_id, | ||
"key": tag.key, | ||
"value": tag.value | ||
} | ||
) | ||
|
||
return response_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" Tag | ||
Keeps tags on more information of fonts. | ||
Eg: languages, serif/sans-serif... | ||
Created by Lahiru Pathirage @ Mooniak<lpsandaruwan@gmail.com> on 8/2/2017 | ||
""" | ||
|
||
from sqlalchemy import Column, ForeignKey, Integer | ||
from sqlalchemy import String | ||
|
||
from session import Base | ||
|
||
|
||
class Tag(Base): | ||
|
||
__tablename__ = "tag" | ||
|
||
tag_id = Column(Integer, primary_key=True) | ||
font_id = Column(Integer, ForeignKey("font.font_id"), nullable=False) | ||
key = Column(String(20), nullable=False) | ||
value = Column(String(20), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" Tags service | ||
High level functions to manipulate tags table. | ||
Created by Lahiru Pathirage @ Mooniak<lpsandaruwan@gmail.com> on 4/1/2017 | ||
""" | ||
|
||
from model import Tag | ||
from session import DBSession | ||
|
||
|
||
class TagService: | ||
|
||
def __init__(self): | ||
self.__db_session = DBSession() | ||
|
||
def add_new(self, font_id, key, value): | ||
new_tag = Tag( | ||
font_id=font_id, | ||
key = key, | ||
value=value | ||
) | ||
|
||
self.__db_session.add(new_tag) | ||
self.__db_session.commit() | ||
|
||
return new_tag | ||
|
||
def delete_by_font_id(self, font_id): | ||
self.find_by_font_id(font_id).delete() | ||
self.__db_session.commit() | ||
|
||
def find_by_font_id(self, font_id): | ||
return self.__db_session.query(Tag).filter_by(font_id=font_id) | ||
|
||
def find_by_key(self,key): | ||
return self.__db_session.query(Tag).filter_by(key=key) | ||
|
||
def find_by_tag_id(self, tag_id): | ||
return self.__db_session.query(Tag).filter_by(tag_id=tag_id) | ||
|
||
def find_by_value(self, value): | ||
return self.__db_session.query(Tag).filter_by(value=value) | ||
|
||
def find_by_key_value(self, key, value): | ||
return self.__db_session.query(Tag).filter_by(key=key, value=value) | ||
|
||
def update_by_font_id(self, tag_id, update_data): | ||
self.find_by_tag_id(tag_id).update(update_data) | ||
self.__db_session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters