working on base class and implementation

dev
Don Oerkfitz 4 years ago
parent 1991739287
commit db3c94b36e

@ -24,7 +24,8 @@
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
"enableStepFiltering": false
},
{
"name": ".NET Core Attach",

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>OSI_API.Business</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Restsharp" Version="106.11.7" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>
</Project>

@ -0,0 +1,9 @@
namespace OSI.API.Business.Objects
{
public class InvoiceObject
{
public int InvoiceNumber { get; set; }
public float InvoiceAmount { get; set; }
public float Discount { get; set; }
}
}

@ -4,43 +4,41 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OSI.API.Business.Objects;
namespace OSI.API.Controllers
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class InvoicesController : ControllerBase
public class InvoicesController : EndpointBase<InvoiceObject>
{
// GET: api/Invoices
[HttpGet]
public IEnumerable<string> Get()
public override IActionResult Delete(int id)
{
return new string[] { "value1", "value2" };
return NotFound();
}
// GET: api/Invoices/5
[HttpGet("{id}")]
public string Get(int id)
public override IActionResult Get()
{
return "value";
throw new NotImplementedException();
}
// POST: api/Invoices
[HttpPost]
public void Post([FromBody] string value)
public override IActionResult Get(int id)
{
return new JsonResult(id);
}
// PUT: api/Invoices/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
public override IActionResult Post([FromBody] InvoiceObject input)
{
throw new NotImplementedException();
}
// DELETE: api/Invoices/5
[HttpDelete("{id}")]
public void Delete(int id)
public override IActionResult Put(int id, [FromBody] InvoiceObject input)
{
return CreatedAtAction(
"Get",
routeValues: new { id = input.InvoiceAmount },
value: Get(id)
);
}
}
}

@ -0,0 +1,28 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace OSI.API.Controllers
{
public abstract class EndpointBase<A> : ControllerBase
{
[HttpGet]
public abstract IActionResult Get();
// GET: api/Clients/5
[HttpGet("{id}")]
public abstract IActionResult Get(int id);
// POST: api/Clients
[HttpPost]
public abstract IActionResult Post([FromBody] A input);
// PUT: api/Clients/5
[HttpPut("{id}")]
public abstract IActionResult Put(int id, [FromBody] A input);
// DELETE: api/Clients/5
[HttpDelete("{id}")]
public abstract IActionResult Delete(int id);
}
}

@ -11,4 +11,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OSI-API.Business\OSI-API.Business.csproj" />
</ItemGroup>
</Project>

@ -7,7 +7,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace OSI_API
namespace OSI.API
{
public class Program
{

@ -12,7 +12,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
namespace OSI_API
namespace OSI.API
{
public class Startup
{
@ -56,7 +56,7 @@ namespace OSI_API
});
}
app.UseHttpsRedirection();
// app.UseHttpsRedirection();
app.UseRouting();

Loading…
Cancel
Save