11using App . DL . Repository . BoardColumn ;
22using App . DL . Repository . Card ;
3+ using App . DL . Repository . Project ;
34using App . PL . Transformer . Card ;
45using Micron . AL . Validation . Basic ;
56using Micron . AL . Validation . Db ;
67using Micron . DL . Middleware ;
78using Micron . DL . Module . Controller ;
89using Micron . DL . Module . Http ;
910using Micron . DL . Module . Validator ;
11+ using Newtonsoft . Json . Linq ;
1012
1113namespace App . AL . Controller . Card {
1214 public sealed class CardController : BaseController {
@@ -24,6 +26,45 @@ public CardController() {
2426 CardRepository . FindByGuid ( ( string ) Request . Query [ "card_guid" ] )
2527 ) ) ;
2628 } ) ;
29+
30+ Get ( "/api/v1/cards/get" , _ => {
31+ var page = GetRequestInt ( "page" ) ;
32+ page = page > 0 ? page : 1 ;
33+
34+ var pageSize = 25 ;
35+ return HttpResponse . Data ( new JObject ( ) {
36+ [ "cards" ] = new CardTransformer ( ) . Many (
37+ DL . Model . Card . Card . Paginate ( page , pageSize )
38+ ) ,
39+ [ "meta" ] = new JObject ( ) {
40+ [ "pages_count" ] = ( DL . Model . Card . Card . Count ( ) / pageSize ) + 1 ,
41+ [ "current_page" ] = page
42+ }
43+ } ) ;
44+ } ) ;
45+
46+ Get ( "/api/v1/project/cards/get" , _ => {
47+ var errors = ValidationProcessor . Process ( Request , new IValidatorRule [ ] {
48+ new ShouldHaveParameter ( "project_guid" ) ,
49+ new ExistsInTable ( "project_guid" , "projects" , "guid" )
50+ } ) ;
51+ if ( errors . Count > 0 ) return HttpResponse . Errors ( errors ) ;
52+
53+ var page = GetRequestInt ( "page" ) ;
54+ page = page > 0 ? page : 1 ;
55+
56+ var pageSize = 25 ;
57+
58+ var project = ProjectRepository . FindByGuid ( GetRequestStr ( "project_guid" ) ) ;
59+
60+ return HttpResponse . Data ( new JObject ( ) {
61+ [ "cards" ] = new CardTransformer ( ) . Many ( project . Cards ( page , pageSize ) ) ,
62+ [ "meta" ] = new JObject ( ) {
63+ [ "pages_count" ] = ( project . CardsCount ( ) / pageSize ) + 1 ,
64+ [ "current_page" ] = page
65+ }
66+ } ) ;
67+ } ) ;
2768
2869 Get ( "/api/v1/board_column/cards/get" , _ => {
2970 var errors = ValidationProcessor . Process ( Request , new IValidatorRule [ ] {
@@ -33,8 +74,19 @@ public CardController() {
3374 if ( errors . Count > 0 ) return HttpResponse . Errors ( errors ) ;
3475
3576 var column = BoardColumnRepository . FindByGuid ( GetRequestStr ( "column_guid" ) ) ;
36-
37- return HttpResponse . Item ( "cards" , new CardTransformer ( ) . Many ( column . Cards ( ) ) ) ;
77+
78+ var page = GetRequestInt ( "page" ) ;
79+ page = page > 0 ? page : 1 ;
80+
81+ var pageSize = 25 ;
82+
83+ return HttpResponse . Data ( new JObject ( ) {
84+ [ "cards" ] = new CardTransformer ( ) . Many ( column . Cards ( page , pageSize ) ) ,
85+ [ "meta" ] = new JObject ( ) {
86+ [ "pages_count" ] = ( column . CardsCount ( ) / pageSize ) + 1 ,
87+ [ "current_page" ] = page
88+ }
89+ } ) ;
3890 } ) ;
3991 }
4092 }
0 commit comments