Skip to content

Commit e9b4fbc

Browse files
Format code
1 parent 556d1d2 commit e9b4fbc

File tree

15 files changed

+66
-62
lines changed

15 files changed

+66
-62
lines changed

packages/api/src/endpoints/books/create.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::sync::Arc;
33
use warp::Filter;
44

55
use application::books::{
6-
BookService,
7-
command_handlers::{CreateBookCommandHandler, CreateBookCommandHandlerTrait},
6+
BookService, CreateBookCommandHandler, CreateBookCommandHandlerTrait,
87
};
98
use domain::commands::CreateBookCommand;
109

packages/api/src/endpoints/books/delete.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::sync::Arc;
33
use warp::Filter;
44

55
use application::books::{
6-
BookService,
7-
command_handlers::{DeleteBookCommandHandler, DeleteBookCommandHandlerTrait},
6+
BookService, DeleteBookCommandHandler, DeleteBookCommandHandlerTrait,
87
};
98
use domain::commands::DeleteBookCommand;
109

packages/api/src/endpoints/books/get_by_id.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::sync::Arc;
33
use warp::Filter;
44

55
use application::books::{
6-
query_handlers::get_by_id_handler::{
7-
GetBookByIdQueryHandler, GetBookByIdQueryHandlerTrait,
8-
},
9-
service::BookService,
6+
BookService, GetBookByIdQueryHandler, GetBookByIdQueryHandlerTrait,
107
};
118
use domain::queries::GetBookByIdQuery;
129

packages/api/src/endpoints/books/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use warp::Filter;
44

55
use application::books::{
6-
BookService, UpdateBookCommandHandlerTrait, command_handlers::UpdateBookCommandHandler
6+
BookService, UpdateBookCommandHandler, UpdateBookCommandHandlerTrait,
77
};
88
use domain::commands::UpdateBookCommand;
99

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
pub mod get_all_handler;
22
pub mod get_by_id_handler;
3+
pub mod list_handler;
34

45
pub use get_all_handler::*;
5-
pub use get_by_id_handler::*;
6+
pub use get_by_id_handler::*;
7+
pub use list_handler::*;

packages/application/src/books/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use sea_orm::DbErr;
66
#[async_trait]
77
pub trait BookService: Send + Sync {
88
async fn get_all(&self) -> Result<Vec<Book>, DbErr>;
9-
async fn list(&self, page: u64, page_size: u64) -> Result<Paged<Book>, DbErr>;
9+
async fn list(&self, page: u64, page_size: u64)
10+
-> Result<Paged<Book>, DbErr>;
1011
async fn get_by_id(&self, id: i32) -> Result<Option<Book>, DbErr>;
1112
async fn get_available(&self) -> Result<Vec<Book>, DbErr>;
1213
async fn search(&self, query: BookQuery) -> Result<Vec<Book>, DbErr>;

packages/common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod app_error;
2-
pub mod server_error;
32
pub mod paged;
3+
pub mod server_error;
44

55
pub use app_error::*;
6+
pub use paged::*;
67
pub use server_error::*;
7-
pub use paged::*;

packages/database/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub mod database;
22
pub mod migrations;
33

4-
pub use database::Database;
4+
pub use database::Database;

packages/database/src/migrations/book.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,45 @@ pub struct Migration;
55

66
#[async_trait::async_trait]
77
impl MigrationTrait for Migration {
8-
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9-
manager
10-
.create_table(
11-
Table::create()
12-
.table("books")
13-
.if_not_exists()
14-
.col(
15-
ColumnDef::new(Book::Id)
16-
.integer()
17-
.not_null()
18-
.primary_key()
19-
.auto_increment(),
20-
)
21-
.col(ColumnDef::new(Book::Title).string().not_null())
22-
.col(ColumnDef::new(Book::Author).string().not_null())
23-
.col(ColumnDef::new(Book::Isbn).string().unique_key())
24-
.col(ColumnDef::new(Book::TotalCopies).integer().not_null())
25-
.col(ColumnDef::new(Book::AvailableCopies).integer().not_null())
26-
.col(ColumnDef::new(Book::PublishedYear).integer().null())
27-
.to_owned(),
28-
)
29-
.await
30-
}
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
manager
10+
.create_table(
11+
Table::create()
12+
.table("books")
13+
.if_not_exists()
14+
.col(
15+
ColumnDef::new(Book::Id)
16+
.integer()
17+
.not_null()
18+
.primary_key()
19+
.auto_increment(),
20+
)
21+
.col(ColumnDef::new(Book::Title).string().not_null())
22+
.col(ColumnDef::new(Book::Author).string().not_null())
23+
.col(ColumnDef::new(Book::Isbn).string().unique_key())
24+
.col(ColumnDef::new(Book::TotalCopies).integer().not_null())
25+
.col(ColumnDef::new(Book::AvailableCopies).integer().not_null())
26+
.col(ColumnDef::new(Book::PublishedYear).integer().null())
27+
.to_owned(),
28+
)
29+
.await
30+
}
3131

32-
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
33-
manager
34-
.drop_table(Table::drop().table(Book::Table).to_owned())
35-
.await
36-
}
32+
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
33+
manager
34+
.drop_table(Table::drop().table(Book::Table).to_owned())
35+
.await
36+
}
3737
}
3838

3939
#[derive(Iden)]
4040
enum Book {
41-
Table,
42-
Id,
43-
Title,
44-
Author,
45-
Isbn,
46-
TotalCopies,
47-
AvailableCopies,
48-
PublishedYear,
41+
Table,
42+
Id,
43+
Title,
44+
Author,
45+
Isbn,
46+
TotalCopies,
47+
AvailableCopies,
48+
PublishedYear,
4949
}

packages/domain/src/queries/book.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ pub struct GetBookByIdQuery {
88
#[derive(Debug, Clone, Serialize, Deserialize)]
99
pub struct GetAllBooksQuery;
1010

11+
#[derive(Debug, Clone, Serialize, Deserialize)]
12+
pub struct ListBooks {
13+
pub page: u64,
14+
pub page_size: u64,
15+
}
16+
1117
#[derive(Debug, Clone, Serialize, Deserialize)]
1218
pub struct GetAvailableBooksQuery;
1319

0 commit comments

Comments
 (0)