#[derive(Deserialize, ToSchema)]
pub struct FareQuery {
pub sx: f64,
pub sy: f64,
pub ex: f64,
pub ey: f64,
pub path_index: Option<usize>,
}
So what: 요금 조회에 필요한 파라미터 구조체 정의
So why: path_index를 Option<usize>로 선언한 이유는 Flutter에서 첫 번째 경로 요금만 볼 때 path_index 없이 호출할 수 있게 필수값으로 0으로 만들어주기 위해서이다
pub async fn get_fare(
state: web::Data<AppState>,
query: web::Query<FareQuery>,
) -> HttpResponse {
match state.odsay.search_route(query.sx, query.sy, query.ex, query.ey).await {
Ok(response) => {
let path_index = query.path_index.unwrap_or(0);
match services::odsay::OdsayService::extract_fare(&response, path_index) {
Some(fare) => HttpResponse::Ok().json(fare),
None => HttpResponse::NotFound().body("요금 정보를 찾을 수 없습니다."),
}
}
Err(e) => HttpResponse::InternalServerError().body(format!("에러: {}", e)),
}
}
So what: ODSay 경로 검색 한 번 호출 후 결과에서 요금만 뽑아온다
So why: ODSay API는 경로 검색 결과 안에 요금 정보가 포함되어 있다. 그래서 search_route를 호출한 다음 extract_fare로 필요한 필드만 꺼내는 구조이다.
'Project > SSAFY2학기 특화 PJT' 카테고리의 다른 글
| [BE] main.rs ( 메인 실행 코드 ) (0) | 2026.03.16 |
|---|---|
| [BE] realtime.rs ( 실시간 데이터 ) (0) | 2026.03.13 |
| [BE] cache.rs ( Valkey 연동 ) (0) | 2026.03.13 |
| [BE] kafka.rs ( Kafka 연동 ) (0) | 2026.03.13 |
| [BE] congestion.rs ( 혼잡도 AI ) (0) | 2026.03.13 |
