-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from opportunity-hack/develop
Hearts API Endpoint
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 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,36 @@ | ||
from model.user import User | ||
from services import hearts_service | ||
from common.utils import safe_get_env_var | ||
from common.auth import auth, auth_user | ||
|
||
from flask import ( | ||
Blueprint, | ||
request, | ||
g | ||
) | ||
|
||
bp_name = 'api-hearts' | ||
bp_url_prefix = '/api/hearts' | ||
bp = Blueprint(bp_name, __name__, url_prefix=bp_url_prefix) | ||
|
||
|
||
# Used to provide profile details - user must be logged in | ||
@bp.route("/", methods=["GET"]) | ||
@auth.require_user | ||
def get_hearts(): | ||
print("get_hearts") | ||
res = hearts_service.get_hearts_for_all_users() | ||
print(f"res: {res}") | ||
return {"hearts": res} | ||
|
||
@bp.route("/", methods=["POST"]) | ||
#@auth.require_user | ||
def save_hearts(): | ||
print("save_hearts") | ||
if auth_user and auth_user.user_id: | ||
print(f"request.get_json(): {request.get_json()}") | ||
# u: User | None = users_service.save_profile_metadata(auth_user.user_id, request.get_json()) | ||
#return vars(u) if u is not None else None | ||
return "Biuttera" | ||
else: | ||
return "Biutter" |
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,33 @@ | ||
from db.db import fetch_users | ||
|
||
|
||
def get_hearts_for_all_users(): | ||
users = fetch_users() | ||
|
||
result = [] | ||
|
||
# Result should have slackUsername, totalHearts, heartTypes (how or what) and heartCount | ||
# This is all within the "history" key for each user | ||
# User is type model.user.User | ||
for user in users: | ||
total_hearts = 0 | ||
|
||
if user.history: | ||
print(f"User history: {user.history}") | ||
''' | ||
Example of user history: | ||
{'what': {'unit_test_coverage': 0, 'documentation': 0.5, 'productionalized_projects': 0.5, 'unit_test_writing': 0, 'observability': 0, 'code_quality': 0.5, 'requirements_gathering': 0.5, 'design_architecture': 0.5}, 'how': {'iterations_of_code_pushed_to_production': 1.5, 'code_reliability': 2, 'standups_completed': 2.5, 'customer_driven_innovation_and_design_thinking': 1}} | ||
''' | ||
# Result should have slackUsername, totalHearts, heartTypes (how or what) and heartCount | ||
# Count the total hearts | ||
for key in user.history: | ||
for subkey in user.history[key]: | ||
total_hearts += user.history[key][subkey] | ||
|
||
result.append({ | ||
"slackUsername": user.name, | ||
"totalHearts": total_hearts, | ||
"heartTypes": list(user.history.keys()), | ||
"history": user.history | ||
}) | ||
return result |