forked from AdaGold/task-list-api
-
Notifications
You must be signed in to change notification settings - Fork 146
Snow Leopards - Aretta B. #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arettab
wants to merge
18
commits into
Ada-C18:master
Choose a base branch
from
arettab:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+758
−117
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e896aed
adds routes for task.py
arettab 1c7143d
creates validation for task creation
arettab 4e637a2
fixes the get all task function
arettab 216ba77
add sorting to read_all_task function
arettab c68c0d2
add patch route to mark complete
arettab 99b2d2b
add route to mark incomplete
arettab 64174a6
complete wave 3
arettab f9c46a3
adds slack api intergration
arettab 95a0cf1
adds slack api intergrationcommit
arettab 5af9425
adds handle_goal function
arettab 5322230
creates test for goal not found
arettab 1c66d54
adds update_task_function
arettab 8873abc
adds a route folder:
arettab 9bb7bf4
finishes wave 5 and most of wave 6
arettab 60f7977
repairs delete_goal test
arettab ec29f1f
adds Procfile
arettab f33ab07
changes requirements.txt
arettab 1001c6e
changes requirements.txt
arettab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
web: gunicorn 'app:create_app()' |
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,168 @@ | ||
import datetime | ||
import os | ||
|
||
import requests | ||
from dotenv import load_dotenv | ||
from flask import Blueprint, abort, jsonify, make_response, request | ||
|
||
from app import db | ||
from app.models.goal import Goal | ||
from app.models.task import Task | ||
|
||
bp = Blueprint("goal", __name__, url_prefix="/goals") | ||
|
||
def validate_model(cls, model_id): | ||
try: | ||
model_id = int(model_id) | ||
except: | ||
abort(make_response( | ||
{"message": f"{cls.__name__} {model_id} invalid"}, 400)) | ||
|
||
model = cls.query.get(model_id) | ||
if not model: | ||
abort(make_response( | ||
{'message': f'{cls.__name__} {model_id} not found'}, 404)) | ||
|
||
return model | ||
|
||
def validate_title(cls, data): | ||
try: | ||
new_cls = cls(title = data["title"]) | ||
except: | ||
abort(make_response( | ||
{"details": "Invalid data"}, 400)) | ||
return new_cls | ||
|
||
|
||
|
||
@bp.route("", methods=["POST"]) | ||
def create_goal(): | ||
request_body = request.get_json() | ||
new_goal = validate_title(Goal,request_body) | ||
|
||
db.session.add(new_goal) | ||
db.session.commit() | ||
|
||
return make_response(jsonify({ | ||
"goal": { | ||
"id":new_goal.goal_id, | ||
"title": new_goal.title, | ||
}}) | ||
, 201) | ||
|
||
@bp.route("", methods=["GET"]) | ||
def read_all_goals(): | ||
goals = Goal.query.all() | ||
|
||
get_response = [] | ||
|
||
for goal in goals: | ||
get_response.append(dict( | ||
id=goal.goal_id, | ||
title=goal.title | ||
)) | ||
|
||
return make_response(jsonify(get_response), 200) | ||
|
||
@bp.route("/<goal_id>", methods=["GET"]) | ||
def handle_task(goal_id): | ||
|
||
goal = validate_model(Goal,goal_id) | ||
|
||
|
||
get_response ={ | ||
f"goal": { | ||
"id": goal.goal_id, | ||
"title": goal.title | ||
}} | ||
|
||
return get_response, 200 | ||
|
||
@bp.route("/<goal_id>", methods=["PUT"]) | ||
def update_goal(goal_id): | ||
goal = validate_model(Goal, goal_id) | ||
|
||
request_body = request.get_json() | ||
|
||
goal.title = request_body["title"] | ||
|
||
db.session.commit() | ||
|
||
update_response = { | ||
"goal": { | ||
"id": goal.goal_id, | ||
"title": goal.title | ||
} | ||
} | ||
|
||
return make_response(update_response), 200 | ||
|
||
@bp.route("/<goal_id>", methods=["DELETE"]) | ||
def delete_goal(goal_id): | ||
goal = validate_model(Goal, goal_id) | ||
|
||
db.session.delete(goal) | ||
db.session.commit() | ||
|
||
return make_response(jsonify({ | ||
"details": f'Goal {goal.goal_id} "{goal.title}" successfully deleted' | ||
})), 200 | ||
|
||
|
||
@bp.route("/<goal_id>/tasks", methods=["POST"]) | ||
def post_task_ids_to_goal(goal_id): | ||
request_body = request.get_json() | ||
goal = validate_model(Goal,goal_id) | ||
|
||
for task_id in request_body["task_ids"]: | ||
task = validate_model(Task, task_id) | ||
goal.tasks.append(task) | ||
|
||
db.session.add(goal) | ||
db.session.commit() | ||
|
||
return make_response({ | ||
"id": goal.goal_id, | ||
"task_ids": request_body["task_ids"] | ||
}), 200 | ||
|
||
@bp.route("/<goal_id>/tasks", methods=["GET"]) | ||
def get_tasks_for_specific_goal(goal_id): | ||
request_body = request.get_json | ||
goal = validate_model(Goal, goal_id) | ||
tasks = goal.tasks | ||
|
||
task_response = [] | ||
|
||
for task in tasks: | ||
task = { | ||
"id": task.task_id, | ||
"goal_id": goal.goal_id, | ||
"title": f"{task.title}", | ||
"description": f"{task.description}", | ||
"is_complete": bool(task.completed_at) | ||
} | ||
task_response.append(task) | ||
|
||
|
||
return make_response({ | ||
"id": goal.goal_id, | ||
"title": f"{goal.title}", | ||
"tasks": task_response | ||
}), 200 | ||
|
||
@bp.route("/tasks/<task_id>", methods=["GET"]) | ||
def get_task(task_id): | ||
|
||
task = validate_model(Task, task_id) | ||
|
||
return make_response({ | ||
"task": { | ||
"id": task_id, | ||
"goal_id": task.goal_id, | ||
"title": f"{task.title}", | ||
"description": f"{task.description}", | ||
"is_complete": bool(task.completed_at) | ||
} | ||
}), 200 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job handling this one!