Skip to content

Commit

Permalink
modified: src/entities/category.rs
Browse files Browse the repository at this point in the history
	modified:   src/entities/product.rs
    modified:   src/main.rs
	modified:   src/routes/category_routes.rs
	modified:   src/routes/mod.rs
	new file:   src/routes/product_routes.rs
	modified:   src/routes/upload_routes.rs
  • Loading branch information
Tapo-o-chka committed Jan 4, 2025
1 parent d36be74 commit 5f0c410
Show file tree
Hide file tree
Showing 7 changed files with 894 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/entities/category.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use sea_orm::entity::prelude::*;
use serde::Serialize;
use crate::entities::image::Entity as Image;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize)]
#[sea_orm(table_name = "category")]
pub struct Model {
#[sea_orm(primary_key)]
Expand All @@ -22,7 +23,6 @@ pub enum Relation {
from = "crate::entities::category::Column::ImageId",
to = "crate::entities::image::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Image,
}
Expand Down
7 changes: 2 additions & 5 deletions src/entities/product.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use sea_orm::entity::prelude::*;
use serde::Serialize;
use crate::entities::category::Entity as Category;
use crate::entities::image::Entity as Image;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize)]
#[sea_orm(table_name = "products")]
pub struct Model {
#[sea_orm(primary_key)]
Expand All @@ -26,16 +27,12 @@ pub enum Relation {
belongs_to = "Category",
from = "crate::entities::product::Column::CategoryId",
to = "crate::entities::category::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Category,
#[sea_orm(
belongs_to = "Image",
from = "crate::entities::product::Column::ImageId",
to = "crate::entities::image::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Image,
}
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mod middleware;
use crate::entities::setup_schema;
use crate::routes::{
auth_routes::auth_routes,
category_routes::category_routes,
category_routes::{category_routes, admin_category_routes},
product_routes::{product_routes, admin_product_routes},
upload_routes::upload_routes
};

Expand All @@ -29,9 +30,19 @@ async fn main() {

let user_routes = auth_routes(shared_db.clone()).await;
let category_routes = category_routes(shared_db.clone()).await;
let admin_category_routes = admin_category_routes(shared_db.clone()).await;
let product_routes = product_routes(shared_db.clone()).await;
let admin_product_routes = admin_product_routes(shared_db.clone()).await;
let upload_routes = upload_routes(shared_db.clone()).await;

let app = Router::new().route("/", get(root)).nest("/", user_routes).nest("/api", category_routes).nest("/api2", upload_routes);
let app = Router::new()
.route("/", get(root))
.nest("/", user_routes)
.nest("/api", category_routes)
.nest("/api", product_routes)
.nest("/api", upload_routes)
.nest("/api/admin", admin_category_routes)
.nest("/api/admin", admin_product_routes);

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
println!("Running at {:?}", listener);
Expand Down
Loading

0 comments on commit 5f0c410

Please sign in to comment.