Add items api route to WretchedMachines
This commit is contained in:
parent
1d15e937ac
commit
444bc76db0
11
WretchedMachines/API/Items.cs
Normal file
11
WretchedMachines/API/Items.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using WretchedMachines.DataAccess;
|
||||||
|
|
||||||
|
namespace WretchedMachines.API;
|
||||||
|
|
||||||
|
class Items
|
||||||
|
{
|
||||||
|
public static IResult GetItems(IDataAccess dataAccess)
|
||||||
|
{
|
||||||
|
return TypedResults.Ok(dataAccess.GetItems());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,9 +8,13 @@
|
|||||||
<p>Use this page to detail your site's privacy policy.</p>
|
<p>Use this page to detail your site's privacy policy.</p>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
@foreach(var item in Model.Items)
|
@{
|
||||||
|
if(Model.Items != null && Model.Items.Any()){
|
||||||
|
foreach(var item in Model.Items)
|
||||||
{
|
{
|
||||||
<li>@item.Id <span>@item.Name</span> @item.Price$</li>
|
<li>@item.Id <span>@item.Name</span> @item.Price$</li>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -1,5 +1,6 @@
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using WretchedMachines.DataAccess;
|
using WretchedMachines.DataAccess;
|
||||||
|
using WretchedMachines.API;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -9,10 +10,16 @@ Log.Logger = new LoggerConfiguration()
|
|||||||
|
|
||||||
Log.Information("Starting");
|
Log.Information("Starting");
|
||||||
builder.Host.UseSerilog();
|
builder.Host.UseSerilog();
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddScoped<IDataAccess, DataAccess>();
|
builder.Services.AddScoped<IDataAccess, DataAccess>();
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
RouteGroupBuilder api = app.MapGroup("/api");
|
||||||
|
|
||||||
|
api.MapGet("/items", Items.GetItems);
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@ -32,3 +39,4 @@ app.UseAuthorization();
|
|||||||
app.MapRazorPages();
|
app.MapRazorPages();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|||||||
25
WretchedMachines/WretchedMachines.sln
Normal file
25
WretchedMachines/WretchedMachines.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.002.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WretchedMachines", "WretchedMachines.csproj", "{991D6359-9E9B-4395-944C-208993435156}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{991D6359-9E9B-4395-944C-208993435156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{991D6359-9E9B-4395-944C-208993435156}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{991D6359-9E9B-4395-944C-208993435156}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{991D6359-9E9B-4395-944C-208993435156}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {E8EF6499-1ADC-4F72-B30E-AB47570659EF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Loading…
x
Reference in New Issue
Block a user