Files
make-space/crates/domain/src/place.rs
T

82 lines
2.5 KiB
Rust

use serde::{Deserialize, Serialize};
/// A search result shown to the user before they confirm the place.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PlaceCandidate {
/// Provider that produced this candidate (`kakao`, `naver`).
pub provider: String,
/// Provider-native id (Kakao place id, Naver place id).
pub provider_id: String,
pub name: String,
pub category: String,
pub address: String,
pub road_address: String,
pub phone: String,
pub lat: f64,
pub lng: f64,
pub place_url: String,
}
impl PlaceCandidate {
/// Stable internal id, e.g. `kakao:12345`.
pub fn place_id(&self) -> String {
format!("{}:{}", self.provider, self.provider_id)
}
}
/// Canonical, normalized place persisted in MongoDB.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Place {
#[serde(rename = "_id")]
pub id: String,
pub kakao_id: Option<String>,
pub naver_place_id: Option<String>,
pub name: String,
pub category: String,
pub address: String,
pub road_address: String,
pub phone: String,
pub lat: f64,
pub lng: f64,
pub place_url: String,
}
/// A saved analysis that can be reopened without starting another analysis job.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RecentPlace {
pub place: Place,
pub analyzed_at: String,
pub last_viewed_at: Option<String>,
pub floor_labels: Vec<String>,
pub seat_estimate: u32,
}
impl Place {
pub fn from_candidate(c: &PlaceCandidate) -> Self {
let (kakao_id, naver_place_id) = match c.provider.as_str() {
"kakao" => (Some(c.provider_id.clone()), None),
"naver" => (None, Some(c.provider_id.clone())),
_ => (None, None),
};
Self {
id: c.place_id(),
kakao_id,
naver_place_id,
name: c.name.clone(),
category: c.category.clone(),
address: c.address.clone(),
road_address: c.road_address.clone(),
phone: c.phone.clone(),
lat: c.lat,
lng: c.lng,
place_url: c.place_url.clone(),
}
}
/// Short region hint (e.g. "성동구 성수동") used to disambiguate web searches.
pub fn region_hint(&self) -> String {
let addr = if self.address.is_empty() { &self.road_address } else { &self.address };
addr.split_whitespace().skip(1).take(2).collect::<Vec<_>>().join(" ")
}
}