game api is added
This commit is contained in:
parent
7502f066fc
commit
b90b54ba2d
|
@ -29,8 +29,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
tokio-cron-scheduler = { version = "*" }
|
tokio-cron-scheduler = { version = "*" }
|
||||||
uuid = { version = "0", features = ["serde", "v4", "v5"] }
|
uuid = { version = "0", features = ["serde", "v4", "v5"] }
|
||||||
|
|
||||||
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.65-snapshot" }
|
beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.66-snapshot" }
|
||||||
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.49-snapshot" }
|
beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.50-snapshot" }
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -91,6 +91,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let _h_scheduler = sched.start().await?;
|
let _h_scheduler = sched.start().await?;
|
||||||
|
|
||||||
|
let vendor_service = services::vendor::service::Service::new(
|
||||||
|
connection_server_broker.clone(),
|
||||||
|
queue_server_broker.clone(),
|
||||||
|
pool.clone(),
|
||||||
|
);
|
||||||
|
let game_service = services::game::service::Service::new(
|
||||||
|
connection_server_broker.clone(),
|
||||||
|
queue_server_broker.clone(),
|
||||||
|
pool.clone(),
|
||||||
|
);
|
||||||
let member_service = services::member::service::Service::new(
|
let member_service = services::member::service::Service::new(
|
||||||
connection_server_broker.clone(),
|
connection_server_broker.clone(),
|
||||||
queue_server_broker.clone(),
|
queue_server_broker.clone(),
|
||||||
|
@ -99,11 +109,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
connection_server_broker.clone(),
|
connection_server_broker.clone(),
|
||||||
queue_server_broker.clone(),
|
queue_server_broker.clone(),
|
||||||
);
|
);
|
||||||
let game_service = services::game::service::Service::new(
|
|
||||||
connection_server_broker.clone(),
|
|
||||||
queue_server_broker.clone(),
|
|
||||||
pool.clone(),
|
|
||||||
);
|
|
||||||
let betting_service = services::betting::service::Service::new(
|
let betting_service = services::betting::service::Service::new(
|
||||||
connection_server_broker.clone(),
|
connection_server_broker.clone(),
|
||||||
queue_server_broker.clone(),
|
queue_server_broker.clone(),
|
||||||
|
@ -119,9 +124,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("Server service [beteran-api-kgon-server-service] is started");
|
println!("Server service [beteran-api-kgon-server-service] is started");
|
||||||
|
|
||||||
futures::try_join!(
|
futures::try_join!(
|
||||||
|
vendor_service.subscribe(),
|
||||||
|
game_service.subscribe(),
|
||||||
// member_service.subscribe(),
|
// member_service.subscribe(),
|
||||||
// member_account_service.subscribe(),
|
// member_account_service.subscribe(),
|
||||||
game_service.subscribe(),
|
|
||||||
// betting_service.subscribe(),
|
// betting_service.subscribe(),
|
||||||
member_event_handler.subscribe(),
|
member_event_handler.subscribe(),
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
use crate::repositories;
|
use crate::repositories;
|
||||||
use beteran_protobuf_rust as bpr;
|
use beteran_protobuf_rust as bpr;
|
||||||
|
|
||||||
impl From<&repositories::vendor::models::Vendor> for bpr::models::api::vendor::Vendor {
|
impl From<&repositories::game::models::Game> for bpr::models::api::game::Game {
|
||||||
fn from(d: &repositories::vendor::models::Vendor) -> Self {
|
fn from(d: &repositories::game::models::Game) -> Self {
|
||||||
bpr::models::api::vendor::Vendor {
|
bpr::models::api::game::Game {
|
||||||
id: d.id as u64,
|
id: d.id as u64,
|
||||||
name: d.name.clone(),
|
|
||||||
company_id: d.company_id as u64,
|
|
||||||
vendor_id: d.vendor_id as u64,
|
|
||||||
key: d.key.clone(),
|
key: d.key.clone(),
|
||||||
|
vendor_id: d.vendor_id as u64,
|
||||||
|
names: d.names.clone(),
|
||||||
|
platform: d.platform.clone(),
|
||||||
|
game_type: d.game_type.clone(),
|
||||||
|
image: d.image.clone(),
|
||||||
category: d.category.clone(),
|
category: d.category.clone(),
|
||||||
max_bet_casino: d.max_bet_casino as u64,
|
|
||||||
max_bet_slot: d.max_bet_slot as u64,
|
|
||||||
is_enable: d.is_enable.clone(),
|
|
||||||
bet_count: d.bet_count as u64,
|
|
||||||
created_at: d.created_at as u64,
|
created_at: d.created_at as u64,
|
||||||
updated_at: d.updated_at as u64,
|
updated_at: d.updated_at as u64,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct Service {
|
||||||
connection_broker: nats::asynk::Connection,
|
connection_broker: nats::asynk::Connection,
|
||||||
queue_broker: String,
|
queue_broker: String,
|
||||||
pool: Pool<ConnectionManager<PgConnection>>,
|
pool: Pool<ConnectionManager<PgConnection>>,
|
||||||
vendor_repository: repositories::vendor::repository::Repository,
|
game_repository: repositories::game::repository::Repository,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Service {
|
impl std::fmt::Debug for Service {
|
||||||
|
@ -32,27 +32,27 @@ impl Service {
|
||||||
connection_broker,
|
connection_broker,
|
||||||
queue_broker,
|
queue_broker,
|
||||||
pool,
|
pool,
|
||||||
vendor_repository: repositories::vendor::repository::Repository::new(),
|
game_repository: repositories::game::repository::Repository::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
||||||
futures::try_join!(self.list_vendors()).map(|_| ())
|
futures::try_join!(self.list_games()).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_vendors(&self) -> Result<(), Box<dyn std::error::Error>> {
|
async fn list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let s = self
|
let s = self
|
||||||
.connection_broker
|
.connection_broker
|
||||||
.queue_subscribe(
|
.queue_subscribe(
|
||||||
bpr::ss::api::vendor::SUBJECT_LIST_VENDORS,
|
bpr::ss::api::game::SUBJECT_LIST_GAMES,
|
||||||
self.queue_broker.as_str(),
|
self.queue_broker.as_str(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
while let Some(message) = s.next().await {
|
while let Some(message) = s.next().await {
|
||||||
if let Err(e) = async {
|
if let Err(e) = async {
|
||||||
let req = bpr::ss::api::vendor::ListVendorsRequest::decode(message.data.as_slice())
|
let req =
|
||||||
.map_err(|e| {
|
bpr::ss::api::game::ListGamesRequest::decode(message.data.as_slice()).map_err(|e| {
|
||||||
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||||
message: format!("invalid request: {}", e),
|
message: format!("invalid request: {}", e),
|
||||||
})
|
})
|
||||||
|
@ -101,33 +101,32 @@ impl Service {
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let find_all = repositories::vendor::models::FindAll {
|
let find_all = repositories::game::models::FindAll {
|
||||||
search: match request.search {
|
search: match request.search {
|
||||||
Some(s) => Some(repositories::vendor::models::FindAllSearch {
|
Some(s) => Some(repositories::game::models::FindAllSearch {
|
||||||
name_like: s.name_like,
|
|
||||||
company_id: s.company_id.map(|d| d as i64),
|
|
||||||
vendor_id: s.vendor_id.map(|d| d as i64),
|
vendor_id: s.vendor_id.map(|d| d as i64),
|
||||||
key_like: s.key_like,
|
key_like: s.key_like,
|
||||||
category_like: s.category_like,
|
category_like: s.category_like,
|
||||||
is_enable: s.is_enable,
|
platform_like: s.platform_like,
|
||||||
|
game_type_like: s.game_type_like,
|
||||||
}),
|
}),
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
pagination: request
|
pagination: request
|
||||||
.pagination
|
.pagination
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
.map(bcr::models::pagination::Pagination::from),
|
||||||
sorts: Some(
|
sorts: Some(
|
||||||
request
|
request
|
||||||
.sorts
|
.sorts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
.map(beteran_common_rust::models::pagination::Sort::from)
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let count = self
|
let count = self
|
||||||
.vendor_repository
|
.game_repository
|
||||||
.select_all_count(&conn, &find_all)
|
.select_all_count(&conn, &find_all)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
@ -138,7 +137,7 @@ impl Service {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let list = self
|
let list = self
|
||||||
.vendor_repository
|
.game_repository
|
||||||
.select_all(&conn, &find_all)
|
.select_all(&conn, &find_all)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
@ -150,12 +149,12 @@ impl Service {
|
||||||
|
|
||||||
message
|
message
|
||||||
.respond(
|
.respond(
|
||||||
bpr::ss::api::vendor::ListVendorsResponse {
|
bpr::ss::api::game::ListGamesResponse {
|
||||||
error: None,
|
error: None,
|
||||||
result: Some(bpr::ss::api::vendor::list_vendors_response::Result {
|
result: Some(bpr::ss::api::game::list_games_response::Result {
|
||||||
vendors: list
|
games: list
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| bpr::models::api::vendor::Vendor::from(d))
|
.map(bpr::models::api::game::Game::from)
|
||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -176,7 +175,7 @@ impl Service {
|
||||||
{
|
{
|
||||||
message
|
message
|
||||||
.respond(
|
.respond(
|
||||||
bpr::ss::api::vendor::ListVendorsResponse {
|
bpr::ss::api::game::ListGamesResponse {
|
||||||
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
result: None,
|
result: None,
|
||||||
}
|
}
|
||||||
|
@ -188,9 +187,6 @@ impl Service {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_game(&self) -> Result<(), Box<dyn std::error::Error>> {
|
async fn execute_game(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -2,3 +2,4 @@ pub mod betting;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
pub mod member;
|
pub mod member;
|
||||||
pub mod member_account;
|
pub mod member_account;
|
||||||
|
pub mod vendor;
|
||||||
|
|
2
src/services/vendor/mod.rs
vendored
Normal file
2
src/services/vendor/mod.rs
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod models;
|
||||||
|
pub mod service;
|
21
src/services/vendor/models.rs
vendored
Normal file
21
src/services/vendor/models.rs
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use crate::repositories;
|
||||||
|
use beteran_protobuf_rust as bpr;
|
||||||
|
|
||||||
|
impl From<&repositories::vendor::models::Vendor> for bpr::models::api::vendor::Vendor {
|
||||||
|
fn from(d: &repositories::vendor::models::Vendor) -> Self {
|
||||||
|
bpr::models::api::vendor::Vendor {
|
||||||
|
id: d.id as u64,
|
||||||
|
name: d.name.clone(),
|
||||||
|
company_id: d.company_id as u64,
|
||||||
|
vendor_id: d.vendor_id as u64,
|
||||||
|
key: d.key.clone(),
|
||||||
|
category: d.category.clone(),
|
||||||
|
max_bet_casino: d.max_bet_casino as u64,
|
||||||
|
max_bet_slot: d.max_bet_slot as u64,
|
||||||
|
is_enable: d.is_enable.clone(),
|
||||||
|
bet_count: d.bet_count as u64,
|
||||||
|
created_at: d.created_at as u64,
|
||||||
|
updated_at: d.updated_at as u64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
198
src/services/vendor/service.rs
vendored
Normal file
198
src/services/vendor/service.rs
vendored
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
use crate::repositories;
|
||||||
|
use beteran_common_rust as bcr;
|
||||||
|
use beteran_protobuf_rust as bpr;
|
||||||
|
use diesel::{
|
||||||
|
r2d2::{ConnectionManager, Pool},
|
||||||
|
PgConnection,
|
||||||
|
};
|
||||||
|
use prost::Message;
|
||||||
|
|
||||||
|
///
|
||||||
|
pub struct Service {
|
||||||
|
connection_broker: nats::asynk::Connection,
|
||||||
|
queue_broker: String,
|
||||||
|
pool: Pool<ConnectionManager<PgConnection>>,
|
||||||
|
vendor_repository: repositories::vendor::repository::Repository,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for Service {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
f.debug_struct("Service of api.kgon.identity").finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Service {
|
||||||
|
///
|
||||||
|
pub fn new(
|
||||||
|
connection_broker: nats::asynk::Connection,
|
||||||
|
queue_broker: String,
|
||||||
|
pool: Pool<ConnectionManager<PgConnection>>,
|
||||||
|
) -> Service {
|
||||||
|
Service {
|
||||||
|
connection_broker,
|
||||||
|
queue_broker,
|
||||||
|
pool,
|
||||||
|
vendor_repository: repositories::vendor::repository::Repository::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn subscribe(&self) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
|
||||||
|
futures::try_join!(self.list_vendors()).map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_vendors(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let s = self
|
||||||
|
.connection_broker
|
||||||
|
.queue_subscribe(
|
||||||
|
bpr::ss::api::vendor::SUBJECT_LIST_VENDORS,
|
||||||
|
self.queue_broker.as_str(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
while let Some(message) = s.next().await {
|
||||||
|
if let Err(e) = async {
|
||||||
|
let req = bpr::ss::api::vendor::ListVendorsRequest::decode(message.data.as_slice())
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::InvalidRequest(bcr::error::rpc::InvalidRequest {
|
||||||
|
message: format!("invalid request: {}", e),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let client = match req.client {
|
||||||
|
Some(c) => c,
|
||||||
|
None => {
|
||||||
|
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||||
|
bcr::error::rpc::InvalidParams {
|
||||||
|
message: "invalid client information".to_string(),
|
||||||
|
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||||
|
location: "request".to_string(),
|
||||||
|
param: "client".to_string(),
|
||||||
|
value: "".to_string(),
|
||||||
|
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||||
|
message: "".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let request = match req.request {
|
||||||
|
Some(r) => r,
|
||||||
|
None => {
|
||||||
|
return Err(bcr::error::rpc::Error::InvalidParams(
|
||||||
|
bcr::error::rpc::InvalidParams {
|
||||||
|
message: "invalid request information".to_string(),
|
||||||
|
detail: bcr::error::rpc::InvalidParamsDetail {
|
||||||
|
location: "request".to_string(),
|
||||||
|
param: "request".to_string(),
|
||||||
|
value: "".to_string(),
|
||||||
|
error_type: bcr::error::rpc::InvalidParamsType::Required,
|
||||||
|
message: "".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let conn = self.pool.get().map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let find_all = repositories::vendor::models::FindAll {
|
||||||
|
search: match request.search {
|
||||||
|
Some(s) => Some(repositories::vendor::models::FindAllSearch {
|
||||||
|
name_like: s.name_like,
|
||||||
|
company_id: s.company_id.map(|d| d as i64),
|
||||||
|
vendor_id: s.vendor_id.map(|d| d as i64),
|
||||||
|
key_like: s.key_like,
|
||||||
|
category_like: s.category_like,
|
||||||
|
is_enable: s.is_enable,
|
||||||
|
}),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
pagination: request
|
||||||
|
.pagination
|
||||||
|
.as_ref()
|
||||||
|
.map(|d| bcr::models::pagination::Pagination::from(d)),
|
||||||
|
sorts: Some(
|
||||||
|
request
|
||||||
|
.sorts
|
||||||
|
.iter()
|
||||||
|
.map(|d| beteran_common_rust::models::pagination::Sort::from(d))
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let count = self
|
||||||
|
.vendor_repository
|
||||||
|
.select_all_count(&conn, &find_all)
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let list = self
|
||||||
|
.vendor_repository
|
||||||
|
.select_all(&conn, &find_all)
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::ss::api::vendor::ListVendorsResponse {
|
||||||
|
error: None,
|
||||||
|
result: Some(bpr::ss::api::vendor::list_vendors_response::Result {
|
||||||
|
vendors: list
|
||||||
|
.iter()
|
||||||
|
.map(|d| bpr::models::api::vendor::Vendor::from(d))
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
bcr::error::rpc::Error::Server(bcr::error::rpc::Server {
|
||||||
|
code: bpr::protobuf::rpc::Error::SERVER_00,
|
||||||
|
message: format!("server {}", e),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok::<(), bcr::error::rpc::Error>(())
|
||||||
|
}
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
message
|
||||||
|
.respond(
|
||||||
|
bpr::ss::api::vendor::ListVendorsResponse {
|
||||||
|
error: Some(bpr::protobuf::rpc::Error::from(e)),
|
||||||
|
result: None,
|
||||||
|
}
|
||||||
|
.encode_to_vec(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
async fn list_games(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn execute_game(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user