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
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions stationapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
tonic-health = "0.12.3"
petgraph = "0.7.1"
tonic-reflection = "0.12.3"

[build-dependencies]
tonic-build = "0.12.3"
7 changes: 7 additions & 0 deletions stationapi/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use std::{env, path::PathBuf};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

tonic_build::configure()
.build_client(false)
.build_server(true)
.type_attribute("Company", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute(
"LineSymbol",
Expand All @@ -20,6 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.protoc_arg("--experimental_allow_proto3_optional")
.file_descriptor_set_path(out_dir.join("stationapi_descriptor.bin"))
.compile_protos(&["proto/stationapi.proto"], &["proto"])?;
Ok(())
}
4 changes: 2 additions & 2 deletions stationapi/src/domain/entity/station.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::station_api::StopCondition;
use crate::proto::StopCondition;

use super::{line::Line, station_number::StationNumber, train_type::TrainType as TrainTypeEntity};

Expand Down Expand Up @@ -204,7 +204,7 @@ impl Station {
mod tests {
use super::Station;
use crate::domain::entity::{line::Line, station_number::StationNumber};
use crate::station_api::StopCondition;
use crate::proto::StopCondition;

#[test]
fn new() {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/infrastructure/station_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
error::DomainError,
repository::station_repository::StationRepository,
},
station_api::StopCondition,
proto::StopCondition,
};

#[derive(sqlx::FromRow)]
Expand Down
5 changes: 4 additions & 1 deletion stationapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pub mod infrastructure;
pub mod presentation;
pub mod use_case;

pub mod station_api {
pub mod proto {
tonic::include_proto!("app.trainlcd.grpc");

pub const FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("stationapi_descriptor");
}
9 changes: 8 additions & 1 deletion stationapi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use stationapi::{
train_type_repository::MyTrainTypeRepository,
},
presentation::controller::grpc::MyApi,
station_api::station_api_server::StationApiServer,
proto::{self, station_api_server::StationApiServer},
use_case::interactor::query::QueryInteractor,
};
use std::sync::Arc;
Expand Down Expand Up @@ -80,19 +80,26 @@ async fn run() -> std::result::Result<(), anyhow::Error> {
.accept_compressed(CompressionEncoding::Zstd)
.send_compressed(CompressionEncoding::Zstd);

let reflection_svc = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(proto::FILE_DESCRIPTOR_SET)
.build_v1()
.unwrap();

info!("StationAPI Server listening on {}", addr);

if disable_grpc_web {
Server::builder()
.add_service(health_service)
.add_service(svc)
.add_service(reflection_svc)
.serve(addr)
.await?;
} else {
Server::builder()
.accept_http1(true)
.add_service(tonic_web::enable(health_service))
.add_service(tonic_web::enable(svc))
.add_service(tonic_web::enable(reflection_svc))
.serve(addr)
.await?;
}
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/presentation/controller/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
train_type_repository::MyTrainTypeRepository,
},
presentation::error::PresentationalError,
station_api::{
proto::{
station_api_server::StationApi, CoordinatesRequest, DistanceResponse,
DistanceResponseState, GetConnectedStationsRequest, GetLineByIdRequest,
GetLinesByNameRequest, GetRouteRequest, GetStationByCoordinatesRequest,
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/company.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{domain::entity::company::Company, station_api::Company as GrpcCompany};
use crate::{domain::entity::company::Company, proto::Company as GrpcCompany};

impl From<Company> for GrpcCompany {
fn from(company: Company) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/line.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{domain::entity::line::Line, station_api::Line as GrpcLine};
use crate::{domain::entity::line::Line, proto::Line as GrpcLine};

impl From<Line> for GrpcLine {
fn from(line: Line) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/line_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{domain::entity::line_symbol::LineSymbol, station_api::LineSymbol as GrpcLineSymbol};
use crate::{domain::entity::line_symbol::LineSymbol, proto::LineSymbol as GrpcLineSymbol};

impl From<LineSymbol> for GrpcLineSymbol {
fn from(symbol: LineSymbol) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/station.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{domain::entity::station::Station, station_api::Station as GrpcStation};
use crate::{domain::entity::station::Station, proto::Station as GrpcStation};

impl From<Station> for GrpcStation {
fn from(station: Station) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/station_number.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
domain::entity::station_number::StationNumber, station_api::StationNumber as GrpcStationNumber,
domain::entity::station_number::StationNumber, proto::StationNumber as GrpcStationNumber,
};

impl From<StationNumber> for GrpcStationNumber {
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/dto/train_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{domain::entity::train_type::TrainType, station_api::TrainType as GrpcTrainType};
use crate::{domain::entity::train_type::TrainType, proto::TrainType as GrpcTrainType};

impl From<TrainType> for GrpcTrainType {
fn from(train_type: TrainType) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions stationapi/src/use_case/interactor/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
train_type_repository::TrainTypeRepository,
},
},
station_api::{self, Route},
proto::{self, Route},
use_case::{error::UseCaseError, traits::query::QueryUseCase},
};
use async_trait::async_trait;
Expand Down Expand Up @@ -827,7 +827,7 @@ where

stop.into()
})
.collect::<Vec<station_api::Station>>();
.collect::<Vec<proto::Station>>();

// TODO: SQLで同等の処理を行う
let includes_requested_station = stops
Expand Down
2 changes: 1 addition & 1 deletion stationapi/src/use_case/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
company::Company, line::Line, line_symbol::LineSymbol, misc::StationIdWithDistance,
station::Station, station_number::StationNumber, train_type::TrainType,
},
station_api::Route,
proto::Route,
use_case::error::UseCaseError,
};

Expand Down