refactor: ♻️ new permission strategy part 1
This commit is contained in:
parent
cf1107d09c
commit
56aa04e32a
24 changed files with 3 additions and 1063 deletions
|
@ -4,9 +4,7 @@ CREATE TABLE IF NOT EXISTS "role"(
|
||||||
name VARCHAR(16) NOT NULL UNIQUE
|
name VARCHAR(16) NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO "role"(id, name) VALUES (0, 'Ahmet Kaan Gümüş') ON CONFLICT(id) DO UPDATE SET "name" = 'Ahmet Kaan Gümüş';
|
INSERT INTO "role"(id, name) VALUES (0, 'Builder') ON CONFLICT(id) DO UPDATE SET "name" = 'Builder';
|
||||||
INSERT INTO "role"(id, name) VALUES (1, 'Founder') ON CONFLICT(id) DO UPDATE SET "name" = 'Founder';
|
INSERT INTO "role"(id, name) VALUES (1, 'Admin') ON CONFLICT(id) DO UPDATE SET "name" = 'Admin';
|
||||||
INSERT INTO "role"(id, name) VALUES (2, 'Maintainer') ON CONFLICT(id) DO UPDATE SET "name" = 'Founder';
|
|
||||||
INSERT INTO "role"(id, name) VALUES (3, 'Admin') ON CONFLICT(id) DO UPDATE SET "name" = 'Admin';
|
|
||||||
INSERT INTO "role"(id, name) VALUES (10, 'Normal') ON CONFLICT(id) DO UPDATE SET "name" = 'Normal';
|
INSERT INTO "role"(id, name) VALUES (10, 'Normal') ON CONFLICT(id) DO UPDATE SET "name" = 'Normal';
|
||||||
INSERT INTO "role"(id, name) VALUES (-1, 'Banned') ON CONFLICT(id) DO UPDATE SET "name" = 'Banned';
|
INSERT INTO "role"(id, name) VALUES (-1, 'Banned') ON CONFLICT(id) DO UPDATE SET "name" = 'Banned';
|
|
@ -1 +0,0 @@
|
||||||
-- Add down migration script here
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
CREATE TABLE IF NOT EXISTS "permission"(
|
|
||||||
id BIGSERIAL PRIMARY KEY UNIQUE NOT NULL,
|
|
||||||
name VARCHAR(256) UNIQUE NOT NULL
|
|
||||||
);
|
|
|
@ -1,2 +0,0 @@
|
||||||
-- Add down migration script here
|
|
||||||
DROP TABLE IF EXISTS "role_permission";
|
|
|
@ -1,6 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
CREATE TABLE IF NOT EXISTS "role_permission"(
|
|
||||||
role_id BIGSERIAL NOT NULL REFERENCES "role"(id),
|
|
||||||
permission_id BIGSERIAL NOT NULL REFERENCES "permission"(id),
|
|
||||||
PRIMARY KEY (role_id, permission_id)
|
|
||||||
);
|
|
|
@ -1,2 +0,0 @@
|
||||||
-- Add down migration script here
|
|
||||||
DROP TABLE IF EXISTS "routing";
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
CREATE TABLE IF NOT EXISTS "routing"(
|
|
||||||
id BIGSERIAL PRIMARY KEY UNIQUE NOT NULL,
|
|
||||||
endpoint VARCHAR(255) UNIQUE NOT NULL
|
|
||||||
);
|
|
|
@ -1,2 +0,0 @@
|
||||||
-- Add down migration script here
|
|
||||||
DROP TABLE IF EXISTS "routing_permission";
|
|
|
@ -1,6 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
CREATE TABLE IF NOT EXISTS "routing_permission"(
|
|
||||||
routing_id BIGSERIAL NOT NULL REFERENCES "routing"(id),
|
|
||||||
permission_id BIGSERIAL NOT NULL REFERENCES "permission"(id),
|
|
||||||
PRIMARY KEY (routing_id, permission_id)
|
|
||||||
);
|
|
|
@ -3,13 +3,9 @@ pub mod comment_interaction;
|
||||||
pub mod contact;
|
pub mod contact;
|
||||||
pub mod interaction;
|
pub mod interaction;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod permission;
|
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod post_interaction;
|
pub mod post_interaction;
|
||||||
pub mod role;
|
pub mod role;
|
||||||
pub mod role_permission;
|
|
||||||
pub mod routing;
|
|
||||||
pub mod routing_permission;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod user_contact;
|
pub mod user_contact;
|
||||||
|
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::feature::permission::Permission;
|
|
||||||
|
|
||||||
pub async fn create(
|
|
||||||
name: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Permission,
|
|
||||||
r#"
|
|
||||||
INSERT INTO "permission"(name)
|
|
||||||
VALUES ($1)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
name,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Permission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "permission" WHERE "id" = $1
|
|
||||||
"#,
|
|
||||||
id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
id: &i64,
|
|
||||||
name: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Permission,
|
|
||||||
r#"
|
|
||||||
UPDATE "permission" SET "name" = $2 WHERE "id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Permission,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "permission" WHERE "id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all(
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<Permission>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Permission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "permission"
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
|
@ -1,106 +0,0 @@
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::feature::role_permission::RolePermission;
|
|
||||||
|
|
||||||
pub async fn create(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
INSERT INTO "role_permission"(role_id, permission_id)
|
|
||||||
VALUES ($1, $2)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
role_id,
|
|
||||||
permission_id
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "role_permission" WHERE "role_id" = $1 AND "permission_id" = $2
|
|
||||||
"#,
|
|
||||||
role_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
UPDATE "role_permission" SET "permission_id" = $2 WHERE "role_id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
role_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "role_permission" WHERE "role_id" = $1 AND "permission_id" = $2
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
role_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all_for_role(
|
|
||||||
role_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RolePermission>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "role_permission" WHERE "role_id" = $1
|
|
||||||
"#,
|
|
||||||
role_id
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all_for_role(
|
|
||||||
role_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RolePermission>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RolePermission,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "role_permission" WHERE "role_id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
role_id,
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::feature::routing::Routing;
|
|
||||||
|
|
||||||
pub async fn create(
|
|
||||||
endpoint: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
INSERT INTO "routing"(endpoint)
|
|
||||||
VALUES ($1)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
endpoint,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(id: &i64, database_connection: &Pool<Postgres>) -> Result<Routing, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "routing" WHERE "id" = $1
|
|
||||||
"#,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
id: &i64,
|
|
||||||
endpoint: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
UPDATE "routing" SET "endpoint" = $2 WHERE "id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
id,
|
|
||||||
endpoint,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "routing" WHERE "id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all(database_connection: &Pool<Postgres>) -> Result<Vec<Routing>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "routing"
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all(database_connection: &Pool<Postgres>) -> Result<Vec<Routing>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
Routing,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "routing"
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
|
@ -1,106 +0,0 @@
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::feature::routing_permission::RoutingPermission;
|
|
||||||
|
|
||||||
pub async fn create(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
INSERT INTO "routing_permission"(routing_id, permission_id)
|
|
||||||
VALUES ($1, $2)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
routing_id,
|
|
||||||
permission_id
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "routing_permission" WHERE "routing_id" = $1 AND "permission_id" = $2
|
|
||||||
"#,
|
|
||||||
routing_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
UPDATE "routing_permission" SET "permission_id" = $2 WHERE "routing_id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
routing_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "routing_permission" WHERE "routing_id" = $1 AND "permission_id" = $2
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
routing_id,
|
|
||||||
permission_id,
|
|
||||||
)
|
|
||||||
.fetch_one(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all_for_routing(
|
|
||||||
routing_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RoutingPermission>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "routing_permission" WHERE "routing_id" = $1
|
|
||||||
"#,
|
|
||||||
routing_id
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all_for_routing(
|
|
||||||
routing_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RoutingPermission>, sqlx::Error> {
|
|
||||||
sqlx::query_as!(
|
|
||||||
RoutingPermission,
|
|
||||||
r#"
|
|
||||||
DELETE FROM "routing_permission" WHERE "routing_id" = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
routing_id,
|
|
||||||
)
|
|
||||||
.fetch_all(database_connection)
|
|
||||||
.await
|
|
||||||
}
|
|
|
@ -4,12 +4,8 @@ pub mod comment_interaction;
|
||||||
pub mod contact;
|
pub mod contact;
|
||||||
pub mod interaction;
|
pub mod interaction;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod permission;
|
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod post_interaction;
|
pub mod post_interaction;
|
||||||
pub mod role;
|
pub mod role;
|
||||||
pub mod role_permission;
|
|
||||||
pub mod routing;
|
|
||||||
pub mod routing_permission;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod user_contact;
|
pub mod user_contact;
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::database::permission;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Permission {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Permission {
|
|
||||||
pub async fn create(
|
|
||||||
name: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
permission::create(name, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
permission::read(id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
id: &i64,
|
|
||||||
name: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
permission::update(id, name, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Permission, sqlx::Error> {
|
|
||||||
permission::delete(id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all(
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<Permission>, sqlx::Error> {
|
|
||||||
permission::read_all(database_connection).await
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::database::role_permission;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct RolePermission {
|
|
||||||
pub role_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RolePermission {
|
|
||||||
pub async fn create(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
role_permission::create(role_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
role_permission::read(role_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
role_permission::update(role_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
pub async fn delete(
|
|
||||||
role_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RolePermission, sqlx::Error> {
|
|
||||||
role_permission::delete(role_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all_for_role(
|
|
||||||
role_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RolePermission>, sqlx::Error> {
|
|
||||||
role_permission::read_all_for_role(role_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all_for_role(
|
|
||||||
role_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RolePermission>, sqlx::Error> {
|
|
||||||
role_permission::delete_all_for_role(role_id, database_connection).await
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::database::routing;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Routing {
|
|
||||||
pub id: i64,
|
|
||||||
pub endpoint: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Routing {
|
|
||||||
pub async fn create(
|
|
||||||
endpoint: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
routing::create(endpoint, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
routing::read(id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
id: &i64,
|
|
||||||
endpoint: &String,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
routing::update(id, endpoint, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(
|
|
||||||
id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Routing, sqlx::Error> {
|
|
||||||
routing::delete(id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all(
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<Routing>, sqlx::Error> {
|
|
||||||
routing::read_all(database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all(
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<Routing>, sqlx::Error> {
|
|
||||||
routing::delete_all(database_connection).await
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use sqlx::{Pool, Postgres};
|
|
||||||
|
|
||||||
use crate::database::routing_permission;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct RoutingPermission {
|
|
||||||
pub routing_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RoutingPermission {
|
|
||||||
pub async fn create(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
routing_permission::create(routing_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
routing_permission::read(routing_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
routing_permission::update(routing_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
pub async fn delete(
|
|
||||||
routing_id: &i64,
|
|
||||||
permission_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<RoutingPermission, sqlx::Error> {
|
|
||||||
routing_permission::delete(routing_id, permission_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_all_for_routing(
|
|
||||||
routing_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RoutingPermission>, sqlx::Error> {
|
|
||||||
routing_permission::read_all_for_routing(routing_id, database_connection).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_all_for_routing(
|
|
||||||
routing_id: &i64,
|
|
||||||
database_connection: &Pool<Postgres>,
|
|
||||||
) -> Result<Vec<RoutingPermission>, sqlx::Error> {
|
|
||||||
routing_permission::delete_all_for_routing(routing_id, database_connection).await
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,13 +3,9 @@ pub mod comment_interaction;
|
||||||
pub mod contact;
|
pub mod contact;
|
||||||
pub mod interaction;
|
pub mod interaction;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod permission;
|
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod post_interaction;
|
pub mod post_interaction;
|
||||||
pub mod role;
|
pub mod role;
|
||||||
pub mod role_permission;
|
|
||||||
pub mod routing;
|
|
||||||
pub mod routing_permission;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod user_contact;
|
pub mod user_contact;
|
||||||
|
|
||||||
|
@ -50,10 +46,6 @@ pub async fn route(concurrency_limit: &usize, State(app_state): State<AppState>)
|
||||||
"/comment_interactions",
|
"/comment_interactions",
|
||||||
comment_interaction::route(axum::extract::State(app_state.clone())),
|
comment_interaction::route(axum::extract::State(app_state.clone())),
|
||||||
)
|
)
|
||||||
.nest(
|
|
||||||
"/role_permissions",
|
|
||||||
role_permission::route(axum::extract::State(app_state.clone())),
|
|
||||||
)
|
|
||||||
.nest(
|
.nest(
|
||||||
"/contacts",
|
"/contacts",
|
||||||
contact::route(axum::extract::State(app_state.clone())),
|
contact::route(axum::extract::State(app_state.clone())),
|
||||||
|
@ -62,14 +54,6 @@ pub async fn route(concurrency_limit: &usize, State(app_state): State<AppState>)
|
||||||
"/user_contacts",
|
"/user_contacts",
|
||||||
user_contact::route(axum::extract::State(app_state.clone())),
|
user_contact::route(axum::extract::State(app_state.clone())),
|
||||||
)
|
)
|
||||||
.nest(
|
|
||||||
"/routings",
|
|
||||||
routing::route(axum::extract::State(app_state.clone())),
|
|
||||||
)
|
|
||||||
.nest(
|
|
||||||
"/routing_permissions",
|
|
||||||
routing_permission::route(axum::extract::State(app_state.clone())),
|
|
||||||
)
|
|
||||||
.layer(CorsLayer::permissive())
|
.layer(CorsLayer::permissive())
|
||||||
.layer(ConcurrencyLimitLayer::new(*concurrency_limit))
|
.layer(ConcurrencyLimitLayer::new(*concurrency_limit))
|
||||||
.with_state(app_state)
|
.with_state(app_state)
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::IntoResponse,
|
|
||||||
routing::{delete, get, patch, post},
|
|
||||||
Json, Router,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{feature::permission::Permission, AppState};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct CreatePermission {
|
|
||||||
name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct UpdatePermission {
|
|
||||||
id: i64,
|
|
||||||
name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn route(State(app_state): State<AppState>) -> Router<AppState> {
|
|
||||||
Router::new()
|
|
||||||
.route("/", post(create))
|
|
||||||
.route("/:id", get(read))
|
|
||||||
.route("/", patch(update))
|
|
||||||
.route("/:id", delete(delete_))
|
|
||||||
.route("/", get(read_all))
|
|
||||||
.with_state(app_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(create_permission): Json<CreatePermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match Permission::create(&create_permission.name, &app_state.database_connection).await {
|
|
||||||
Ok(permission) => (StatusCode::CREATED, Json(serde_json::json!(permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read(State(app_state): State<AppState>, Path(id): Path<i64>) -> impl IntoResponse {
|
|
||||||
match Permission::read(&id, &app_state.database_connection).await {
|
|
||||||
Ok(permission) => (StatusCode::OK, Json(serde_json::json!(permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(update_permission): Json<UpdatePermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match Permission::update(
|
|
||||||
&update_permission.id,
|
|
||||||
&update_permission.name,
|
|
||||||
&app_state.database_connection,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(permission) => (StatusCode::ACCEPTED, Json(serde_json::json!(permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_(State(app_state): State<AppState>, Path(id): Path<i64>) -> impl IntoResponse {
|
|
||||||
match Permission::delete(&id, &app_state.database_connection).await {
|
|
||||||
Ok(permission) => (StatusCode::NO_CONTENT, Json(serde_json::json!(permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_all(State(app_state): State<AppState>) -> impl IntoResponse {
|
|
||||||
match Permission::read_all(&app_state.database_connection).await {
|
|
||||||
Ok(permissions) => (StatusCode::OK, Json(serde_json::json!(permissions))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::IntoResponse,
|
|
||||||
routing::{delete, get, patch, post},
|
|
||||||
Json, Router,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{feature::role_permission::RolePermission, AppState};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct CreateRolePermission {
|
|
||||||
pub role_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct UpdateRolePermission {
|
|
||||||
pub role_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn route(State(app_state): State<AppState>) -> Router<AppState> {
|
|
||||||
Router::new()
|
|
||||||
.route("/", post(create))
|
|
||||||
.route("/roles/:role_id/permissions/:permission_id", get(read))
|
|
||||||
.route("/", patch(update))
|
|
||||||
.route(
|
|
||||||
"/roles/:role_id/permissions/:permission_id",
|
|
||||||
delete(delete_),
|
|
||||||
)
|
|
||||||
.route("/roles/:role_id", get(read_all_for_role))
|
|
||||||
.route("/roles/:role_id", delete(delete_all_for_role))
|
|
||||||
.with_state(app_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(create_role_permission): Json<CreateRolePermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::create(
|
|
||||||
&create_role_permission.role_id,
|
|
||||||
&create_role_permission.permission_id,
|
|
||||||
&app_state.database_connection,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::CREATED,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path((role_id, permission_id)): Path<(i64, i64)>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::read(&role_id, &permission_id, &app_state.database_connection).await {
|
|
||||||
Ok(role_permission) => (StatusCode::OK, Json(serde_json::json!(role_permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(update_role): Json<UpdateRolePermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::update(
|
|
||||||
&update_role.role_id,
|
|
||||||
&update_role.permission_id,
|
|
||||||
&app_state.database_connection,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::ACCEPTED,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path((role_id, permission_id)): Path<(i64, i64)>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::delete(&role_id, &permission_id, &app_state.database_connection).await {
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::NO_CONTENT,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_all_for_role(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path(role_id): Path<i64>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::read_all_for_role(&role_id, &app_state.database_connection).await {
|
|
||||||
Ok(role_permissions) => (StatusCode::OK, Json(serde_json::json!(role_permissions))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_all_for_role(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path(role_id): Path<i64>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RolePermission::delete_all_for_role(&role_id, &app_state.database_connection).await {
|
|
||||||
Ok(role_permissions) => (StatusCode::OK, Json(serde_json::json!(role_permissions))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::IntoResponse,
|
|
||||||
routing::get,
|
|
||||||
Json, Router,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{feature::routing::Routing, AppState};
|
|
||||||
|
|
||||||
pub fn route(State(app_state): State<AppState>) -> Router<AppState> {
|
|
||||||
Router::new()
|
|
||||||
.route("/:id", get(read))
|
|
||||||
.route("/", get(read_all))
|
|
||||||
.with_state(app_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read(State(app_state): State<AppState>, Path(id): Path<i64>) -> impl IntoResponse {
|
|
||||||
match Routing::read(&id, &app_state.database_connection).await {
|
|
||||||
Ok(routing) => (StatusCode::OK, Json(serde_json::json!(routing))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_all(State(app_state): State<AppState>) -> impl IntoResponse {
|
|
||||||
match Routing::read_all(&app_state.database_connection).await {
|
|
||||||
Ok(routings) => (StatusCode::OK, Json(serde_json::json!(routings))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,144 +0,0 @@
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::IntoResponse,
|
|
||||||
routing::{delete, get, patch, post},
|
|
||||||
Json, Router,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{feature::routing_permission::RoutingPermission, AppState};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct CreateRoutingPermission {
|
|
||||||
pub routing_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct UpdateRoutingPermission {
|
|
||||||
pub routing_id: i64,
|
|
||||||
pub permission_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn route(State(app_state): State<AppState>) -> Router<AppState> {
|
|
||||||
Router::new()
|
|
||||||
.route("/", post(create))
|
|
||||||
.route(
|
|
||||||
"/routings/:routing_id/permissions/:permission_id",
|
|
||||||
get(read),
|
|
||||||
)
|
|
||||||
.route("/", patch(update))
|
|
||||||
.route(
|
|
||||||
"/routings/:routing_id/permissions/:permission_id",
|
|
||||||
delete(delete_),
|
|
||||||
)
|
|
||||||
.route("/routings/:routing_id", get(read_all_for_routing))
|
|
||||||
.route("/routings/:routing_id", delete(delete_all_for_routing))
|
|
||||||
.with_state(app_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(create_role_permission): Json<CreateRoutingPermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::create(
|
|
||||||
&create_role_permission.routing_id,
|
|
||||||
&create_role_permission.permission_id,
|
|
||||||
&app_state.database_connection,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::CREATED,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path((routing_id, permission_id)): Path<(i64, i64)>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::read(&routing_id, &permission_id, &app_state.database_connection).await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (StatusCode::OK, Json(serde_json::json!(role_permission))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Json(update_role): Json<UpdateRoutingPermission>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::update(
|
|
||||||
&update_role.routing_id,
|
|
||||||
&update_role.permission_id,
|
|
||||||
&app_state.database_connection,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::ACCEPTED,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path((routing_id, permission_id)): Path<(i64, i64)>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::delete(&routing_id, &permission_id, &app_state.database_connection)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permission) => (
|
|
||||||
StatusCode::NO_CONTENT,
|
|
||||||
Json(serde_json::json!(role_permission)),
|
|
||||||
),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_all_for_routing(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path(routing_id): Path<i64>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::read_all_for_routing(&routing_id, &app_state.database_connection).await
|
|
||||||
{
|
|
||||||
Ok(role_permissions) => (StatusCode::OK, Json(serde_json::json!(role_permissions))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_all_for_routing(
|
|
||||||
State(app_state): State<AppState>,
|
|
||||||
Path(routing_id): Path<i64>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match RoutingPermission::delete_all_for_routing(&routing_id, &app_state.database_connection)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(role_permissions) => (StatusCode::OK, Json(serde_json::json!(role_permissions))),
|
|
||||||
Err(err_val) => (
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
Json(serde_json::json!(err_val.to_string())),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue