Skip to content

Commit

Permalink
Add new API methods for repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Oct 17, 2018
1 parent 74599bd commit 6eccf78
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion Wirehome.Core/HTTP/Controllers/RepositoriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public RepositoriesController(RepositoryService repositoryService)
}

[HttpPost]
[Route("/api/v1/repositories/{type}/download")]
[Route("/api/v1/repositories/{type}/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadEntity(string type, string uid)
{
if (type == null) throw new ArgumentNullException(nameof(type));
if (uid == null) throw new ArgumentNullException(nameof(uid));

var typeBuffer = (RepositoryType)Enum.Parse(typeof(RepositoryType), type, true);
Expand All @@ -30,8 +31,61 @@ public async Task DownloadEntity(string type, string uid)
[ApiExplorerSettings(GroupName = "v1")]
public void DeleteEntity(string type, string uid)
{
if (type == null) throw new ArgumentNullException(nameof(type));
if (uid == null) throw new ArgumentNullException(nameof(uid));

var typeBuffer = (RepositoryType)Enum.Parse(typeof(RepositoryType), type, true);
_repositoryService.DeleteEntity(typeBuffer, RepositoryEntityUid.Parse(uid));
}

[HttpPost]
[Route("/api/v1/repositories/component_logics/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadComponentLogicEntity(string uid)
{
if (uid == null) throw new ArgumentNullException(nameof(uid));

await _repositoryService.DownloadEntityAsync(RepositoryType.ComponentLogics, RepositoryEntityUid.Parse(uid));
}

[HttpPost]
[Route("/api/v1/repositories/component_adapters/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadComponentAdapterEntity(string uid)
{
if (uid == null) throw new ArgumentNullException(nameof(uid));

await _repositoryService.DownloadEntityAsync(RepositoryType.ComponentAdapters, RepositoryEntityUid.Parse(uid));
}

[HttpPost]
[Route("/api/v1/repositories/services/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadServiceEntity(string uid)
{
if (uid == null) throw new ArgumentNullException(nameof(uid));

await _repositoryService.DownloadEntityAsync(RepositoryType.Services, RepositoryEntityUid.Parse(uid));
}

[HttpPost]
[Route("/api/v1/repositories/tools/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadToolEntity(string uid)
{
if (uid == null) throw new ArgumentNullException(nameof(uid));

await _repositoryService.DownloadEntityAsync(RepositoryType.Tools, RepositoryEntityUid.Parse(uid));
}

[HttpPost]
[Route("/api/v1/repositories/automations/{uid}/download")]
[ApiExplorerSettings(GroupName = "v1")]
public async Task DownloadAutomationEntity(string uid)
{
if (uid == null) throw new ArgumentNullException(nameof(uid));

await _repositoryService.DownloadEntityAsync(RepositoryType.Automations, RepositoryEntityUid.Parse(uid));
}
}
}

0 comments on commit 6eccf78

Please sign in to comment.