|
7 | 7 | from packet.context_processors import get_rit_name
|
8 | 8 | from packet.mail import send_report_mail
|
9 | 9 | from packet.utils import before_request, packet_auth, notify_slack
|
10 |
| -from packet.models import Packet, MiscSignature, NotificationSubscription |
| 10 | +from packet.models import Packet, MiscSignature, NotificationSubscription, Freshman |
11 | 11 | from packet.notifications import packet_signed_notification, packet_100_percent_notification
|
12 | 12 |
|
13 | 13 |
|
| 14 | +@app.route("/api/v1/packets/<username>", methods=["GET"]) |
| 15 | +@packet_auth |
| 16 | +def get_packets_by_user(username: str) -> dict: |
| 17 | + """ |
| 18 | + Return a dictionary of packets for a freshman by username, giving packet start and end date by packet id |
| 19 | + """ |
| 20 | + frosh = Freshman.by_username(username) |
| 21 | + |
| 22 | + return {packet.id: { |
| 23 | + 'start': packet.start, |
| 24 | + 'end': packet.end, |
| 25 | + } for packet in frosh.packets} |
| 26 | + |
| 27 | + |
| 28 | +@app.route("/api/v1/packets/<username>/newest", methods=["GET"]) |
| 29 | +@packet_auth |
| 30 | +def get_newest_packet_by_user(username: str) -> dict: |
| 31 | + """ |
| 32 | + Return a user's newest packet |
| 33 | + """ |
| 34 | + frosh = Freshman.by_username(username) |
| 35 | + |
| 36 | + packet = frosh.packets[-1] |
| 37 | + |
| 38 | + return { |
| 39 | + packet.id: { |
| 40 | + 'start': packet.start, |
| 41 | + 'end': packet.end, |
| 42 | + 'required': vars(packet.signatures_required()), |
| 43 | + 'received': vars(packet.signatures_received()), |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | +@app.route("/api/v1/packet/<packet_id>", methods=["GET"]) |
| 49 | +@packet_auth |
| 50 | +def get_packet_by_id(packet_id: int) -> dict: |
| 51 | + """ |
| 52 | + Return the scores of the packet in question |
| 53 | + """ |
| 54 | + |
| 55 | + packet = Packet.by_id(packet_id) |
| 56 | + |
| 57 | + return { |
| 58 | + 'required': vars(packet.signatures_required()), |
| 59 | + 'received': vars(packet.signatures_received()), |
| 60 | + } |
| 61 | + |
14 | 62 | @app.route("/api/v1/sign/<packet_id>/", methods=["POST"])
|
15 | 63 | @packet_auth
|
16 | 64 | @before_request
|
|
0 commit comments