Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stationapi/src/infrastructure/station_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,9 @@ impl InternalStationRepository {
ON a.id = la.alias_cd
WHERE s.e_status = 0
AND ($4::int IS NULL OR COALESCE(s.transport_type, 0) = $4)
ORDER BY point(s.lat, s.lon) <-> point($1, $2)
ORDER BY
CASE WHEN $4 IS NULL THEN COALESCE(s.transport_type, 0) ELSE 0 END,
point(s.lat, s.lon) <-> point($1, $2)
LIMIT $3"#,
)
.bind(latitude)
Expand Down
13 changes: 2 additions & 11 deletions stationapi/src/presentation/controller/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
domain::entity::gtfs::{TransportType, TransportTypeFilter},
domain::entity::gtfs::TransportTypeFilter,
infrastructure::{
company_repository::MyCompanyRepository, line_repository::MyLineRepository,
station_repository::MyStationRepository, train_type_repository::MyTrainTypeRepository,
Expand Down Expand Up @@ -123,7 +123,7 @@ impl StationApi for MyApi {
let longitude = request_ref.longitude;
let limit = request_ref.limit;
let transport_type = convert_transport_type(request_ref.transport_type);
let mut stations = match self
let stations = match self
.query_use_case
.get_stations_by_coordinates(latitude, longitude, limit, transport_type)
.await
Expand All @@ -132,15 +132,6 @@ impl StationApi for MyApi {
Err(err) => return Err(PresentationalError::from(err).into()),
};

// RailAndBusが指定された場合は、Railを先頭にソート(stable sortで距離順を維持)
if transport_type == TransportTypeFilter::RailAndBus {
stations.sort_by(|a, b| match (a.transport_type, b.transport_type) {
(TransportType::Rail, TransportType::Bus) => std::cmp::Ordering::Less,
(TransportType::Bus, TransportType::Rail) => std::cmp::Ordering::Greater,
_ => std::cmp::Ordering::Equal,
});
}

Ok(tonic::Response::new(MultipleStationResponse {
stations: stations.into_iter().map(|station| station.into()).collect(),
}))
Expand Down