File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 7
7
using Micron . DL . Module . Controller ;
8
8
using Micron . DL . Module . Http ;
9
9
using Micron . DL . Module . Validator ;
10
+ using Newtonsoft . Json . Linq ;
10
11
11
12
namespace App . AL . Controller . Card {
12
13
public sealed class CardController : BaseController {
@@ -33,8 +34,21 @@ public CardController() {
33
34
if ( errors . Count > 0 ) return HttpResponse . Errors ( errors ) ;
34
35
35
36
var column = BoardColumnRepository . FindByGuid ( GetRequestStr ( "column_guid" ) ) ;
36
-
37
- return HttpResponse . Item ( "cards" , new CardTransformer ( ) . Many ( column . Cards ( ) ) ) ;
37
+
38
+ var page = GetRequestInt ( "page" ) ;
39
+ page = page > 0 ? page : 1 ;
40
+
41
+ var pageSize = 25 ;
42
+
43
+ return HttpResponse . Data ( new JObject ( ) {
44
+ [ "data" ] = new JObject ( ) {
45
+ [ "cards" ] = new CardTransformer ( ) . Many ( column . Cards ( page , pageSize ) )
46
+ } ,
47
+ [ "meta" ] = new JObject ( ) {
48
+ [ "pages_count" ] = ( column . CardsCount ( ) / pageSize ) + 1 ,
49
+ [ "current_page" ] = page
50
+ }
51
+ } ) ;
38
52
} ) ;
39
53
}
40
54
}
Original file line number Diff line number Diff line change @@ -56,16 +56,19 @@ public BoardColumn Save() {
56
56
57
57
public BoardColumn Refresh ( ) => Find ( id ) ;
58
58
59
- public static int Count ( ) => ExecuteScalarInt ( "SELECT count (*) FROM board_columns WHERE id = @id" ) ;
59
+ public static int Count ( ) => ExecuteScalarInt ( "SELECT COUNT (*) FROM board_columns WHERE id = @id" ) ;
60
60
61
61
public void Delete ( ) => ExecuteScalarInt ( "DELETE FROM board_columns WHERE id = @id" , new { id } ) ;
62
62
63
63
public BoardModel Board ( ) => BoardModel . Find ( board_id ) ;
64
64
65
- public Card . Card [ ] Cards ( int limit = 25 )
65
+ public Card . Card [ ] Cards ( int page = 1 , int limit = 25 )
66
66
=> Connection ( ) . Query < Card . Card > (
67
- @"SELECT * FROM cards WHERE column_id = @column_id LIMIT @limit" ,
68
- new { column_id = id , limit }
67
+ @"SELECT * FROM cards WHERE column_id = @column_id OFFSET @offset LIMIT @limit" ,
68
+ new { column_id = id , offset = ( ( page - 1 ) * limit ) , limit }
69
69
) . ToArray ( ) ;
70
+
71
+ public int CardsCount ( )
72
+ => ExecuteScalarInt ( "SELECT COUNT(*) FROM cards WHERE column_id = @id" , new { id } ) ;
70
73
}
71
74
}
You can’t perform that action at this time.
0 commit comments