|
4 | 4 |
|
5 | 5 | import api.queue.controller as controller |
6 | 6 | from api.auth.controller import get_user |
7 | | -from api.queue.controller import remove_from_queue_without_visit |
| 7 | +from api.queue.controller import remove_from_queue_without_visit, get_tas_visit |
8 | 8 | from api.roster.controller import min_level |
9 | 9 | from api.database.db import db |
10 | 10 |
|
@@ -121,23 +121,73 @@ def restore_visit(): |
121 | 121 |
|
122 | 122 | user_id = user["user_id"] |
123 | 123 |
|
| 124 | + return get_tas_visit(user_id) |
| 125 | + |
| 126 | +@blueprint.route("/active-visits", methods=["GET"]) |
| 127 | +@min_level('ta') |
| 128 | +def get_active_visits(): |
124 | 129 | in_progress = db.get_in_progress_visits() |
125 | | - in_progress = list(filter(lambda v: v["ta_id"] == user_id, in_progress)) |
126 | 130 |
|
127 | | - if len(in_progress) == 0: |
128 | | - return {"message": "You have no in-progress visits."}, 404 |
| 131 | + visits = [] |
| 132 | + |
| 133 | + for visit in in_progress: |
| 134 | + student = db.lookup_identifier(visit["student_id"]) |
| 135 | + |
| 136 | + if visit["ta_id"] is not None: |
| 137 | + ta = db.lookup_identifier(visit["ta_id"]) |
| 138 | + ta_name = ta["preferred_name"] |
| 139 | + else: |
| 140 | + ta_name = None |
| 141 | + |
| 142 | + visits.append({ |
| 143 | + "student_id": visit["student_id"], |
| 144 | + "student_username": student["ubit"], |
| 145 | + "student_name": student["preferred_name"], |
| 146 | + "visitID": visit["visit_id"], |
| 147 | + "visit_reason": visit["student_visit_reason"], |
| 148 | + "ta_id": visit["ta_id"], |
| 149 | + "ta_name": ta_name |
| 150 | + }) |
| 151 | + |
| 152 | +@blueprint.route("/visits/<id>", methods=["GET"]) |
| 153 | +@min_level('instructor') |
| 154 | +def get_visit(visit_id): |
| 155 | + """ |
| 156 | + Retrieve all information about the specified visit. |
| 157 | +
|
| 158 | + """ |
| 159 | + |
| 160 | + pass |
| 161 | + |
| 162 | +@blueprint.route("/steal-visit/<id>", methods=["PATCH"]) |
| 163 | +@min_level('ta') |
| 164 | +def steal_visit(visit_id): |
| 165 | + """ |
| 166 | + Replace the TA associated with the visit with the TA who sent |
| 167 | + the request. Returns all information about the visit being stolen. |
| 168 | +
|
| 169 | + Does not work on visits that are not in progress, or if the TA |
| 170 | + has an active visit. |
| 171 | +
|
| 172 | + """ |
| 173 | + |
| 174 | + pass |
| 175 | + |
| 176 | +@blueprint.route("/abandon-visit", methods=["PATCH"]) |
| 177 | +@min_level('ta') |
| 178 | +def abandon_visit(): |
| 179 | + """ |
| 180 | + Abandon the visit associated with the TA who sent the request. |
| 181 | + Does not end the visit. |
| 182 | +
|
| 183 | + Returns an error if the TA isn't in an active visit. Future retrievals |
| 184 | + of this visit should return "None" as the TA's ID and name. |
| 185 | +
|
| 186 | +
|
| 187 | + """ |
| 188 | + pass |
129 | 189 |
|
130 | | - visit = in_progress[0] |
131 | | - student = db.lookup_identifier(visit["student_id"]) |
132 | 190 |
|
133 | | - return { |
134 | | - "id": visit["student_id"], |
135 | | - "username": student["ubit"], |
136 | | - "pn": student["person_num"], |
137 | | - "preferred_name": student["preferred_name"], |
138 | | - "visitID": visit["visit_id"], |
139 | | - "visit_reason": visit["student_visit_reason"] |
140 | | - } |
141 | 191 |
|
142 | 192 | @blueprint.route("/help-a-student", methods=["POST"]) |
143 | 193 | @min_level("ta") |
|
0 commit comments