-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Anurag 1:1 meeting * Meeting notes for 1:1 05-12-2020 * Updated frontend notes * Create 5-13-20-Jason-onboarding.md * 5-13-20-Jason-onboarding * Delete 5-13-20-Jason-onboarding.md * Update 5-13-20-Jason-onboarding.md * Update 5-13-20-Jason-onboarding.md * Updated folders to not break windows laptops * Initial commit * Added Tag model * Added emoji field * Added emoji field to Meta class * Implemented create_tag function * Implemented CreateTag * Implemented Update Tag function * Implemented FetchTags * Implemented TagFollowers * Removed comment * Added tag * Implemented Tag Routes, Models, Schemas, Decorators & Utils * Fixed typo for submission_guidelines --> submission_guideline * Updated comments * Added comment Detailed comment that explains many to many relationship to keep track of user id and tag id * Modified backref to back_populates for user and tag models * Added validate_form_data decorator to ensure sanitized data * Removed unused code * Updated relationships in Tag and User model * updated * Fixed name of typo in validate_tag_form decorator * Updated * Updated * Added toasted marshmallow.jit
- Loading branch information
Showing
9 changed files
with
295 additions
and
3 deletions.
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
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,39 @@ | ||
from ..models import Tag | ||
from functools import wraps | ||
from ..tags.schemas import tag_form_schema | ||
from flask import request | ||
|
||
|
||
# Decorator to check if a tag exists | ||
def tag_exists(f): | ||
|
||
@wraps(f) | ||
def wrap(*args, **kwargs): | ||
tag = Tag.query.get(kwargs['tag_id']) | ||
|
||
if tag: | ||
return f(*args, **kwargs) | ||
else: | ||
return { | ||
"message": "Tag does not exist" | ||
}, 404 | ||
|
||
return wrap | ||
|
||
|
||
# Decorator to check if data in form is valid | ||
def validate_tag_form(f): | ||
|
||
@wraps(f) | ||
def wrap(*args, **kwargs): | ||
form_data = request.get_json() | ||
errors = tag_form_schema.validate(form_data) | ||
|
||
if errors: | ||
return { | ||
"message": "Unable to create tag. Please enter all required form inputs." | ||
}, 422 | ||
else: | ||
return f(*args, **kwargs) | ||
|
||
return wrap |
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,95 @@ | ||
from .. import api, db | ||
from ..models import Tag, User | ||
from ..tags.decorators import tag_exists, validate_tag_form | ||
from ..tags.schemas import tag_schema, tags_schema, tag_form_schema | ||
from ..tags.utils import create_tag, update_tag | ||
from flask import Blueprint, request, session | ||
from flask_restful import Resource | ||
|
||
# Blueprint for tags | ||
tag_bp = Blueprint("tags", __name__) | ||
|
||
|
||
# Class to fetch and create tag | ||
class Tags(Resource): | ||
# Create Tag | ||
@validate_tag_form | ||
def post(self): | ||
form_data = request.get_json() | ||
tag = create_tag(form_data) | ||
|
||
db.session.add(tag) | ||
db.session.commit() | ||
|
||
return { | ||
"message": "Tag sucessfully created" | ||
}, 201 | ||
|
||
|
||
# Fetch Tags | ||
def get(self): | ||
tag = Tag.query.limit(15).all() | ||
|
||
if len(tag) != 0: | ||
return tags_schema.dump(tag) | ||
else: | ||
return { | ||
"message": "No Tags" | ||
}, 404 | ||
|
||
|
||
# Class for updating, deleting & fetching tags | ||
class TagCRUD(Resource): | ||
# Update specific tag | ||
@validate_tag_form | ||
@tag_exists | ||
def put(self, tag_id): | ||
tag = Tag.query.get(tag_id) | ||
form_data = request.get_json() | ||
update_tag(tag, form_data) | ||
|
||
db.session.commit() | ||
|
||
return { | ||
"message": "Tag successfully updated" | ||
}, 200 | ||
|
||
# Fetch specific tag | ||
@tag_exists | ||
def get(self, tag_id): | ||
tag = Tag.query.get(tag_id) | ||
|
||
return tag_schema.dump(tag) | ||
|
||
# Delete specific tag | ||
@tag_exists | ||
def delete(self, tag_id): | ||
tag = Tag.query.get(tag_id) | ||
|
||
db.session.delete(tag) | ||
db.session.commit() | ||
|
||
return { | ||
"message": "Tag successfully deleted" | ||
}, 200 | ||
|
||
|
||
# Class to update followers | ||
class TagFollowers(Resource): | ||
def put(self, tag_id): | ||
user_data = session["profile"] | ||
user = User.query.get(user_data["user_id"]) | ||
tag = Tag.query.get(tag_id) | ||
|
||
tag.users.append(user) | ||
db.session.commit() | ||
|
||
return { | ||
"message": user.name + "is now following" + tag.name | ||
}, 200 | ||
|
||
|
||
# # Creates the routes for the classes | ||
api.add_resource(Tags, "/api/tags") | ||
api.add_resource(TagCRUD, "/api/tags/<int:tag_id>") | ||
api.add_resource(TagFollowers, "/api/tags/<int:tag_id>/followers") |
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,28 @@ | ||
from marshmallow import Schema, fields | ||
import toastedmarshmallow | ||
|
||
|
||
# Validates tag form | ||
class TagFormSchema(Schema): | ||
name = fields.Str(required=True) | ||
summary = fields.Str(required=True) | ||
submission_guideline = fields.Str(required=True) | ||
about = fields.Str(required=True) | ||
emoji = fields.Str(required=True) | ||
|
||
class Meta: | ||
# Fields to show when sending data | ||
fields = ("name", "summary", "submission_guideline", "about", "emoji") | ||
ordered = True | ||
|
||
|
||
class TagSchema(Schema): | ||
id = fields.Int(required=True) | ||
|
||
|
||
tag_form_schema = TagFormSchema() | ||
tag_schema = TagSchema() | ||
tags_schema = TagSchema(many=True) | ||
tag_form_schema.jit = toastedmarshmallow.Jit | ||
tag_schema.jit = toastedmarshmallow.Jit | ||
tags_schema.jit = toastedmarshmallow.Jit |
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,24 @@ | ||
from ..models import Tag | ||
|
||
|
||
# Function to create a tag | ||
def create_tag(form_data): | ||
tag = Tag(name=form_data["name"], | ||
summary=form_data["summary"], | ||
submission_guideline=form_data["submission_guideline"], | ||
about=form_data["about"], | ||
emoji=form_data["emoji"] | ||
) | ||
|
||
return tag | ||
|
||
|
||
# Function to update a tag | ||
def update_tag(tag, form_data): | ||
tag.name = form_data["name"] | ||
tag.summary = form_data["summary"] | ||
tag.submission_guideline = form_data["submission_guideline"] | ||
tag.about = form_data["about"] | ||
tag.emoji = form_data["emoji"] | ||
|
||
return |
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,36 @@ | ||
# Meeting Purpose | ||
Weekly meeting | ||
|
||
**Lead** | ||
Bryan | ||
|
||
**Attendees** | ||
* Anurag | ||
|
||
## Updates: | ||
*What has been completed and can be checked off* | ||
|
||
* | ||
|
||
## Discussion Points: | ||
*Ideas, feedback, concerns, plans* | ||
* Understand the overview of the onboarding procedure | ||
* Breakdown of tasks and expectations for the first week | ||
* Understand what Engineering team does | ||
Practice taking notes on Github during the 1:1 | ||
* Please give your overview feedback and express what position you are within the Engineering team! | ||
* Give onboarding feedback | ||
* | ||
|
||
## Action Plan: | ||
*Where to go next, dependencies, all deadlines* | ||
*Bryan will talk to the People team to improve the onboarding process and have them delve more into what BitProject actually represents as an organization. | ||
*Watch the remaining webinars and close this issue. | ||
|
||
## Deliverables: | ||
*Within the next (timeframe)* | ||
*Anurag will watch the webinars by Thursday and finish the onboarding checklist. | ||
|
||
Name | Assigned To | Deadline | Notes | ||
------|-------------|----------|------ | ||
Name | @ | May 20th | Explanation |
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,34 @@ | ||
# Meeting Purpose | ||
|
||
**Lead** | ||
Bryan Wong | ||
|
||
**Attendees** | ||
* Zexing(Jason) Fang | ||
|
||
## Updates: | ||
*What has been completed and can be checked off* | ||
|
||
* Jason is almost done with onboarding checklist | ||
|
||
## Discussion Points: | ||
*Ideas, feedback, concerns, plans* | ||
* Understand the overview of the onboarding procedure | ||
* Breakdown of tasks and expectations for the first week | ||
* Understand what Engineering team does | ||
* Practice taking notes on Github during the 1:1 | ||
* Please give your overview feedback and express what position you are interested within the Engineering team! | ||
* Give onboarding feedback | ||
* Clear up the onboarding issue | ||
|
||
|
||
## Action Plan: | ||
*Where to go next, dependencies, all deadlines* | ||
* None. Jason finished his onboarding checklist! | ||
|
||
## Deliverables: | ||
*Within the next (timeframe)* | ||
|
||
Name | Assigned To | Deadline | Notes | ||
------|-------------|----------|------ | ||
Example 1 | @studentusername2 | Feb 30th | Explanation |
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