@@ -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