Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Add "my batch" filter
Browse files Browse the repository at this point in the history
Issue #3 add filters
  • Loading branch information
jasonaowen committed Feb 21, 2017
1 parent 776871e commit 028a854
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ def get_random_overlapping(cursor, current_user):
[current_user])
return cursor.fetchone()

def get_random_in_batch(cursor, current_user):
"""Find a random person from the database that is in (one of) the current
user's batch(es)."""
cursor.execute("""WITH user_batch AS (
SELECT batch_id
FROM stints
WHERE person_id = %s
)
SELECT people.person_id,
people.first_name,
people.middle_name,
people.last_name,
people.image_url
FROM people
INNER JOIN stints
ON people.person_id = stints.person_id
INNER JOIN user_batch
ON stints.batch_id = user_batch.batch_id
ORDER BY random()
LIMIT 1""",
[current_user])
return cursor.fetchone()

@app.route('/api/people/random')
@needs_authorization
def get_random_person():
Expand All @@ -145,6 +168,8 @@ def get_random_person():
random_person = get_random_person_from_all_batches(cursor, current_user)
elif random_person_filter == 'overlapping':
random_person = get_random_overlapping(cursor, current_user)
elif random_person_filter == 'my_batch':
random_person = get_random_in_batch(cursor, current_user)
else:
return (jsonify({
'message': 'Unrecognized filter',
Expand Down
1 change: 1 addition & 0 deletions src/components/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Next extends Component {
<select name="filter" ref={input => this._selection = input}>
<option value="all">Everyone</option>
<option value="overlapping">At RC with me</option>
<option value="my_batch">My batch</option>
</select>
<input type="submit" value="Next!" label="Next!" />
</form>
Expand Down

0 comments on commit 028a854

Please sign in to comment.