Skip to content

Commit

Permalink
Feature/sc 1490/create basic crud operations for cli (#8)
Browse files Browse the repository at this point in the history
* CUD operations for environment

* EnvironmentClient API

* Domain API

* Removed unused import and variable

* Updated file location for log and state files

* CRUD commands
  • Loading branch information
jthind authored Nov 23, 2022
1 parent 13cb52f commit 5ee763b
Show file tree
Hide file tree
Showing 45 changed files with 1,149 additions and 51 deletions.
35 changes: 33 additions & 2 deletions src/Enterspeed.Cli/Api/Domain/CreateDomain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
namespace Enterspeed.Cli.Api.Domain;
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

internal class CreateDomain
namespace Enterspeed.Cli.Api.Domain;

public class CreateDomainRequest : IRequest<CreateDomainResponse>
{
public string Name { get; set; }
public string[] Hostnames { get; set; }
}

public class CreateDomainResponse
{
public DomainId DomainId { get; set; }
}

public class CreateDomainRequestRequestHandler : IRequestHandler<CreateDomainRequest, CreateDomainResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public CreateDomainRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<CreateDomainResponse> Handle(CreateDomainRequest createDomainRequest, CancellationToken cancellationToken)
{
var request = new RestRequest("tenant/domains", Method.Post)
.AddJsonBody(createDomainRequest);

var response = await _enterspeedClient.ExecuteAsync<CreateDomainResponse>(request, cancellationToken);
return response;
}
}
37 changes: 35 additions & 2 deletions src/Enterspeed.Cli/Api/Domain/DeleteDomain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
namespace Enterspeed.Cli.Api.Domain;
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

internal class DeleteDomain
namespace Enterspeed.Cli.Api.Domain;

public class DeleteDomainRequest : IRequest<DeleteDomainResponse>
{
public DomainId DomainId { get; }

public DeleteDomainRequest(DomainId domainId)
{
DomainId = domainId;
}
}

public class DeleteDomainResponse
{
}

public class DeleteEnvironmentRequestRequestHandler : IRequestHandler<DeleteDomainRequest, DeleteDomainResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public DeleteEnvironmentRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<DeleteDomainResponse> Handle(DeleteDomainRequest deleteDomainRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/domains/{deleteDomainRequest.DomainId.DomainGuid}", Method.Delete);

var response = await _enterspeedClient.ExecuteAsync<DeleteDomainResponse>(request, cancellationToken);
return response;
}
}
36 changes: 33 additions & 3 deletions src/Enterspeed.Cli/Api/Domain/UpdateDomain.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
using Enterspeed.Cli.Domain.Models;
using System.Text.Json.Serialization;
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

namespace Enterspeed.Cli.Api.Domain;

public class UpdateDomainRequest : IRequest<UpdateDomainResponse[]>
public class UpdateDomainRequest : IRequest<UpdateDomainResponse>
{
public DomainId DomainId { get; set; }
[JsonIgnore]
public DomainId DomainId { get; }
public string Name { get; set; }
public string[] Hostnames { get; set; }

public UpdateDomainRequest(DomainId domainId)
{
DomainId = domainId;
}
}

public class UpdateDomainResponse
Expand All @@ -18,4 +28,24 @@ public class UpdateDomainResponse
public string Name { get; set; }

public string[] Hostnames { get; set; }
}


public class UpdateDomainRequestRequestHandler : IRequestHandler<UpdateDomainRequest, UpdateDomainResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public UpdateDomainRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<UpdateDomainResponse> Handle(UpdateDomainRequest updateDomainRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/domains/{updateDomainRequest.DomainId.DomainGuid}", Method.Put)
.AddJsonBody(updateDomainRequest);

var response = await _enterspeedClient.ExecuteAsync<UpdateDomainResponse>(request, cancellationToken);
return response;
}
}
8 changes: 5 additions & 3 deletions src/Enterspeed.Cli/Api/Environment/CreateEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Enterspeed.Cli.Services.EnterspeedClient;
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

Expand All @@ -11,6 +12,7 @@ public class CreateEnvironmentRequest : IRequest<CreateEnvironmentResponse>

public class CreateEnvironmentResponse
{
public EnvironmentId EnvironmentId { get; set; }
}

public class CreateEnvironmentRequestRequestHandler : IRequestHandler<CreateEnvironmentRequest, CreateEnvironmentResponse>
Expand All @@ -22,10 +24,10 @@ public CreateEnvironmentRequestRequestHandler(IEnterspeedClient enterspeedClient
_enterspeedClient = enterspeedClient;
}

public async Task<CreateEnvironmentResponse> Handle(CreateEnvironmentRequest createEnvironmentsRequest, CancellationToken cancellationToken)
public async Task<CreateEnvironmentResponse> Handle(CreateEnvironmentRequest createEnvironmentRequest, CancellationToken cancellationToken)
{
var request = new RestRequest("tenant/environments", Method.Post)
.AddJsonBody(createEnvironmentsRequest);
.AddJsonBody(createEnvironmentRequest);

var response = await _enterspeedClient.ExecuteAsync<CreateEnvironmentResponse>(request, cancellationToken);
return response;
Expand Down
27 changes: 26 additions & 1 deletion src/Enterspeed.Cli/Api/Environment/DeleteEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

namespace Enterspeed.Cli.Api.Environment
{
public class DeleteEnvironmentRequest : IRequest<DeleteEnvironmentResponse>
{
public EnvironmentId EnvironmentId { get; set; }
public EnvironmentId EnvironmentId { get; }

public DeleteEnvironmentRequest(EnvironmentId environmentId)
{
EnvironmentId = environmentId;
}
}

public class DeleteEnvironmentResponse
{
}

public class DeleteEnvironmentRequestRequestHandler : IRequestHandler<DeleteEnvironmentRequest, DeleteEnvironmentResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public DeleteEnvironmentRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<DeleteEnvironmentResponse> Handle(DeleteEnvironmentRequest deleteEnvironmentsRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/environments/{deleteEnvironmentsRequest.EnvironmentId.EnvironmentGuid}", Method.Delete);

var response = await _enterspeedClient.ExecuteAsync<DeleteEnvironmentResponse>(request, cancellationToken);
return response;
}
}
}
32 changes: 30 additions & 2 deletions src/Enterspeed.Cli/Api/Environment/UpdateEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
using Enterspeed.Cli.Domain.Models;
using System.Text.Json.Serialization;
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;

namespace Enterspeed.Cli.Api.Environment
{
public class UpdateEnvironmentRequest : IRequest<UpdateEnvironmentResponse>
{
public EnvironmentId EnvironmentId { get; set; }
[JsonIgnore]
public EnvironmentId EnvironmentId { get; }
public string Name { get; set; }

public UpdateEnvironmentRequest(EnvironmentId environmentId)
{
EnvironmentId = environmentId;
}
}

public class UpdateEnvironmentResponse
{
}

public class UpdateEnvironmentRequestRequestHandler : IRequestHandler<UpdateEnvironmentRequest, UpdateEnvironmentResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public UpdateEnvironmentRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<UpdateEnvironmentResponse> Handle(UpdateEnvironmentRequest updateEnvironmentRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/environments/{updateEnvironmentRequest.EnvironmentId.EnvironmentGuid}", Method.Put)
.AddJsonBody(updateEnvironmentRequest);

var response = await _enterspeedClient.ExecuteAsync<UpdateEnvironmentResponse>(request, cancellationToken);
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;
using System.Text.Json.Serialization;

namespace Enterspeed.Cli.Api.EnvironmentClient
{
public class CreateEnvironmentClientRequest : IRequest<CreateEnvironmentClientResponse>
{
public string Name { get; set; }
public string[] AllowedDomains { get; set; }

public bool RegenerateAccessKey { get; set; }

[JsonIgnore]
public EnvironmentId EnvironmentId { get; }

public CreateEnvironmentClientRequest(EnvironmentId environmentId)
{
EnvironmentId = environmentId;
}
}

public class CreateEnvironmentClientResponse
{
public EnvironmentClientId EnvironmentClientId { get; set; }
}

public class CreateEnvironmentClientRequestRequestHandler : IRequestHandler<CreateEnvironmentClientRequest, CreateEnvironmentClientResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public CreateEnvironmentClientRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<CreateEnvironmentClientResponse> Handle(CreateEnvironmentClientRequest createEnvironmentClientRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/environment-clients/{createEnvironmentClientRequest.EnvironmentId.EnvironmentGuid}", Method.Post)
.AddJsonBody(createEnvironmentClientRequest);

var response = await _enterspeedClient.ExecuteAsync<CreateEnvironmentClientResponse>(request, cancellationToken);
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;
using System.Text.Json.Serialization;

namespace Enterspeed.Cli.Api.EnvironmentClient
{
public class DeleteEnvironmentClientRequest : IRequest<DeleteEnvironmentClientResponse>
{
[JsonIgnore]
public EnvironmentClientId EnvironmentClientId { get; }

public DeleteEnvironmentClientRequest(EnvironmentClientId environmentClientId)
{
EnvironmentClientId = environmentClientId;
}
}

public class DeleteEnvironmentClientResponse
{
}

public class DeleteEnvironmentClientRequestRequestHandler : IRequestHandler<DeleteEnvironmentClientRequest, DeleteEnvironmentClientResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public DeleteEnvironmentClientRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<DeleteEnvironmentClientResponse> Handle(DeleteEnvironmentClientRequest deleteEnvironmentClientRequest, CancellationToken cancellationToken)
{
var request =
new RestRequest(
$"tenant/environment-clients/{deleteEnvironmentClientRequest.EnvironmentClientId.EnvironmentGuid}/{deleteEnvironmentClientRequest.EnvironmentClientId.ClientGuid}/",
Method.Delete);

var response = await _enterspeedClient.ExecuteAsync<DeleteEnvironmentClientResponse>(request, cancellationToken);
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Enterspeed.Cli.Domain.Models;
using Enterspeed.Cli.Services.EnterspeedClient;
using MediatR;
using RestSharp;
using System.Text.Json.Serialization;

namespace Enterspeed.Cli.Api.EnvironmentClient
{
public class UpdateEnvironmentClientRequest : IRequest<UpdateEnvironmentClientResponse>
{
public string Name { get; set; }
public string[] AllowedDomains { get; set; }

public bool RegenerateAccessKey { get; set; }

[JsonIgnore]
public EnvironmentClientId EnvironmentClientId { get; }

public UpdateEnvironmentClientRequest(EnvironmentClientId environmentClientId)
{
EnvironmentClientId = environmentClientId;
}
}

public class UpdateEnvironmentClientResponse
{
public EnvironmentClientId EnvironmentClientId { get; set; }
}

public class UpdateEnvironmentClientRequestRequestHandler : IRequestHandler<UpdateEnvironmentClientRequest, UpdateEnvironmentClientResponse>
{
private readonly IEnterspeedClient _enterspeedClient;

public UpdateEnvironmentClientRequestRequestHandler(IEnterspeedClient enterspeedClient)
{
_enterspeedClient = enterspeedClient;
}

public async Task<UpdateEnvironmentClientResponse> Handle(UpdateEnvironmentClientRequest updateEnvironmentClientRequest, CancellationToken cancellationToken)
{
var request = new RestRequest($"tenant/environment-clients/{updateEnvironmentClientRequest.EnvironmentClientId.EnvironmentGuid}/{updateEnvironmentClientRequest.EnvironmentClientId.ClientGuid}/", Method.Put)
.AddJsonBody(updateEnvironmentClientRequest);

var response = await _enterspeedClient.ExecuteAsync<UpdateEnvironmentClientResponse>(request, cancellationToken);
return response;
}
}
}
Loading

0 comments on commit 5ee763b

Please sign in to comment.