From 3ad73b26d302a6f8bf5fc294d33aab62e949a01f Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Mon, 29 Aug 2022 04:14:38 +0000 Subject: [PATCH] refactoring --- Cargo.toml | 4 ++-- migrations/202208061300_api_kgon_game/down.sql | 2 +- migrations/202208061300_api_kgon_game/up.sql | 8 ++++---- src/repositories/game/models.rs | 8 ++++---- src/repositories/game/repository.rs | 18 +++++++++--------- src/repositories/game/schema.rs | 2 +- src/services/game/models.rs | 2 +- src/services/game/service.rs | 2 +- src/synchronizations/game/synchronizer.rs | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8bcccd3..ba3cfb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] } tokio-cron-scheduler = { version = "0" } uuid = { version = "0", features = ["serde", "v4", "v5"] } -beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.80-snapshot" } -beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.66-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.81-snapshot" } +beteran-common-rust = { git = "https://gitlab.loafle.net/bet/beteran-common-rust.git", tag = "v0.1.67-snapshot" } [build-dependencies] diff --git a/migrations/202208061300_api_kgon_game/down.sql b/migrations/202208061300_api_kgon_game/down.sql index 12237e8..f81f65b 100644 --- a/migrations/202208061300_api_kgon_game/down.sql +++ b/migrations/202208061300_api_kgon_game/down.sql @@ -1,4 +1,4 @@ -DROP INDEX idx_api_kgon_games_kgon_vendor_id; +DROP INDEX idx_api_kgon_games_parent_id; DROP INDEX idx_api_kgon_games_key; DROP INDEX idx_api_kgon_games_category; DROP INDEX idx_api_kgon_games_game_type; diff --git a/migrations/202208061300_api_kgon_game/up.sql b/migrations/202208061300_api_kgon_game/up.sql index d3bf6e5..dc19a78 100644 --- a/migrations/202208061300_api_kgon_game/up.sql +++ b/migrations/202208061300_api_kgon_game/up.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS api_kgon_games ( id BIGINT NOT NULL, - kgon_vendor_id BIGINT NOT NULL, + parent_id BIGINT NOT NULL, key TEXT NOT NULL, names TEXT NOT NULL, platform TEXT NOT NULL, @@ -10,12 +10,12 @@ CREATE TABLE IF NOT EXISTS api_kgon_games ( created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000), updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000), PRIMARY KEY (id), - CONSTRAINT fk_api_kgon_games_kgon_vendor_id - FOREIGN KEY(kgon_vendor_id) + CONSTRAINT fk_api_kgon_games_parent_id + FOREIGN KEY(parent_id) REFERENCES api_kgon_vendors(id) ); -CREATE INDEX idx_api_kgon_games_kgon_vendor_id ON api_kgon_games (kgon_vendor_id); +CREATE INDEX idx_api_kgon_games_parent_id ON api_kgon_games (parent_id); CREATE INDEX idx_api_kgon_games_key ON api_kgon_games (key); CREATE INDEX idx_api_kgon_games_category ON api_kgon_games (category); CREATE INDEX idx_api_kgon_games_game_type ON api_kgon_games (game_type); diff --git a/src/repositories/game/models.rs b/src/repositories/game/models.rs index 1c81a91..b64bbfc 100644 --- a/src/repositories/game/models.rs +++ b/src/repositories/game/models.rs @@ -8,7 +8,7 @@ pub struct Game { /// pub id: i64, /// - pub kgon_vendor_id: i64, + pub parent_id: i64, /// pub key: String, /// @@ -34,7 +34,7 @@ pub struct NewGame { /// pub id: i64, /// - pub kgon_vendor_id: i64, + pub parent_id: i64, /// pub key: String, /// @@ -74,7 +74,7 @@ pub struct UpsertGame { /// pub id: i64, /// - pub kgon_vendor_id: i64, + pub parent_id: i64, /// pub key: String, /// @@ -93,7 +93,7 @@ pub struct UpsertGame { #[derive(Debug, Clone)] pub struct FindAllSearch { /// - pub kgon_vendor_id: Option, + pub parent_id: Option, /// pub key_like: Option, /// diff --git a/src/repositories/game/repository.rs b/src/repositories/game/repository.rs index 667cd72..8544311 100644 --- a/src/repositories/game/repository.rs +++ b/src/repositories/game/repository.rs @@ -53,7 +53,7 @@ impl Repository { .on_conflict(dsl::id) .do_update() .set(( - dsl::kgon_vendor_id.eq(excluded(dsl::kgon_vendor_id)), + dsl::parent_id.eq(excluded(dsl::parent_id)), dsl::key.eq(excluded(dsl::key)), dsl::names.eq(excluded(dsl::names)), dsl::platform.eq(excluded(dsl::platform)), @@ -90,8 +90,8 @@ impl Repository { let mut q = api_kgon_games::table.into_boxed(); if let Some(s) = &find_all.search { - if let Some(sp) = s.kgon_vendor_id { - q = q.filter(api_kgon_games::dsl::kgon_vendor_id.eq(sp)); + if let Some(sp) = s.parent_id { + q = q.filter(api_kgon_games::dsl::parent_id.eq(sp)); } if let Some(sp) = &s.key_like { q = q.filter(api_kgon_games::dsl::key.like(sp)); @@ -119,8 +119,8 @@ impl Repository { let mut q = api_kgon_games::table.into_boxed(); if let Some(s) = &find_all.search { - if let Some(sp) = s.kgon_vendor_id { - q = q.filter(api_kgon_games::dsl::kgon_vendor_id.eq(sp)); + if let Some(sp) = s.parent_id { + q = q.filter(api_kgon_games::dsl::parent_id.eq(sp)); } if let Some(sp) = &s.key_like { q = q.filter(api_kgon_games::dsl::key.like(sp)); @@ -148,8 +148,8 @@ impl Repository { for s in orderbys { match s { bcr::pagination::Sort::ASC(property) => match property.as_str() { - "kgon_vendor_id" => { - q = q.order_by(api_kgon_games::kgon_vendor_id.asc()); + "parent_id" => { + q = q.order_by(api_kgon_games::parent_id.asc()); } "key" => { q = q.order_by(api_kgon_games::key.asc()); @@ -172,8 +172,8 @@ impl Repository { _ => {} }, bcr::pagination::Sort::DESC(property) => match property.as_str() { - "kgon_vendor_id" => { - q = q.order_by(api_kgon_games::kgon_vendor_id.desc()); + "parent_id" => { + q = q.order_by(api_kgon_games::parent_id.desc()); } "key" => { q = q.order_by(api_kgon_games::key.desc()); diff --git a/src/repositories/game/schema.rs b/src/repositories/game/schema.rs index 60eefc0..293e12f 100644 --- a/src/repositories/game/schema.rs +++ b/src/repositories/game/schema.rs @@ -7,7 +7,7 @@ table! { /// id -> BigInt, /// - kgon_vendor_id -> BigInt, + parent_id -> BigInt, /// key -> Text, /// diff --git a/src/services/game/models.rs b/src/services/game/models.rs index 7b58766..e926bcc 100644 --- a/src/services/game/models.rs +++ b/src/services/game/models.rs @@ -6,7 +6,7 @@ impl From<&repositories::game::models::Game> for bpr::models::api::game::Game { bpr::models::api::game::Game { id: d.id as u64, key: d.key.clone(), - kgon_vendor_id: d.kgon_vendor_id as u64, + parent_id: d.parent_id as u64, names: d.names.clone(), platform: d.platform.clone(), game_type: d.game_type.clone(), diff --git a/src/services/game/service.rs b/src/services/game/service.rs index bf2a93d..2722854 100644 --- a/src/services/game/service.rs +++ b/src/services/game/service.rs @@ -104,7 +104,7 @@ impl Service { let find_all = repositories::game::models::FindAll { search: match request.search { Some(s) => Some(repositories::game::models::FindAllSearch { - kgon_vendor_id: s.kgon_vendor_id.map(|d| d as i64), + parent_id: s.parent_id.map(|d| d as i64), key_like: s.key_like, category_like: s.category_like, platform_like: s.platform_like, diff --git a/src/synchronizations/game/synchronizer.rs b/src/synchronizations/game/synchronizer.rs index 11d6653..ea339dc 100644 --- a/src/synchronizations/game/synchronizer.rs +++ b/src/synchronizations/game/synchronizer.rs @@ -90,7 +90,7 @@ impl Synchronizer { upsert_games.push(repositories::game::models::UpsertGame { id: g.id, - kgon_vendor_id: v.id, + parent_id: v.id, key: g.key.clone(), names: serde_json::to_string(&g.names).expect("names"), platform: g.platform.clone(),