-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from engineering87/develop
Enhanced code
- Loading branch information
Showing
42 changed files
with
1,087 additions
and
751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/SharpConnector.Api/Controllers/ConnectorController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// (c) 2020 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using Microsoft.AspNetCore.Mvc; | ||
using SharpConnector.Interfaces; | ||
|
||
namespace SharpConnector.Api.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class ConnectorController : ControllerBase | ||
{ | ||
private readonly ISharpConnectorClient<string> _connectorClient; | ||
|
||
private readonly ILogger<ConnectorController> _logger; | ||
|
||
public ConnectorController(ILogger<ConnectorController> logger, ISharpConnectorClient<string> connectorClient) | ||
{ | ||
_logger = logger; | ||
_connectorClient = connectorClient; | ||
} | ||
|
||
[HttpGet("{key}", Name = "Get")] | ||
public ActionResult<string> Get(string key) | ||
{ | ||
var result = _connectorClient.Get(key); | ||
return result != null ? Ok(result) : NotFound(); | ||
} | ||
|
||
[HttpGet("async/{key}")] | ||
public async Task<ActionResult<string>> GetAsync(string key) | ||
{ | ||
var result = await _connectorClient.GetAsync(key); | ||
return result != null ? Ok(result) : NotFound(); | ||
} | ||
|
||
[HttpGet("all")] | ||
public ActionResult<IEnumerable<string>> GetAll() | ||
{ | ||
var results = _connectorClient.GetAll(); | ||
return Ok(results); | ||
} | ||
|
||
[HttpPost("insert")] | ||
public ActionResult<bool> Insert(string key, [FromBody] string value) | ||
{ | ||
var success = _connectorClient.Insert(key, value); | ||
return success ? Ok(success) : BadRequest("Insert failed."); | ||
} | ||
|
||
[HttpPost("insert/with-expiration")] | ||
public ActionResult<bool> Insert(string key, [FromBody] string value, TimeSpan expiration) | ||
{ | ||
var success = _connectorClient.Insert(key, value, expiration); | ||
return success ? Ok(success) : BadRequest("Insert with expiration failed."); | ||
} | ||
|
||
[HttpPost("insert-async")] | ||
public async Task<ActionResult<bool>> InsertAsync(string key, [FromBody] string value) | ||
{ | ||
var success = await _connectorClient.InsertAsync(key, value); | ||
return success ? Ok(success) : BadRequest("Async insert failed."); | ||
} | ||
|
||
[HttpPost("insert-async/with-expiration")] | ||
public async Task<ActionResult<bool>> InsertAsync(string key, [FromBody] string value, TimeSpan expiration) | ||
{ | ||
var success = await _connectorClient.InsertAsync(key, value, expiration); | ||
return success ? Ok(success) : BadRequest("Async insert with expiration failed."); | ||
} | ||
|
||
[HttpPost("insert-many")] | ||
public ActionResult<bool> InsertMany([FromBody] Dictionary<string, string> values) | ||
{ | ||
var success = _connectorClient.InsertMany(values); | ||
return success ? Ok(success) : BadRequest("Insert many failed."); | ||
} | ||
|
||
[HttpPost("insert-many/with-expiration")] | ||
public ActionResult<bool> InsertMany([FromBody] Dictionary<string, string> values, TimeSpan expiration) | ||
{ | ||
var success = _connectorClient.InsertMany(values, expiration); | ||
return success ? Ok(success) : BadRequest("Insert many with expiration failed."); | ||
} | ||
|
||
[HttpDelete("{key}")] | ||
public ActionResult<bool> Delete(string key) | ||
{ | ||
var success = _connectorClient.Delete(key); | ||
return success ? Ok(success) : NotFound("Delete failed."); | ||
} | ||
|
||
[HttpDelete("async/{key}")] | ||
public async Task<ActionResult<bool>> DeleteAsync(string key) | ||
{ | ||
var success = await _connectorClient.DeleteAsync(key); | ||
return success ? Ok(success) : NotFound("Async delete failed."); | ||
} | ||
|
||
[HttpPut("{key}")] | ||
public ActionResult<bool> Update(string key, [FromBody] string value) | ||
{ | ||
var success = _connectorClient.Update(key, value); | ||
return success ? Ok(success) : NotFound("Update failed."); | ||
} | ||
|
||
[HttpPut("async/{key}")] | ||
public async Task<ActionResult<bool>> UpdateAsync(string key, [FromBody] string value) | ||
{ | ||
var success = await _connectorClient.UpdateAsync(key, value); | ||
return success ? Ok(success) : NotFound("Async update failed."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// (c) 2020 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using SharpConnector.Middleware; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
// Register the SharpConnector services with string payload type. | ||
builder.Services.AddSharpConnectorServices<string>(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:44453", | ||
"sslPort": 44308 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5124", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7158;http://localhost:5124", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Remove="appsettings.litedb.json" /> | ||
<Content Remove="appsettings.memcached.json" /> | ||
<Content Remove="appsettings.mongodb.json" /> | ||
<Content Remove="appsettings.ravendb.json" /> | ||
<Content Remove="appsettings.redis.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="appsettings.litedb.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Include="appsettings.memcached.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Include="appsettings.mongodb.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Include="appsettings.ravendb.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Include="appsettings.redis.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SharpConnector\SharpConnector.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@SharpConnector.Api_HostAddress = http://localhost:5124 | ||
|
||
GET {{SharpConnector.Api_HostAddress}}/weatherforecast/ | ||
Accept: application/json | ||
|
||
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "RavenDb", | ||
"DatabaseName": "test", | ||
"ConnectionString": "http://live-test.ravendb.net" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
12 changes: 6 additions & 6 deletions
12
...arpConnector.Test/appsettings.litedb.json → ...harpConnector.Api/appsettings.litedb.json
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "LiteDb", | ||
"CollectionName": "test", | ||
"ConnectionString": "LiteDbTest.db" | ||
} | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "LiteDb", | ||
"CollectionName": "test", | ||
"ConnectionString": "LiteDbTest.db" | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...Connector.Test/appsettings.memcached.json → ...pConnector.Api/appsettings.memcached.json
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "Memcached", | ||
"ConnectionString": "127.0.0.1:11211" | ||
} | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "Memcached", | ||
"ConnectionString": "127.0.0.1:11211" | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...rpConnector.Test/appsettings.mongodb.json → ...arpConnector.Api/appsettings.mongodb.json
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "MongoDb", | ||
"DatabaseName": "test", | ||
"CollectionName": "test", | ||
"ConnectionString": "mongodb_connectionstring_here" | ||
} | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "MongoDb", | ||
"DatabaseName": "test", | ||
"CollectionName": "test", | ||
"ConnectionString": "mongodb_connectionstring_here" | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...rpConnector.Test/appsettings.ravendb.json → ...arpConnector.Api/appsettings.ravendb.json
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "RavenDb", | ||
"DatabaseName": "test", | ||
"ConnectionString": "http://live-test.ravendb.net" | ||
} | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "RavenDb", | ||
"DatabaseName": "test", | ||
"ConnectionString": "http://live-test.ravendb.net" | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...harpConnector.Test/appsettings.redis.json → ...SharpConnector.Api/appsettings.redis.json
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "Redis", | ||
"DatabaseNumber": 0, | ||
"ConnectionString": "redis_connectionstring_here" | ||
} | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "Redis", | ||
"DatabaseNumber": 0, | ||
"ConnectionString": "redis_connectionstring_here" | ||
} | ||
} |
Oops, something went wrong.