public async Task <HATEOASResult> GetByTableAsync(Guid tableId)
        {
            var rows = await rowService.GetAllAsync(tableId);

            var rowsResponse = rows.Select(r => RowConverter.GetRowResponse(r)).ToList();

            return(this.HATEOASResult(rowsResponse, (r) => Ok(r)));
        }
Beispiel #2
0
        public DBMSQuery(IDatabaseService databaseService, ITableService tableService, IRowService rowService,
                         IDatabaseHub databaseHub)
        {
            Name = nameof(DBMSQuery);

            Field <ListGraphType <DatabaseType> >("databases", "returns all the databases",
                                                  arguments: new QueryArguments(new List <QueryArgument>
            {
            }),
                                                  resolve: context =>
            {
                return(databaseService.GetAllAsync().Result);
            });

            Field <DatabaseType>("create_database", "creates a database",
                                 arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <StringGraphType>
                {
                    Name = "name"
                }
            }),
                                 resolve: context =>
            {
                var name     = context.GetArgument <string>("name");
                var database = new DbManager.Models.Database
                {
                    Id   = Guid.NewGuid(),
                    Name = name
                };
                var createdDatabase = databaseService.CreateAsync(database).Result;
                databaseHub.SendMessageAsync("database created");
                return(createdDatabase);
            });

            Field <ListGraphType <TableType> >("tables", "returns database tables",
                                               arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <StringGraphType>
                {
                    Name = "databaseId"
                }
            }),
                                               resolve: context =>
            {
                var databaseId = context.GetArgument <Guid?>("databaseId");
                return(tableService.GetAllAsync((Guid)databaseId).Result);
            });

            Field <ListGraphType <RowType> >("rows", "returns table rows",
                                             arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <StringGraphType>
                {
                    Name = "tableId"
                }
            }),
                                             resolve: context =>
            {
                var tableId = context.GetArgument <Guid?>("tableId");
                return(rowService.GetAllAsync((Guid)tableId).Result);
            });

            Field <ListGraphType <RowType> >("search", "returns table rows by search keyword",
                                             arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <StringGraphType>
                {
                    Name = "tableId"
                },
                new QueryArgument <StringGraphType>
                {
                    Name = "keyword"
                },
                new QueryArgument <StringGraphType>
                {
                    Name = "column"
                }
            }),
                                             resolve: context =>
            {
                var tableId = context.GetArgument <Guid?>("tableId");
                var keyword = context.GetArgument <string>("keyword");
                var column  = context.GetArgument <string>("column");
                return(rowService.SearchByKeywordAsync((Guid)tableId, keyword, column).Result);
            });
        }