Skip to content

Commit

Permalink
[server] 모든 테이블/원하는 테이블의 정보를 반환하는 REST API 추가 및 API 네이밍 변경
Browse files Browse the repository at this point in the history
- 모든 테이블/원하는 테이블의 정보를 반환하는 REST API 추가
  1. GET tables/*/info
  2. POST tables/*/info
  3. GET types/*/info

- API URL 의 item 네이밍을 items 로 변경
  • Loading branch information
powerumc committed Aug 27, 2019
1 parent 67bc4b8 commit 8a3253a
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public string[] GetTableList(string databaseName, string tags = null)
{
var tables = dataBase.TableContext.Tables;
var query = from item in tables
where (item.TableInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
where (item.TableInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
return query.ToArray();
}

Expand All @@ -81,6 +81,46 @@ public IDictionary<int, object> GetTableData(string databaseName, string tableNa
});
}

[HttpGet]
[Route("tables/*/info")]
public GetTableInfoResponse[] GetTablesInfo(string databaseName, string tags = null, string columnTags = null)
{
var tables = this.GetTables(databaseName, tags);
return tables.Select(table =>
{
return table.Dispatcher.Invoke(() =>
{
var tableInfo = table.TableInfo;
if (!string.IsNullOrWhiteSpace(columnTags))
{
tableInfo = table.TableInfo.Filter((TagInfo)columnTags);
}

return GetTableInfoResponse.ConvertFrom(tableInfo);
});
}).ToArray();
}

[HttpPost]
[Route("tables/*/info")]
public GetTableInfoResponse[] GetTablesInfoByTableName(string databaseName, [FromBody] GetTableInfoByTableNameRequest request, string tags = null, string columnTags = null)
{
var tables = this.GetTables(databaseName, tags);
var intersectTables = tables.Select(table => table.Dispatcher.Invoke(() => table.TableName))
.Intersect(request.TableNames, StringComparer.OrdinalIgnoreCase);

return intersectTables.Select(tableName =>
{
var table = tables.First(o => o.Dispatcher.Invoke(() => o.TableName == tableName));
var tableInfo = table.Dispatcher.Invoke(() => table.TableInfo);
if (!string.IsNullOrWhiteSpace(columnTags))
{
tableInfo = tableInfo.Filter((TagInfo)columnTags);
}
return GetTableInfoResponse.ConvertFrom(tableInfo);
}).ToArray();
}

[HttpGet]
[Route("tables/{tableName}/info")]
public GetTableInfoResponse GetTableInfo(string databaseName, string tableName, string tags = null)
Expand All @@ -106,7 +146,7 @@ public GetTableInfoResponse GetTableInfo(string databaseName, string tableName,
public void CopyTable(string databaseName, string tableName, [FromBody] CopyTableRequest request)
{
var table = this.GetTable(databaseName, tableName);
table.Dispatcher.Invoke(() => table.Copy(this.Authentication, request.NewTableName,request.CategoryPath, request.CopyContent));
table.Dispatcher.Invoke(() => table.Copy(this.Authentication, request.NewTableName, request.CategoryPath, request.CopyContent));
}

[HttpDelete]
Expand Down Expand Up @@ -154,15 +194,15 @@ public ContainsTableResponse ContainsTable(string databaseName, string tableName
}

[HttpGet]
[Route("table-item")]
[Route("table-items")]
public string[] GetTableItemList(string databaseName)
{
var dataBase = this.GetDataBase(databaseName);
return dataBase.Dispatcher.Invoke(() => dataBase.TableContext.Select(item => item.Path).ToArray());
}

[HttpPost]
[Route("table-item/log")]
[Route("table-items/log")]
public GetTableItemLogInfoResponse[] GetTableItemLogInfo(string databaseName, [FromBody] GetTableItemLogInfoRequest request)
{
var tableItem = this.GetTableItem(databaseName, request.TableItemPath);
Expand All @@ -174,31 +214,31 @@ public GetTableItemLogInfoResponse[] GetTableItemLogInfo(string databaseName, [F
}

[HttpPut]
[Route("table-item/move")]
[Route("table-items/move")]
public void MoveTableItem(string databaseName, [FromBody] MoveTableItemRequest request)
{
var tableItem = this.GetTableItem(databaseName, request.TableItemPath);
tableItem.Dispatcher.Invoke(() => tableItem.Move(this.Authentication, request.ParentPath));
}

[HttpPut]
[Route("table-item/rename")]
[Route("table-items/rename")]
public void RenameTableItem(string databaseName, [FromBody] RenameTableItemRequest request)
{
var tableItem = this.GetTableItem(databaseName, request.TableItemPath);
tableItem.Dispatcher.Invoke(() => tableItem.Rename(this.Authentication, request.NewName));
}

[HttpPut]
[Route("table-item/delete")]
[Route("table-items/delete")]
public void DeleteTableItem(string databaseName, [FromBody] DeleteTableItemRequest request)
{
var tableItem = this.GetTableItem(databaseName, request.TableItemPath);
tableItem.Dispatcher.Invoke(() => tableItem.Delete(this.Authentication));
}

[HttpPost]
[Route("table-item/contains")]
[Route("table-items/contains")]
public ContainsTableItemResponse ContainsTableItem(string databaseName, [FromBody] ContainsTableItemRequest request)
{
var dataBase = this.GetDataBase(databaseName);
Expand All @@ -221,6 +261,34 @@ private IDataBase GetDataBase(string databaseName)
});
}

private ITable[] GetTables(string dataBaseName, string tags = null)
{
if (dataBaseName == null)
throw new ArgumentNullException(nameof(dataBaseName));

var dataBase = this.cremaHost.Dispatcher.Invoke(() =>
{
if (this.cremaHost.DataBases.Contains(dataBaseName) == false)
throw new DataBaseNotFoundException(dataBaseName);
return this.cremaHost.DataBases[dataBaseName];
});

return dataBase.Dispatcher.Invoke(() =>
{
if (tags == null)
{
var tables = dataBase.TableContext.Tables.ToArray();
return tables;
}
else
{
var tagInfo = (TagInfo)tags;
var tables = dataBase.TableContext.Tables.Where(table => (table.TableInfo.DerivedTags & tagInfo) != TagInfo.Unused).ToArray();
return tables;
}
});
}

private ITable GetTable(string dataBaseName, string tableName)
{
if (dataBaseName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public string[] GetTypeList(string databaseName, string tags = null)

var types = dataBase.TypeContext.Types;
var query = from item in types
where (item.TypeInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
where (item.TypeInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
return query.ToArray();
});
}
Expand All @@ -77,6 +77,19 @@ public IDictionary<int, object> GetTypeData(string databaseName, string typeName
});
}

[HttpGet]
[Route("types/*/info")]
public GetTypeInfoResponse[] GetTypeInfo(string databaseName)
{
var types = this.GetTypes(databaseName);

return types.Select(type => type.Dispatcher.Invoke(() =>
{
var typeInfo = type.TypeInfo;
return GetTypeInfoResponse.ConvertFrom(typeInfo);
})).ToArray();
}

[HttpGet]
[Route("types/{typeName}/info")]
public GetTypeInfoResponse GetTypeInfo(string databaseName, string typeName)
Expand Down Expand Up @@ -135,7 +148,7 @@ public ContainsTypeResponse ContainsType(string databaseName, string typeName)
}

[HttpGet]
[Route("type-item")]
[Route("type-items")]
public string[] GetTypeItemList(string databaseName, string tags = null)
{
var dataBase = this.GetDataBase(databaseName);
Expand All @@ -148,38 +161,38 @@ public string[] GetTypeItemList(string databaseName, string tags = null)

var types = dataBase.TypeContext.Types;
var query = from item in types
where (item.TypeInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
where (item.TypeInfo.DerivedTags & (TagInfo)tags) != TagInfo.Unused
select item.Name;
return query.ToArray();
});
}

[HttpPut]
[Route("type-item/delete")]
[Route("type-items/delete")]
public void DeleteTypeItem(string databaseName, [FromBody] DeleteTypeItemRequest request)
{
var typeItem = this.GetTypeItem(databaseName, request.TypeItemPath);
typeItem.Dispatcher.Invoke(() => typeItem.Delete(this.Authentication));
}

[HttpPut]
[Route("type-item/move")]
[Route("type-items/move")]
public void MoveTypeItem(string databaseName, [FromBody] MoveTypeItemRequest request)
{
var typeItem = this.GetTypeItem(databaseName, request.TypeItemPath);
typeItem.Dispatcher.Invoke(() => typeItem.Move(this.Authentication, request.ParentPath));
}

[HttpPut]
[Route("type-item/rename")]
[Route("type-items/rename")]
public void RenameTypeItem(string databaseName, [FromBody] RenameTypeItemRequest request)
{
var typeItem = this.GetTypeItem(databaseName, request.TypeItemPath);
typeItem.Dispatcher.Invoke(() => typeItem.Rename(this.Authentication, request.NewName));
}

[HttpPost]
[Route("type-item/contains")]
[Route("type-items/contains")]
public ContainsTypeItemResponse ContainsTypeItem(string databaseName, [FromBody] ContainsTypeItemRequest request)
{
var dataBase = this.GetDataBase(databaseName);
Expand All @@ -202,6 +215,25 @@ private IDataBase GetDataBase(string databaseName)
});
}

private IType[] GetTypes(string dataBaseName)
{
if (dataBaseName == null)
throw new ArgumentNullException(nameof(dataBaseName));

var dataBase = this.cremaHost.Dispatcher.Invoke(() =>
{
if (this.cremaHost.DataBases.Contains(dataBaseName) == false)
throw new DataBaseNotFoundException(dataBaseName);
return this.cremaHost.DataBases[dataBaseName];
});

return dataBase.Dispatcher.Invoke(() =>
{
var types = dataBase.TypeContext.Types;
return types.ToArray();
}).ToArray();
}

private IType GetType(string dataBaseName, string typeName)
{
if (dataBaseName == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ntreev.Crema.ServiceHosts.Http.Apis.V1.Requests.Commands
{
public class GetTableInfoByTableNameRequest
{
[Required]
public string[] TableNames { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Apis\CremaAuthorizeAttribute.cs" />
<Compile Include="Apis\CremaExceptionHandler.cs" />
<Compile Include="Apis\CremaHttpHostExtensions.cs" />
<Compile Include="Apis\V1\Requests\Commands\GetTableInfoByTableNameRequest.cs" />
<Compile Include="Apis\V1\Responses\Commands\LoginAndLoadEnterDataBaseResponse.cs" />
<Compile Include="HttpCommandServiceHost.cs" />
<Compile Include="Apis\MefDependencyResolver.cs" />
Expand Down

0 comments on commit 8a3253a

Please sign in to comment.