Skip to content

Commit 9b0dd03

Browse files
committed
[FEATURE] Import max size fixed.
1 parent 02f11d7 commit 9b0dd03

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[profile.dev]
9+
opt-level = 3
10+
11+
[profile.release]
12+
opt-level = 3
13+
814
[dependencies]
915
tokio = { version = "1", features = ["full"] }
1016
lazy_static = "1.4.0"

src/infrastructure/controller_collection.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use axum::{
2-
extract::Path,
2+
extract::{DefaultBodyLimit, Path},
33
http::StatusCode,
44
middleware,
55
response::IntoResponse,
@@ -10,7 +10,7 @@ use rust_db_manager_core::{
1010
commons::configuration::configuration::Configuration,
1111
domain::{
1212
collection::generate_collection_query::GenerateCollectionQuery,
13-
filter::{collection_query::CollectionQuery, data_base_query::DataBaseQuery, document_query::DocumentQuery},
13+
filter::{collection_query::CollectionQuery, data_base_query::DataBaseQuery},
1414
},
1515
};
1616

@@ -30,14 +30,15 @@ impl ControllerCollection {
3030

3131
pub fn route(router: Router) -> Router {
3232
router
33+
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/import", post(Self::import))
34+
.layer(DefaultBodyLimit::max(52428800 ))
3335
.route("/api/v1/service/:service/data-base/:data_base/collection", get(Self::find_all))
3436
.route("/api/v1/service/:service/data-base/:data_base/collection", post(Self::insert))
3537
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection", delete(Self::delete))
3638
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/metadata", get(Self::metadata))
3739
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/schema", get(Self::schema))
3840
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/rename", post(Self::rename))
3941
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/export", get(Self::export))
40-
.route("/api/v1/service/:service/data-base/:data_base/collection/:collection/import", post(Self::import))
4142
.route_layer(middleware::from_fn(handler::autentication_handler))
4243
}
4344

src/infrastructure/pagination.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,48 @@ impl Pagination {
66

77
pub fn paginate<T: Clone>(params: DTOQueryPagination, collection: Vec<T>) -> DTOPaginatedCollection<T> {
88
let size = collection.len();
9-
let offset = params.offset;
109
let limit = params.limit;
10+
let offset = params.offset;
1111

12-
if offset >= size {
13-
let previous = Pagination::calculate_previous(size, offset, limit);
12+
if limit >= size {
13+
let previous = Pagination::calculate_previous(size, limit, offset);
1414
return DTOPaginatedCollection::new(size, previous, size, Vec::new());
1515
}
1616

17-
if size == 0 || limit == 0 {
18-
return DTOPaginatedCollection::new(size, offset, offset, Vec::new());
17+
if size == 0 || offset == 0 {
18+
return DTOPaginatedCollection::new(size, limit, limit, Vec::new());
1919
}
2020

21-
let mut limit_fixed = limit;
22-
if offset + limit >= size {
23-
limit_fixed = size - offset;
21+
let mut offset_fixed = offset;
22+
if limit + offset >= size {
23+
offset_fixed = size - limit;
2424
}
2525

26-
let cursor = offset + limit_fixed;
26+
let cursor = limit + offset_fixed;
2727

28-
let next = Pagination::calculate_next(size, cursor, limit);
29-
let previous = Pagination::calculate_previous(size, cursor, limit);
28+
let next = Pagination::calculate_next(size, cursor, offset);
29+
let previous = Pagination::calculate_previous(size, cursor, offset);
3030

31-
let slice = collection[offset..=cursor-1].to_vec();
31+
let slice = collection[limit..=cursor-1].to_vec();
3232

3333
return DTOPaginatedCollection::new(size, previous, next, slice);
3434
}
3535

36-
fn calculate_next(size: usize, cursor: usize, limit: usize) -> usize {
37-
let next = cursor + limit;
36+
fn calculate_next(size: usize, cursor: usize, offset: usize) -> usize {
37+
let next = cursor + offset;
3838
if next >= size {
3939
return size;
4040
}
4141
return next;
4242
}
4343

44-
fn calculate_previous(size: usize, cursor: usize, limit: usize) -> usize {
45-
if cursor.checked_sub(limit).is_none() {
44+
fn calculate_previous(size: usize, cursor: usize, offset: usize) -> usize {
45+
if cursor.checked_sub(offset).is_none() {
4646
return 0;
4747
}
48-
let previous = cursor - limit;
48+
let previous = cursor - offset;
4949
if previous > size {
50-
return Pagination::calculate_previous(size, size, limit);
50+
return Pagination::calculate_previous(size, size, offset);
5151
}
5252
return previous;
5353
}

0 commit comments

Comments
 (0)