Exemple #1
0
 public static CardModel Create(UserModel user = null)
 {
     user ??= UserFaker.Create();
     return(CardRepository.CreateAndGet(
                "cardName_" + Rand.SmallInt(),
                "description" + Rand.SmallInt(),
                Rand.IntRange(0, 100),
                BoardColumnFaker.Create(user),
                user
                ));
 }
Exemple #2
0
        public void Create_Card()
        {
            var user        = UserFaker.Create();
            var column      = BoardColumnFaker.Create(user);
            var name        = "testName" + Rand.Int();
            var columnOrder = Rand.IntRange(1, 30);

            var card = CardRepository.CreateAndGet(name, "", columnOrder, column, user);

            card = CardRepository.Find(name, user, column);
            Assert.AreEqual(card.name, name);
            Assert.AreEqual(card.column_id, column.id);
        }
        public static void Run(DL.Model.Project.Project project, User creator)
        {
            if (creator != null)
            {
                ProjectTeamMemberRepository.CreateAndGet(project, creator);
                UserLibraryItemRepository.FindOrCreate(project.Creator(), project);
            }

            ProjectAliasRepository.Create(project);
            ProjectWorkUtils.SetUp(project);

            // Basic boards set up
            var board      = BoardRepository.CreateAndGet("Development", "Basic board", project, creator);
            var todoColumn = BoardColumnRepository.CreateAndGet("TODO", board, 1);

            BoardColumnRepository.CreateAndGet("In progress", board, 2);
            BoardColumnRepository.CreateAndGet("Done", board, 3);
            CardRepository.CreateAndGet(
                "Example card", DefaultCardDescription, 1, todoColumn, creator
                );
        }
Exemple #4
0
        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)));
            });
        }
Exemple #5
0
        public SyncIssues()
        {
            Post("/api/v1/schedule/issues/sync/start", _ => {
                var task = Task.Run(async() => {
                    var githubClient = GitHubApi.Client();

                    var projects = DL.Model.Project.Project.GetRandom(50);

                    foreach (var project in projects)
                    {
                        var board = project.Boards().First(x => x.name == "Development");
                        if (board == null)
                        {
                            continue;
                        }

                        var todoColumn = board.Columns().First(c => c.name == "TODO");
                        if (todoColumn == null)
                        {
                            continue;
                        }

                        try {
                            var originId = project.Repository().origin_id;
                            var issues   = githubClient.Issue.GetAllForRepository(
                                Convert.ToInt64(originId)
                                , new ApiOptions()
                            {
                                PageSize = 100
                            }
                                ).Result;
                            foreach (var issue in issues)
                            {
                                try {
                                    var existingCard = Card.FindBy("origin_id", issue.Id.ToString());
                                    if (existingCard != null)
                                    {
                                        continue;
                                    }
                                    var card = CardRepository.CreateAndGet(
                                        issue.Title, issue.Body ?? "", 1, todoColumn, null
                                        );
                                    card.UpdateCol("origin_id", issue.Id.ToString());
                                }
                                catch (Exception e) {
                                    Console.WriteLine(e.Message);
                                }
                            }
                        }
                        catch (AggregateException e) {
                            if (e.Message.Contains("API rate limit"))
                            {
                                Console.WriteLine("waiting");
                                await Task.Delay(GitHubApi.TimeUntilReset() * 1000);
                            }
                            else
                            {
                                SentrySdk.CaptureException(e);
                            }
                        }
                        catch (Exception e) {
                            Console.WriteLine(e.Message);
                            SentrySdk.CaptureException(e);
                        }
                    }

                    Console.WriteLine("Finished!");
                });
                JobsPool.Get().Push(task);
                return(HttpResponse.Data(new JObject()));
            });
        }