change: rename core crate to service in examples (#1662)

* change: rename `core` crate to `service` in examples

* fix(jsonrpsee-example): broken dependency
This commit is contained in:
df51d 2023-05-23 04:33:44 +02:00 committed by GitHub
parent 59e3ba8095
commit 0b15f4f5e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
113 changed files with 399 additions and 399 deletions

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
actix3-example-api = { path = "api" } actix3-example-api = { path = "api" }

View File

@ -6,7 +6,7 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-mysql",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-mysql",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
@ -19,9 +19,9 @@ cargo install systemfd
systemfd --no-pid -s http::8000 -- cargo watch -x run systemfd --no-pid -s http::8000 -- cargo watch -x run
``` ```
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
actix3-example-core = { path = "../core" } actix3-example-service = { path = "../service" }
actix-http = "2" actix-http = "2"
actix-web = "3" actix-web = "3"
actix-flash = "0.2" actix-flash = "0.2"

View File

@ -1,4 +1,4 @@
use actix3_example_core::{ use actix3_example_service::{
sea_orm::{Database, DatabaseConnection}, sea_orm::{Database, DatabaseConnection},
Mutation, Query, Mutation, Query,
}; };

View File

@ -1,5 +1,5 @@
[package] [package]
name = "actix-example-core" name = "actix3-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,7 +1,7 @@
mod prepare; mod prepare;
use actix3_example_service::{Mutation, Query};
use entity::post; use entity::post;
use jsonrpsee_example_core::{Mutation, Query};
use prepare::prepare_mock_db; use prepare::prepare_mock_db;
#[tokio::test] #[tokio::test]

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
actix-example-api = { path = "api" } actix-example-api = { path = "api" }

View File

@ -4,7 +4,7 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-mysql",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-mysql",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
@ -17,9 +17,9 @@ cargo install systemfd cargo-watch
systemfd --no-pid -s http::8000 -- cargo watch -x run systemfd --no-pid -s http::8000 -- cargo watch -x run
``` ```
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
actix-example-core = { path = "../core" } actix-example-service = { path = "../service" }
actix-files = "0.6" actix-files = "0.6"
actix-http = "3" actix-http = "3"
actix-rt = "2.7" actix-rt = "2.7"

View File

@ -1,4 +1,4 @@
use actix_example_core::{ use actix_example_service::{
sea_orm::{Database, DatabaseConnection}, sea_orm::{Database, DatabaseConnection},
Mutation, Query, Mutation, Query,
}; };

View File

@ -1,5 +1,5 @@
[package] [package]
name = "actix3-example-core" name = "actix-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,7 +1,7 @@
mod prepare; mod prepare;
use actix_example_service::{Mutation, Query};
use entity::post; use entity::post;
use poem_example_core::{Mutation, Query};
use prepare::prepare_mock_db; use prepare::prepare_mock_db;
#[tokio::test] #[tokio::test]

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
axum-example-api = { path = "api" } axum-example-api = { path = "api" }

View File

@ -4,15 +4,15 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
1. Visit [localhost:8000](http://localhost:8000) in browser 1. Visit [localhost:8000](http://localhost:8000) in browser
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
axum-example-core = { path = "../core" } axum-example-service = { path = "../service" }
tokio = { version = "1.23.0", features = ["full"] } tokio = { version = "1.23.0", features = ["full"] }
axum = "0.6.1" axum = "0.6.1"
tower = "0.4.13" tower = "0.4.13"

View File

@ -7,7 +7,7 @@ use axum::{
routing::{get, get_service, post}, routing::{get, get_service, post},
Router, Server, Router, Server,
}; };
use axum_example_core::{ use axum_example_service::{
sea_orm::{Database, DatabaseConnection}, sea_orm::{Database, DatabaseConnection},
Mutation as MutationCore, Query as QueryCore, Mutation as MutationCore, Query as QueryCore,
}; };

View File

@ -1,5 +1,5 @@
[package] [package]
name = "axum-example-core" name = "axum-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,6 +1,6 @@
mod prepare; mod prepare;
use axum_example_core::{Mutation, Query}; use axum_example_service::{Mutation, Query};
use entity::post; use entity::post;
use prepare::prepare_mock_db; use prepare::prepare_mock_db;

View File

@ -7,7 +7,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
graphql-example-api = { path = "api" } graphql-example-api = { path = "api" }

View File

@ -6,15 +6,15 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
1. Visit [localhost:3000/api/graphql](http://localhost:3000/api/graphql) in browser 1. Visit [localhost:3000/api/graphql](http://localhost:3000/api/graphql) in browser
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
graphql-example-core = { path = "../core" } graphql-example-service = { path = "../service" }
tokio = { version = "1.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] }
axum = "0.5.1" axum = "0.5.1"
dotenvy = "0.15.0" dotenvy = "0.15.0"

View File

@ -1,4 +1,4 @@
use graphql_example_core::sea_orm::DatabaseConnection; use graphql_example_service::sea_orm::DatabaseConnection;
pub struct Database { pub struct Database {
pub connection: DatabaseConnection, pub connection: DatabaseConnection,
@ -6,7 +6,7 @@ pub struct Database {
impl Database { impl Database {
pub async fn new() -> Self { pub async fn new() -> Self {
let connection = graphql_example_core::sea_orm::Database::connect( let connection = graphql_example_service::sea_orm::Database::connect(
std::env::var("DATABASE_URL").unwrap(), std::env::var("DATABASE_URL").unwrap(),
) )
.await .await

View File

@ -1,7 +1,7 @@
use async_graphql::{Context, Object, Result}; use async_graphql::{Context, Object, Result};
use entity::async_graphql::{self, InputObject, SimpleObject}; use entity::async_graphql::{self, InputObject, SimpleObject};
use entity::note; use entity::note;
use graphql_example_core::Mutation; use graphql_example_service::Mutation;
use crate::db::Database; use crate::db::Database;

View File

@ -1,6 +1,6 @@
use async_graphql::{Context, Object, Result}; use async_graphql::{Context, Object, Result};
use entity::{async_graphql, note}; use entity::{async_graphql, note};
use graphql_example_core::Query; use graphql_example_service::Query;
use crate::db::Database; use crate::db::Database;

View File

@ -1,5 +1,5 @@
[package] [package]
name = "graphql-example-core" name = "graphql-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,7 +1,7 @@
mod prepare; mod prepare;
use entity::note; use entity::note;
use graphql_example_core::{Mutation, Query}; use graphql_example_service::{Mutation, Query};
use prepare::prepare_mock_db; use prepare::prepare_mock_db;
#[tokio::test] #[tokio::test]

View File

@ -6,7 +6,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
jsonrpsee-example-api = { path = "api" } jsonrpsee-example-api = { path = "api" }

View File

@ -2,7 +2,7 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
@ -63,9 +63,9 @@ curl --location --request POST 'http://127.0.0.1:8000' \
``` ```
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -5,7 +5,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
jsonrpsee-example-core = { path = "../core" } jsonrpsee-example-service = { path = "../service" }
jsonrpsee = { version = "0.8.0", features = ["full"] } jsonrpsee = { version = "0.8.0", features = ["full"] }
jsonrpsee-core = "0.9.0" jsonrpsee-core = "0.9.0"
tokio = { version = "1.8.0", features = ["full"] } tokio = { version = "1.8.0", features = ["full"] }

View File

@ -6,8 +6,8 @@ use jsonrpsee::core::{async_trait, RpcResult};
use jsonrpsee::http_server::HttpServerBuilder; use jsonrpsee::http_server::HttpServerBuilder;
use jsonrpsee::proc_macros::rpc; use jsonrpsee::proc_macros::rpc;
use jsonrpsee::types::error::CallError; use jsonrpsee::types::error::CallError;
use jsonrpsee_example_core::sea_orm::{Database, DatabaseConnection}; use jsonrpsee_example_service::sea_orm::{Database, DatabaseConnection};
use jsonrpsee_example_core::{Mutation, Query}; use jsonrpsee_example_service::{Mutation, Query};
use log::info; use log::info;
use migration::{Migrator, MigratorTrait}; use migration::{Migrator, MigratorTrait};
use simplelog::*; use simplelog::*;

View File

@ -1,5 +1,5 @@
[package] [package]
name = "jsonrpsee-example-core" name = "jsonrpsee-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -0,0 +1,79 @@
mod prepare;
use entity::post;
use jsonrpsee_example_service::{Mutation, Query};
use prepare::prepare_mock_db;
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -5,7 +5,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
poem-example-api = { path = "api" } poem-example-api = { path = "api" }

View File

@ -4,15 +4,15 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line 1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
poem-example-core = { path = "../core" } poem-example-service = { path = "../service" }
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
poem = { version = "1.2.33", features = ["static-files"] } poem = { version = "1.2.33", features = ["static-files"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

View File

@ -8,7 +8,7 @@ use poem::http::StatusCode;
use poem::listener::TcpListener; use poem::listener::TcpListener;
use poem::web::{Data, Form, Html, Path, Query}; use poem::web::{Data, Form, Html, Path, Query};
use poem::{get, handler, post, EndpointExt, Error, IntoResponse, Result, Route, Server}; use poem::{get, handler, post, EndpointExt, Error, IntoResponse, Result, Route, Server};
use poem_example_core::{ use poem_example_service::{
sea_orm::{Database, DatabaseConnection}, sea_orm::{Database, DatabaseConnection},
Mutation as MutationCore, Query as QueryCore, Mutation as MutationCore, Query as QueryCore,
}; };

View File

@ -1,5 +1,5 @@
[package] [package]
name = "poem-example-core" name = "poem-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,7 +1,7 @@
mod prepare; mod prepare;
use actix3_example_core::{Mutation, Query};
use entity::post; use entity::post;
use poem_example_service::{Mutation, Query};
use prepare::prepare_mock_db; use prepare::prepare_mock_db;
#[tokio::test] #[tokio::test]

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
rocket-example-api = { path = "api" } rocket-example-api = { path = "api" }

View File

@ -4,15 +4,15 @@
1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database 1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `🚀 Rocket has launched from http://localhost:8000` line 1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `🚀 Rocket has launched from http://localhost:8000` line
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -8,7 +8,7 @@ publish = false
[dependencies] [dependencies]
async-stream = { version = "0.3" } async-stream = { version = "0.3" }
async-trait = { version = "0.1" } async-trait = { version = "0.1" }
rocket-example-core = { path = "../core" } rocket-example-service = { path = "../service" }
futures = { version = "0.3" } futures = { version = "0.3" }
futures-util = { version = "0.3" } futures-util = { version = "0.3" }
rocket = { version = "0.5.0-rc.1", features = [ rocket = { version = "0.5.0-rc.1", features = [

View File

@ -8,7 +8,7 @@ use rocket::request::FlashMessage;
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
use rocket::{Build, Request, Rocket}; use rocket::{Build, Request, Rocket};
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
use rocket_example_core::{Mutation, Query}; use rocket_example_service::{Mutation, Query};
use serde_json::json; use serde_json::json;
use migration::MigratorTrait; use migration::MigratorTrait;

View File

@ -1,4 +1,4 @@
use rocket_example_core::sea_orm; use rocket_example_service::sea_orm;
use async_trait::async_trait; use async_trait::async_trait;
use sea_orm::ConnectOptions; use sea_orm::ConnectOptions;

View File

@ -1,79 +0,0 @@
mod prepare;
use entity::post;
use prepare::prepare_mock_db;
use rocket_example_core::{Mutation, Query};
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -1,5 +1,5 @@
[package] [package]
name = "rocket-example-core" name = "rocket-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -0,0 +1,79 @@
mod prepare;
use entity::post;
use prepare::prepare_mock_db;
use rocket_example_service::{Mutation, Query};
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -6,7 +6,7 @@ edition = "2021"
publish = false publish = false
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration", "dto"] members = [".", "api", "service", "entity", "migration", "dto"]
[dependencies] [dependencies]
rocket-example-api = { path = "api" } rocket-example-api = { path = "api" }

View File

@ -2,7 +2,7 @@
1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database 1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server

View File

@ -8,7 +8,7 @@ publish = false
[dependencies] [dependencies]
async-stream = { version = "0.3" } async-stream = { version = "0.3" }
async-trait = { version = "0.1" } async-trait = { version = "0.1" }
rocket-example-core = { path = "../core" } rocket-example-service = { path = "../service" }
futures = { version = "0.3" } futures = { version = "0.3" }
futures-util = { version = "0.3" } futures-util = { version = "0.3" }
rocket = { version = "0.5.0-rc.1", features = [ rocket = { version = "0.5.0-rc.1", features = [

View File

@ -1,6 +1,6 @@
use dto::dto; use dto::dto;
use rocket::serde::json::Json; use rocket::serde::json::Json;
use rocket_example_core::{Mutation, Query}; use rocket_example_service::{Mutation, Query};
use sea_orm_rocket::Connection; use sea_orm_rocket::Connection;

View File

@ -1,4 +1,4 @@
use rocket_example_core::sea_orm; use rocket_example_service::sea_orm;
use async_trait::async_trait; use async_trait::async_trait;
use sea_orm::ConnectOptions; use sea_orm::ConnectOptions;

View File

@ -1,79 +0,0 @@
mod prepare;
use entity::post;
use prepare::prepare_mock_db;
use rocket_example_core::{Mutation, Query};
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -1,5 +1,5 @@
[package] [package]
name = "rocket-example-core" name = "rocket-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -0,0 +1,79 @@
mod prepare;
use entity::post;
use prepare::prepare_mock_db;
use rocket_example_service::{Mutation, Query};
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -5,7 +5,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
salvo-example-api = { path = "api" } salvo-example-api = { path = "api" }

View File

@ -4,15 +4,15 @@
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database 1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line) 1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
1. Execute `cargo run` to start the server 1. Execute `cargo run` to start the server
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line 1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
salvo-example-core = { path = "../core" } salvo-example-service = { path = "../service" }
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
salvo = { version = "0.27", features = ["affix", "serve-static"] } salvo = { version = "0.27", features = ["affix", "serve-static"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

View File

@ -6,7 +6,7 @@ use salvo::extra::affix;
use salvo::extra::serve_static::DirHandler; use salvo::extra::serve_static::DirHandler;
use salvo::prelude::*; use salvo::prelude::*;
use salvo::writer::Text; use salvo::writer::Text;
use salvo_example_core::{ use salvo_example_service::{
sea_orm::{Database, DatabaseConnection}, sea_orm::{Database, DatabaseConnection},
Mutation, Query, Mutation, Query,
}; };

View File

@ -1,79 +0,0 @@
mod prepare;
use entity::post;
use prepare::prepare_mock_db;
use salvo_example_core::{Mutation, Query};
#[tokio::test]
async fn main() {
let db = &prepare_mock_db();
{
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
assert_eq!(post.id, 1);
}
{
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
assert_eq!(post.id, 5);
}
{
let post = Mutation::create_post(
db,
post::Model {
id: 0,
title: "Title D".to_owned(),
text: "Text D".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::ActiveModel {
id: sea_orm::ActiveValue::Unchanged(6),
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
}
);
}
{
let post = Mutation::update_post_by_id(
db,
1,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
},
)
.await
.unwrap();
assert_eq!(
post,
post::Model {
id: 1,
title: "New Title A".to_owned(),
text: "New Text A".to_owned(),
}
);
}
{
let result = Mutation::delete_post(db, 5).await.unwrap();
assert_eq!(result.rows_affected, 1);
}
{
let result = Mutation::delete_all_posts(db).await.unwrap();
assert_eq!(result.rows_affected, 5);
}
}

View File

@ -1,5 +1,5 @@
[package] [package]
name = "salvo-example-core" name = "salvo-example-service"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -1,8 +1,8 @@
mod prepare; mod prepare;
use actix_example_core::{Mutation, Query};
use entity::post; use entity::post;
use prepare::prepare_mock_db; use prepare::prepare_mock_db;
use salvo_example_service::{Mutation, Query};
#[tokio::test] #[tokio::test]
async fn main() { async fn main() {

View File

@ -7,7 +7,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace] [workspace]
members = [".", "api", "core", "entity", "migration"] members = [".", "api", "service", "entity", "migration"]
[dependencies] [dependencies]
tonic-example-api = { path = "api" } tonic-example-api = { path = "api" }

View File

@ -14,9 +14,9 @@ run client using
cargo run --bin client cargo run --bin client
``` ```
Run mock test on the core logic crate: Run mock test on the service logic crate:
```bash ```bash
cd core cd service
cargo test --features mock cargo test --features mock
``` ```

View File

@ -5,7 +5,7 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
tonic-example-core = { path = "../core" } tonic-example-service = { path = "../service" }
tonic = "0.7" tonic = "0.7"
tokio = { version = "1.17", features = ["macros", "rt-multi-thread", "full"] } tokio = { version = "1.17", features = ["macros", "rt-multi-thread", "full"] }
entity = { path = "../entity" } entity = { path = "../entity" }

Some files were not shown because too many files have changed in this diff Show More