Skip to content
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

Resolve issues #186-188, modified prod.config file #190

Merged
merged 30 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
260f27e
Fix user_read response
js324 Dec 7, 2022
0018ebe
Merge branch 'master' into develop
js324 Dec 7, 2022
28b8177
solved the timestamp issue, which adds a timestamp whenever the user …
ethxng Aug 18, 2023
4d64f07
downgraded urllib3 version bc newer version isn't compatible with oth…
ethxng Aug 18, 2023
06cc670
modified test_validate.py to comply with the same user and password a…
ethxng Aug 19, 2023
681743b
changed up the paramter of the call 'update' to satisfy Travis CI
ethxng Aug 19, 2023
c071a82
added pylint disable option for tests to pass
ethxng Aug 19, 2023
db1f88e
solved the timestamp issue (#174)
ethxng Aug 22, 2023
c34ff39
set up the new skeleton endpoint
ethxng Aug 23, 2023
af460f0
update /statistics method from GET to POST
ethxng Aug 25, 2023
fa5d2c0
added logic code
ethxng Aug 31, 2023
baaf92b
test comment
ethxng Aug 31, 2023
b90c65d
Merge branch 'develop' of https://github.com/HackRU/lcs into develop
ethxng Aug 31, 2023
ef94297
wrote tests for /statistics endpoint and fixed buggy codes from prev …
ethxng Sep 1, 2023
51ee60c
Merge branch 'develop' into ethan_statsForHack
ethxng Sep 1, 2023
2ca1e50
test trial run
ethxng Sep 1, 2023
176939f
fixed test for travis build to pass
ethxng Sep 1, 2023
1444197
New endpoint that would return the stats for a hackathon (#176)
ethxng Sep 1, 2023
31d4b64
tests
ethxng Sep 1, 2023
8662a9e
Merge branch 'master' into develop
ethxng Sep 1, 2023
098d7db
Resolve issues #179-182 for Spring 24 hackathon
ethxng Feb 21, 2024
c6852ec
Merge branch 'master' into develop
ethxng Feb 21, 2024
67dbb1a
fix tests errors in /tests
ethxng Feb 24, 2024
252b59a
resolve test errors part2
ethxng Feb 24, 2024
2b57723
Merge branch 'master' into develop
ethxng Feb 24, 2024
db7a5e7
Ethan hack spr24 part2 (#189)
ethxng Mar 19, 2024
b9cfe3a
add env variables to dev and prod config
ethxng Mar 19, 2024
1f3db42
add env variables to dev and prod config part2
ethxng Mar 19, 2024
28ae515
fix dev config file
ethxng Mar 19, 2024
b45772c
Merge branch 'master' into develop
ethxng Mar 19, 2024
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
5 changes: 4 additions & 1 deletion deployment/config.dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
DB_COLLECTIONS = {
"users": "users",
"magic links": "magicLinks",
"slack messages": "slackMessages"
"slack messages": "slackMessages",
"houses": "houses",
"teams": "teams"
}

SPARKPOST_KEY = os.getenv("DEVELOP_SPARKPOST_KEY", "")
Expand Down Expand Up @@ -58,6 +60,7 @@ class GOOGLE_CAL:
RESUME_BUCKET = os.getenv("DEVELOP_RESUME_BUCKET", "")
WAIVER_BUCKET = os.getenv("DEVELOP_WAIVER_BUCKET", "")
VACCINE_BUCKET = os.getenv("DEVELOP_VACCINE_BUCKET", "")
SPONSOR_BUCKET = os.getenv("DEVELOP_SPONSOR_BUCKET", "")
# Json webtoken
JWT_SECRET = os.getenv("DEVELOP_JWT_SECRET", "")
JWT_ALGO = os.getenv("DEVELOP_JWT_ALGO", "")
5 changes: 4 additions & 1 deletion deployment/config.prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
DB_COLLECTIONS = {
"users": "users",
"magic links": "magicLinks",
"slack messages": "slackMessages"
"slack messages": "slackMessages",
"houses": "houses",
"teams": "teams"
}

SPARKPOST_KEY = os.getenv("PRODUCTION_SPARKPOST_KEY", "")
Expand Down Expand Up @@ -61,6 +63,7 @@ class GOOGLE_CAL:
RESUME_BUCKET = os.getenv("PRODUCTION_RESUME_BUCKET", "")
WAIVER_BUCKET = os.getenv("PRODUCTION_WAIVER_BUCKET", "")
VACCINE_BUCKET = os.getenv("PRODUCTION_VACCINE_BUCKET", "")
SPONSOR_BUCKET = os.getenv("PRODUCTION_SPONSOR_BUCKET", "")
# Json webtoken
JWT_SECRET = os.getenv("PRODUCTION_JWT_SECRET", "")
JWT_ALGO = os.getenv("PRODUCTION_JWT_ALGO", "")
12 changes: 12 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,15 @@ functions:
request:
template:
application/json: '$input.body'

get-house-points:
handler: src/houses.get_all_points
events:
- http:
path: get-house_points
integration: lambda
method: get
cors: true
request:
template:
application/json: '$input.body'
18 changes: 18 additions & 0 deletions src/houses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from src.util import coll

def get_all_points(event, context):

# get house collection
houses = coll('houses')

data = houses.find({})

results = {
"status": 200,
"houses": {}
}

for doc in data:
results['houses'][doc['name']] = doc['points']

return results
12 changes: 9 additions & 3 deletions src/qrscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def qr_match(event, context, user=None):
'token': {'type': 'string'},
'qr': {'type': 'string'},
'event': {'type': 'string'},
'point': {'type': 'integer'},
'again': {'type': 'boolean'}
},
'required': ['token', 'qr', 'event']
Expand All @@ -55,23 +56,28 @@ def attend_event(aws_event, context, user=None):
qr = aws_event['qr']
event = aws_event['event']
again = aws_event.get('again', False)
point = aws_event.get('point', 0)

# in case user accidentally put a negative number
if point < 0:
point = 0

def attend(user):
# if the user has already attended the event and is not an event that can be re-attended, complain
if not again and user['day_of'].get(event, 0) > 0:
return {'statusCode': 402, 'body': 'user already checked into event'}
# update the user data to reflect event attendance by incrementing the count of the event by 1
# update the user data to reflect event attendance by incrementing the count of the event by the variable 'point'
new_user = users.find_one_and_update({'email': user['email']},
{
'$inc': {'day_of.' + event: 1},
'$push': {'day_of.timestamps.' + event: datetime.utcnow()}
},
return_document=pymongo.ReturnDocument.AFTER)

# update the user's house points to reflect event attendance by incrementing it by 1
# update the user's house points to reflect event attendance by incrementing it by the variable 'point'
update_points = houses.find_one_and_update({"name": new_user['house']},
{
'$inc': {'points': 1}
'$inc': {'points': point}
},
return_document=pymongo.ReturnDocument.AFTER)

Expand Down
87 changes: 52 additions & 35 deletions src/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
from src.util import coll
import json

# the request body will include:
# 1. token (for auth)
# 2. team_leader: email (string)
# 3. team_members: [strings]
# the request body will require:
# 1. team_leader: email (string)
# 2. team_members: [strings]

# procedure:
# 1. check to see if team_leader is teamless (must be true before proceed)
# 2. check to see if ALL team_members are teamless (must be true before proceed)
# 3. create a new team in collection "Team", assign a team_id by: getting the total no. of teams in collection + 1
# 4. assign team leader and team_members inside Team object (maybe?)
# 1. Team leader and team members need to be distinct
# 2. check to see if team_leader exists and is teamless (must be true before proceed)
# 3. check to see if ALL team_members exist and are teamless (must be true before proceed)
# 4. create a new team in collection "Team", assign a team_id by: getting the total no. of teams in collection + 1
# 5. Go find each user, including team leader and member, attach team_id into their user profile

@ensure_schema({
"type": "object",
"properties": {
"token": {"type": "string"},
"team_leader": {"type": "string"},
"team_members": {"type": "array"}
},
"required": ["token", "team_leader", "team_members"]
"required": ["team_leader", "team_members"]
})
def make_teams(event, context):
team_leader_email = event['team_leader']
Expand All @@ -31,40 +29,59 @@ def make_teams(event, context):
users = coll('users')
teams = coll('teams')

# check to see if team leader is teamless (consider changing to checking from teams instead of using users)
# Team leader and team members need to be distinct
if team_leader_email in team_members_emails:
return {"status": 400, "error": "team leader email is the same as one of the members"}

# team members (array of strings) need to be distinct among themselves
if len(team_members_emails) != len(set(team_members_emails)):
return {"status": 400, "error": "team member emails need to be distinct"}


# check to see if team leader exists and is teamless
team_leader = users.find_one({"email": team_leader_email})

if "team_id" in team_leader and team_leader['team_id'] > 0:
return {"status": 400, "body": "team leader already has a team"}
if team_leader is not None:
if "team_id" in team_leader and team_leader['team_id'] > 0:
return {"status": 400, "error": "team leader already has a team"}
else:
return {"status": 400, "error": "team leader email does not exist"}

# check to see if all team members are teamless
# check to see if all team members exist and are teamless
for member_email in team_members_emails:
team_member = users.find_one({"email": member_email})
if "team_id" in team_member and team_member['team_id'] > 0:
return {"status": 400, "bodys": "team member already has a team"}
if team_member is not None:
if "team_id" in team_member and team_member['team_id'] > 0:
return {"status": 400, "error": "team member already has a team"}
else:
return {"status": 400, "error": "this team member email does not exist", "email": member_email}

# create a team
teams_count = teams.count_documents({})
new_team = teams.insert_one({
"team_leader": team_leader_email,
"team_members": team_members_emails,
"team_id": teams_count + 1
})
try:
teams_count = teams.count_documents({})
new_team = teams.insert_one({
"team_leader": team_leader_email,
"team_members": team_members_emails,
"team_id": teams_count + 1
})

# assigning team_id to team leader and members in Users collection
team_id = teams_count + 1
print(team_id)
update_team_leader_id = users.find_one_and_update({"email": team_leader_email},
{
'$set': {'team_id': team_id}
})

for member_email in team_members_emails:
update_team_member_id = users.find_one_and_update({"email": member_email},
{
'$set': {'team_id': team_id}
})
# assigning team_id to team leader and members in Users collection
team_id = teams_count + 1

update_team_leader_id = users.find_one_and_update({"email": team_leader_email},
{
'$set': {'team_id': team_id}
})

for member_email in team_members_emails:
update_team_member_id = users.find_one_and_update({"email": member_email},
{
'$set': {'team_id': team_id}
})
except Exception as e:
return {"status": 500, 'error': e}

# success response
return {
"status": 200,
"body": {
Expand Down