Skip to content

Commit

Permalink
Pushing hotel requests to uber in realtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Nov 11, 2024
1 parent 96e265f commit 5bb3f57
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
4 changes: 4 additions & 0 deletions backend/tuber/api/hotels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
from tuber.api.util import *
from .room_matcher import rematch_hotel_block, clear_hotel_block
from .uber import export_requests
import time

@app.route("/api/event/<int:event>/hotel/<int:hotel_block>/room/<int:room_id>/remove_roommates", methods=["POST"])
Expand Down Expand Up @@ -554,7 +555,10 @@ def hotel_request_single_api(event, request_id):
requested_night = RoomNightRequest(
event=event, badge=hotel_request.badge, requested=room_night_request['requested'], room_night=room_night_request['id'])
db.add(requested_night)

db.commit()

export_requests(event, [hotel_request,])
return "null", 200


Expand Down
55 changes: 54 additions & 1 deletion backend/tuber/api/uber.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def export_rooms(event):
badges = {x.id: x for x in badges}

hrr = db.query(HotelRoomRequest).filter(HotelRoomRequest.event == event).all()
#hrr = get(f"{BASE_URL}/hotel_room_request?full=true&deep=true")
hrr = {x.badge: x for x in hrr}
reqs = {}

Expand Down Expand Up @@ -177,6 +176,60 @@ def export_rooms(event):
db.commit()
return "null", 200

def export_requests(event, hotel_room_requests):
event_obj = db.query(Event).filter(Event.id == event).one()
headers = {
'X-Auth-Token': event_obj.uber_apikey
}

room_nights = db.query(HotelRoomNight).filter(HotelRoomNight.event == event).all()
uber_room_nights = get_nights(event_obj.uber_url, headers)
room_nights_lookup = {}
for room_night in room_nights:
if room_night.date in uber_room_nights.keys():
room_nights_lookup[room_night['id']
] = uber_room_nights[room_night['date']]
else:
print(f"Could not find uber entry for {room_night['name']}")

badges = db.query(Badge).filter(Badge.event == event).all()

badges = {x.id: x for x in badges}

hrr = {x.badge: x for x in hotel_room_requests}

for idx, badge in enumerate(hrr.keys()):
g.progress(idx / len(hrr), status=f"Exporting Request {badge.public_name}")
req = hrr[badge]
if req.declined:
continue
requested_nights = [x.room_night
for x in req.room_night_requests if x.requested]
if not requested_nights:
continue
req_nights = [room_nights_lookup[x]
for x in requested_nights if x in room_nights_lookup]
request = create_request(
event_obj.uber_url,
headers,
hrr[badge].uber_id,
attendee_id=badges[badge].uber_id,
special_needs=hrr[badge].notes,
approved=True,
nights=req_nights
)
hrr.uber_id = request['id']
db.add(hrr)

db.commit()
return "null", 200

@app.route("/api/event/<int:event>/uber/export_requests", methods=["POST"])
def export_requests_api(event):
hrr = db.query(HotelRoomRequest).filter(HotelRoomRequest.event == event).all()
export_requests(event, hrr)
return "null", 200

def create_attendee(uber_model, event, hotel_eligible=True):
staff_badge_type = db.query(BadgeType).filter(BadgeType.name == "Staff", BadgeType.event == event).one_or_none()
if not staff_badge_type:
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/views/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Button @click="import_shifts" label="Import Shifts"></Button><br /><br />
<Button @click="sync_attendees" label="Sync Attendees"></Button><br /><br />
<Button @click="export_rooms" label="Export Rooms to Uber"></Button><br /><br />
<Button @click="export_requests" label="Export Hotel Requests to Uber"></Button><br /><br />
<Progress ref="progress" />
</div>
</template>
Expand Down Expand Up @@ -38,12 +39,12 @@ export default {
}
},
async sync_attendees () {
try {
//try {
await post('/api/event/' + this.event.id + '/uber/sync_attendees', null, this.$refs.progress, "Syncing Attendees")
this.$toast.add({ severity: 'success', summary: 'Attendees Synced', life: 1000 })
} catch {
this.$toast.add({ severity: 'error', summary: 'Failed to sync attendees', detail: 'Please contact your server administrator for assistance.', life: 3000 })
}
//} catch {
// this.$toast.add({ severity: 'error', summary: 'Failed to sync attendees', detail: 'Please contact your server administrator for assistance.', life: 3000 })
//}
},
async export_rooms () {
try {
Expand All @@ -52,6 +53,14 @@ export default {
} catch {
this.$toast.add({ severity: 'error', summary: 'Failed to export rooms', detail: 'Please contact your server administrator for assistance.', life: 3000 })
}
},
async export_requests () {
try {
await post('/api/event/' + this.event.id + '/uber/export_requests', null, this.$refs.progress, "Exporting Requests")
this.$toast.add({ severity: 'success', summary: 'Requests Exported', life: 1000 })
} catch {
this.$toast.add({ severity: 'error', summary: 'Failed to export requests', detail: 'Please contact your server administrator for assistance.', life: 3000 })
}
}
}
}
Expand Down

0 comments on commit 5bb3f57

Please sign in to comment.