backend/feature/recompute-trip-time #62
@@ -179,6 +179,45 @@ def get_landmark(landmark_uuid: str) -> Landmark:
 | 
				
			|||||||
        raise HTTPException(status_code=404, detail="Landmark not found") from exc
 | 
					        raise HTTPException(status_code=404, detail="Landmark not found") from exc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.post("/trip/recompute-time/{trip_uuid}/{removed_landmark_uuid}")
 | 
				
			||||||
 | 
					def update_trip_time(trip_uuid: str, removed_landmark_uuid: str) -> Trip:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Updates the reaching times of a given trip when removing a landmark.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Args:
 | 
				
			||||||
 | 
					        landmark_uuid (str) : unique identifier for a Landmark.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Returns:
 | 
				
			||||||
 | 
					        (Landmark)          : the corresponding Landmark.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    # First, fetch the trip in the cache.
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        trip = cache_client.get(f'trip_{trip_uuid}')
 | 
				
			||||||
 | 
					    except KeyError as exc:
 | 
				
			||||||
 | 
					        raise HTTPException(status_code=404, detail='Trip not found') from exc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    landmarks = []
 | 
				
			||||||
 | 
					    next_uuid = trip.first_landmark_uuid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Extract landmarks
 | 
				
			||||||
 | 
					    try :
 | 
				
			||||||
 | 
					        while next_uuid is not None:
 | 
				
			||||||
 | 
					            landmark = cache_client.get(f'landmark_{next_uuid}')
 | 
				
			||||||
 | 
					            # Filter out the removed landmark.
 | 
				
			||||||
 | 
					            if next_uuid != removed_landmark_uuid :
 | 
				
			||||||
 | 
					                landmarks.append(landmark)
 | 
				
			||||||
 | 
					            next_uuid = landmark.next_uuid  # Prepare for the next iteration
 | 
				
			||||||
 | 
					    except KeyError as exc:
 | 
				
			||||||
 | 
					        raise HTTPException(status_code=404, detail=f'landmark {next_uuid} not found') from exc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Re-link every thing and compute times again
 | 
				
			||||||
 | 
					    linked_tour = LinkedLandmarks(landmarks)
 | 
				
			||||||
 | 
					    trip = Trip.from_linked_landmarks(linked_tour, cache_client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return trip
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.post("/toilets/new")
 | 
					@app.post("/toilets/new")
 | 
				
			||||||
def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -> list[Toilets] :
 | 
					def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -> list[Toilets] :
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user