Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/controllers/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ def delete(self, tag_id):


class TagFollowingView(Resource):
@ jwt_required
@jwt_required
def post(self, tag_id):
current_user_id = get_jwt_identity()
tag = Tag.get_by_id(tag_id)

if not tag:
return dict(status='fail', message=f'Tag with id {tag_id} not found'), 404


existing_tag_follow = TagFollowers.find_first(
user_id=current_user_id, tag_id=tag_id)
if existing_tag_follow:
Expand All @@ -122,7 +121,7 @@ def post(self, tag_id):
message=f'You are now following tag with id {tag_id}'
), 201

@ jwt_required
@jwt_required
def get(self, tag_id):
tag = Tag.get_by_id(tag_id)
follower_schema = UserIndexSchema(many=True)
Expand All @@ -138,7 +137,7 @@ def get(self, tag_id):
data=dict(followers=json.loads(users_data))
), 200

@ jwt_required
@jwt_required
def delete(self, tag_id):
current_user_id = get_jwt_identity()
tag = Tag.get_by_id(tag_id)
Expand Down
4 changes: 3 additions & 1 deletion app/models/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class Tag(ModelMixin):
projects = db.relationship("ProjectTag", back_populates="tag")
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
followers = db.relationship('TagFollowers', back_populates='tag')
documentation_url = db.Column(db.String, nullable=True)
official_url = db.Column(db.String, nullable=True)
github_link = db.Column(db.String, nullable=True)

def __repr__(self):
return f"<Tag {self.name}>"



class ProjectTag(ModelMixin):
__tablename__ = "project_tag"

Expand Down
3 changes: 3 additions & 0 deletions app/schemas/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TagSchema(Schema):
date_created = fields.Date(dump_only=True)
projects_count = fields.Method("get_projects_count", dump_only=True)
is_following = fields.Method("get_is_following", dump_only=True)
documentation_url = fields.String(allow_none=True)
official_url = fields.String(allow_none=True)
github_link = fields.String(allow_none=True)

def get_projects_count(self, obj):
return len(obj.projects)
Expand Down