forked from moattarwork/Easify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of the minimal api
- Loading branch information
1 parent
8e5d207
commit 50fc3ae
Showing
44 changed files
with
1,410 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/AuthenticationController.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,41 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class AuthenticationController : Controller | ||
{ | ||
public AuthenticationController(ILogger<AuthenticationController> logger) | ||
{ | ||
Log = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
private ILogger<AuthenticationController> Log { get; } | ||
|
||
[HttpGet("secured")] | ||
[Authorize] | ||
public IActionResult GetSecured() | ||
{ | ||
return Ok(); | ||
} | ||
|
||
[HttpGet("unsecured")] | ||
public IActionResult GetUnsecured() | ||
{ | ||
return Ok(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/AutomapperController.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,56 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using LittleBlocks.Sample.Minimal.WebAPI.Domain; | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class AutomapperController : Controller | ||
{ | ||
private readonly ITypeMapper _mapper; | ||
|
||
public AutomapperController(ITypeMapper mapper) | ||
{ | ||
if (mapper == null) throw new ArgumentNullException(nameof(mapper)); | ||
_mapper = mapper; | ||
} | ||
|
||
[HttpGet("person/{firstname}/{lastname}")] | ||
public IActionResult GetPerson(string firstname, string lastname) | ||
{ | ||
var personToMap = new PersonEntity | ||
{ | ||
FirstName = firstname, | ||
LastName = lastname | ||
}; | ||
|
||
var person = _mapper.Map<PersonDo>(personToMap); | ||
return new ObjectResult(person); | ||
} | ||
|
||
[HttpGet("asset/{assetid}")] | ||
public IActionResult GetAsset(string assetid) | ||
{ | ||
var assetToMap = new AssetEntity | ||
{ | ||
Id = assetid | ||
}; | ||
|
||
var asset = _mapper.Map<AssetDo>(assetToMap); | ||
return new ObjectResult(asset); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/ConfigurationController.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,38 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class ConfigurationController : Controller | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public ConfigurationController(IConfiguration configuration) | ||
{ | ||
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); | ||
} | ||
|
||
[HttpGet("environment/{name}")] | ||
public IActionResult GetValidEnvironmentConfig(string name) | ||
{ | ||
var configItem = _configuration[name]; | ||
if (string.IsNullOrWhiteSpace(configItem)) | ||
return NotFound(); | ||
|
||
return Ok(configItem); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/ErrorsController.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,46 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using LittleBlocks.Sample.Minimal.WebAPI.Domain; | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class ErrorsController : Controller | ||
{ | ||
[HttpGet("{data}")] | ||
public IActionResult Get(string data) | ||
{ | ||
if (data == "throwFriendly") | ||
throw new OurApplicationException(); | ||
if (data == "throwUnfriendly") | ||
throw new Exception("Very bad exception!"); | ||
if (data == "throwThirdParty") | ||
throw new ThirdPartyPluginFailedException(); | ||
if (data == "throwHierarchy") | ||
{ | ||
var leafException1 = new OurApplicationException("My friendly leaf1!"); | ||
var leafException2 = new Exception("Security critical super secret!"); | ||
var leafException4 = new ThirdPartyPluginFailedException(); | ||
var leafException3 = new Exception("Security critical super secret #2!", leafException4); | ||
var aggregate = new AggregateException("Should not see me! (aggregate)", leafException1, leafException2, | ||
leafException3); | ||
throw new OurApplicationException("Admin root thrown!", aggregate); | ||
} | ||
|
||
return new ObjectResult(data); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/FeatureController.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,21 @@ | ||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class FeatureController : Controller | ||
{ | ||
private readonly IFeatureManager _featureManager; | ||
|
||
public FeatureController(IFeatureManager featureManager) | ||
{ | ||
_featureManager = featureManager ?? throw new ArgumentNullException(nameof(featureManager)); | ||
} | ||
|
||
[HttpGet("{name}")] | ||
public async Task<IActionResult> GetFeatureAvailability(string name) | ||
{ | ||
if (!await _featureManager.GetFeatureNamesAsync().AnyAsync(m => m == name)) | ||
return NotFound(false); | ||
|
||
return Ok(await _featureManager.IsEnabledAsync(name)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/LogsController.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,41 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class LogsController : Controller | ||
{ | ||
public LogsController(ILogger<LogsController> logger) | ||
{ | ||
Log = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
private ILogger<LogsController> Log { get; } | ||
|
||
[HttpGet] | ||
public IActionResult Get() | ||
{ | ||
Log.LogTrace("Trace"); | ||
Log.LogDebug("Debug"); | ||
Log.LogInformation("Information"); | ||
Log.LogWarning("Warning"); | ||
Log.LogError("Error"); | ||
Log.LogCritical("Critical"); | ||
|
||
return Ok(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/ServiceController.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,36 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using LittleBlocks.Sample.Minimal.WebAPI.Core; | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public class ServiceController : Controller | ||
{ | ||
private readonly IMyService _service; | ||
|
||
public ServiceController(IMyService service) | ||
{ | ||
_service = service ?? throw new ArgumentNullException(nameof(service)); | ||
} | ||
|
||
[HttpGet("{data}")] | ||
public string Get(string data) | ||
{ | ||
return _service.Process(data); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Samples/LittleBlocks.Sample.MinimalApi..WebAPI/Controllers/ValidationController.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,30 @@ | ||
// This software is part of the LittleBlocks framework | ||
// Copyright (C) 2024 LittleBlocks | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using LittleBlocks.Sample.Minimal.WebAPI.Domain; | ||
|
||
namespace LittleBlocks.Sample.Minimal.WebAPI.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
public sealed class ValidationController : Controller | ||
{ | ||
[Route("")] | ||
[HttpPost] | ||
public async Task<IActionResult> Post([FromBody] StoreDocumentsRequest request) | ||
{ | ||
return await Task.FromResult(Ok()); | ||
} | ||
} |
Oops, something went wrong.