public CardController() { Get("/api/v1/card/get", _ => { var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameter("card_guid"), new ExistsInTable("card_guid", "cards", "guid") }); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } return(HttpResponse.Item("card", new CardTransformer().Transform( CardRepository.FindByGuid((string)Request.Query["card_guid"]) ))); }); Get("/api/v1/cards/get", _ => { var page = GetRequestInt("page"); page = page > 0 ? page : 1; var pageSize = 25; return(HttpResponse.Data(new JObject() { ["cards"] = new CardTransformer().Many( DL.Model.Card.Card.Paginate(page, pageSize) ), ["meta"] = new JObject() { ["pages_count"] = (DL.Model.Card.Card.Count() / pageSize) + 1, ["current_page"] = page } })); }); Get("/api/v1/project/cards/get", _ => { var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameter("project_guid"), new ExistsInTable("project_guid", "projects", "guid") }); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } var page = GetRequestInt("page"); page = page > 0 ? page : 1; var pageSize = 25; var project = ProjectRepository.FindByGuid(GetRequestStr("project_guid")); return(HttpResponse.Data(new JObject() { ["cards"] = new CardTransformer().Many(project.Cards(page, pageSize)), ["meta"] = new JObject() { ["pages_count"] = (project.CardsCount() / pageSize) + 1, ["current_page"] = page } })); }); Get("/api/v1/board_column/cards/get", _ => { var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameter("column_guid"), new ExistsInTable("column_guid", "board_columns", "guid") }); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } var column = BoardColumnRepository.FindByGuid(GetRequestStr("column_guid")); var page = GetRequestInt("page"); page = page > 0 ? page : 1; var pageSize = 25; return(HttpResponse.Data(new JObject() { ["cards"] = new CardTransformer().Many(column.Cards(page, pageSize)), ["meta"] = new JObject() { ["pages_count"] = (column.CardsCount() / pageSize) + 1, ["current_page"] = page } })); }); }
public CardCrudController() { Post("/api/v1/card/create", _ => { var me = UserRepository.Find(CurrentRequest.UserId); var column = BoardColumnRepository.FindByGuid(GetRequestStr("column_guid")); var board = column.Board(); var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameters(new[] { "name", "column_guid" }), new ExistsInTable("column_guid", "board_columns", "guid"), new HasPermission(me, board.id, EntityType.Board) }, true); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } var description = (string)Request.Query["description"] ?? ""; int columnOrder = Request.Query["column_order"] ?? 0; var card = CardRepository.CreateAndGet( (string)Request.Query["name"], description, columnOrder, column, me ); return(HttpResponse.Item( "card", new CardTransformer().Transform(card), HttpStatusCode.Created )); }); Patch("/api/v1/card/edit", _ => { var me = UserRepository.Find(CurrentRequest.UserId); var card = CardRepository.FindByGuid(GetRequestStr("card_guid")); var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameters(new[] { "card_guid" }), new ExistsInTable("card_guid", "cards", "guid"), new HasPermission(me, card.id, EntityType.Card) }, true); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } card = CardRepository.UpdateAndRefresh(card, new JObject() { ["name"] = GetRequestStr("name"), ["description"] = GetRequestStr("description"), ["column_order"] = GetRequestStr("column_order"), ["column_guid"] = GetRequestStr("column_guid"), }); return(HttpResponse.Item("card", new CardTransformer().Transform(card))); }); Delete("/api/v1/card/delete", _ => { var me = UserRepository.Find(CurrentRequest.UserId); var card = CardRepository.FindByGuid(GetRequestStr("card_guid")); var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameters(new[] { "card_guid" }), new ExistsInTable("card_guid", "cards", "guid"), new HasPermission(me, card.id, EntityType.Card) }, true); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } card.Delete(); return(HttpResponse.Item("card", new CardTransformer().Transform(card))); }); }