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)));
        }
        public async Task <HATEOASResult> GetAsync(Guid id)
        {
            var row = await rowService.GetAsync(id);

            var rowResponse = RowConverter.GetRowResponse(row);

            return(this.HATEOASResult(rowResponse, (r) => Ok(r)));
        }
        public async Task <HATEOASResult> SearchAsync(Guid tableId, string keyword, string column)
        {
            var rows = await rowService.SearchByKeywordAsync(tableId, keyword, column);

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

            return(this.HATEOASResult(rowsResponse, (r) => Ok(r)));
        }
        public async Task <ActionResult <RowResponse> > CreateAsync([FromBody] Row row)
        {
            if (!await rowService.ValidateAsync(row))
            {
                return(BadRequest());
            }
            var createdRow = await rowService.CreateAsync(row);

            var rowResponse = RowConverter.GetRowResponse(createdRow);

            return(Ok(rowResponse));
        }
Пример #5
0
        public async Task SearchAsync()
        {
            // Arrange
            var table = new Table
            {
                Id         = Guid.NewGuid(),
                DatabaseId = Guid.NewGuid(),
                Name       = tableName,
                Schema     = JsonConvert.SerializeObject(new BrandTableSchema {
                    Name = StringType, Country = StringType
                })
            };

            var row1 = new Row
            {
                Id      = Guid.NewGuid(),
                TableId = table.Id,
                Content = JsonConvert.SerializeObject(new BrandTableSchema {
                    Name = row1Name, Country = row1Country
                })
            };

            var row2 = new Row
            {
                Id      = Guid.NewGuid(),
                TableId = table.Id,
                Content = JsonConvert.SerializeObject(new BrandTableSchema {
                    Name = row2Name, Country = row2Country
                })
            };

            using var context = new AzureSqlDbContext(DbContextUtilities.GetContextOptions());

            await context.Rows.AddAsync(row1);

            await context.Rows.AddAsync(row2);

            await context.Tables.AddAsync(table);

            await context.SaveChangesAsync();

            var rowService = new SqlRowService(context);

            // Act
            var result = await rowService.SearchByKeywordAsync(table.Id, searchKeyword, searchColumn);

            var resultResponse = result.Select(r => RowConverter.GetRowResponse(r)).ToList();

            // Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(1, resultResponse.Count);
            Assert.AreEqual(row2Name, resultResponse.FirstOrDefault().Content["name"]);
        }