mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-11-24 23:25:37 +01:00
Add delete API
This commit is contained in:
parent
16a39af2f6
commit
55dba6ee11
@ -1,13 +1,12 @@
|
||||
namespace Giants.Services
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface IServerRegistryService
|
||||
{
|
||||
Task DeleteServer(string ipAddress);
|
||||
|
||||
Task<IEnumerable<ServerInfo>> GetAllServers();
|
||||
|
||||
Task AddServer(ServerInfo server);
|
||||
|
@ -85,6 +85,18 @@
|
||||
return serverInfo.Values;
|
||||
}
|
||||
|
||||
public async Task DeleteServer(string ipAddress)
|
||||
{
|
||||
ArgumentUtility.CheckStringForNullOrEmpty(ipAddress, nameof(ipAddress));
|
||||
|
||||
ServerInfo serverInfo = await this.registryStore.GetServerInfo(ipAddress);
|
||||
|
||||
if (serverInfo != null)
|
||||
{
|
||||
await this.registryStore.DeleteServer(serverInfo.id);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ConcurrentDictionary<string, ServerInfo>> PopulateCache(ICacheEntry entry)
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1);
|
||||
|
@ -58,6 +58,11 @@
|
||||
partitionKey: new PartitionKey(serverInfo.DocumentType));
|
||||
}
|
||||
|
||||
public async Task DeleteServer(string id, string partitionKey = null)
|
||||
{
|
||||
await this.client.DeleteItem<ServerInfo>(id, partitionKey);
|
||||
}
|
||||
|
||||
public async Task DeleteServers(IEnumerable<string> ids, string partitionKey = null)
|
||||
{
|
||||
ArgumentUtility.CheckEnumerableForNullOrEmpty(ids, nameof(ids));
|
||||
|
@ -9,6 +9,12 @@
|
||||
{
|
||||
Task Initialize();
|
||||
|
||||
Task DeleteServer(string id, string partitionKey = null);
|
||||
|
||||
Task DeleteServers(IEnumerable<string> ids, string partitionKey = null);
|
||||
|
||||
Task<ServerInfo> GetServerInfo(string ipAddress);
|
||||
|
||||
Task<IEnumerable<ServerInfo>> GetServerInfos(Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null);
|
||||
|
||||
Task<IEnumerable<TSelect>> GetServerInfos<TSelect>(
|
||||
@ -16,10 +22,6 @@
|
||||
Expression<Func<ServerInfo, bool>> whereExpression = null,
|
||||
string partitionKey = null);
|
||||
|
||||
Task<ServerInfo> GetServerInfo(string ipAddress);
|
||||
|
||||
Task UpsertServerInfo(ServerInfo serverInfo);
|
||||
|
||||
Task DeleteServers(IEnumerable<string> ids, string partitionKey = null);
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,26 @@
|
||||
|
||||
public Task<IEnumerable<ServerInfo>> GetServerInfos(Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
IQueryable<ServerInfo> serverInfoQuery = this.servers.Values.AsQueryable();
|
||||
|
||||
if (whereExpression != null)
|
||||
{
|
||||
serverInfoQuery = serverInfoQuery.Where(whereExpression);
|
||||
}
|
||||
|
||||
return Task.FromResult(serverInfoQuery.AsEnumerable());
|
||||
}
|
||||
|
||||
public Task<IEnumerable<TSelect>> GetServerInfos<TSelect>(Expression<Func<ServerInfo, TSelect>> selectExpression, Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
IQueryable<ServerInfo> serverInfoQuery = this.servers.Values.AsQueryable();
|
||||
|
||||
if (whereExpression != null)
|
||||
{
|
||||
serverInfoQuery = serverInfoQuery.Where(whereExpression);
|
||||
}
|
||||
|
||||
return Task.FromResult(serverInfoQuery.Select(selectExpression).AsEnumerable());
|
||||
}
|
||||
|
||||
public Task DeleteServers(IEnumerable<string> ids, string partitionKey = null)
|
||||
@ -55,5 +69,12 @@
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task DeleteServer(string id, string partitionKey = null)
|
||||
{
|
||||
this.servers.TryRemove(id, out ServerInfo _);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,16 @@ namespace Giants.Web.Controllers
|
||||
this.serverRegistryService = serverRegistryService;
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public async Task DeleteServer()
|
||||
{
|
||||
string requestIpAddress = this.GetRequestIpAddress();
|
||||
|
||||
this.logger.LogInformation("Deleting server from {IPAddress}", requestIpAddress);
|
||||
|
||||
await this.serverRegistryService.DeleteServer(requestIpAddress);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<DataContract.ServerInfoWithHostAddress>> GetServers()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user