Skip to content

Commit

Permalink
Initial implementation of the minimal api
Browse files Browse the repository at this point in the history
  • Loading branch information
moattarwork committed Feb 25, 2024
1 parent 8e5d207 commit 50fc3ae
Show file tree
Hide file tree
Showing 44 changed files with 1,410 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/LittleBlocks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extras", "Extras", "{B2C58A
..\GitVersion.yml = ..\GitVersion.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleBlocks.Sample.Minimal.WebAPI", "Samples\LittleBlocks.Sample.MinimalApi..WebAPI\LittleBlocks.Sample.Minimal.WebAPI.csproj", "{22C0106F-3EFC-46E4-863C-4861F794F917}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -216,6 +218,10 @@ Global
{0A9E6275-2F18-43DC-86DC-C3F3F37FB177}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A9E6275-2F18-43DC-86DC-C3F3F37FB177}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A9E6275-2F18-43DC-86DC-C3F3F37FB177}.Release|Any CPU.Build.0 = Release|Any CPU
{22C0106F-3EFC-46E4-863C-4861F794F917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22C0106F-3EFC-46E4-863C-4861F794F917}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22C0106F-3EFC-46E4-863C-4861F794F917}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22C0106F-3EFC-46E4-863C-4861F794F917}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -255,6 +261,7 @@ Global
{74F7FFB2-57CB-4217-976A-B0916B20AD05} = {C6B49B11-8BC9-4A68-9238-85BECC4BDF97}
{15A17D77-C9BE-4ADE-A42A-0DB5C88D4A0C} = {C6B49B11-8BC9-4A68-9238-85BECC4BDF97}
{0A9E6275-2F18-43DC-86DC-C3F3F37FB177} = {709EFF89-FE7B-4818-B435-856741E1C21B}
{22C0106F-3EFC-46E4-863C-4861F794F917} = {709EFF89-FE7B-4818-B435-856741E1C21B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AD317B39-D1E3-4033-A80A-C5F8CACAAF2C}
Expand Down
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();
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
}
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();
}
}
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);
}
}
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());
}
}
Loading

0 comments on commit 50fc3ae

Please sign in to comment.