started data layer

dev
Don Oerkfitz 3 years ago
parent fab692c15e
commit 082745ac25

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using OSI.API.Business.Database;
using OSI.API.Business.Objects;
namespace OSI.API.Business.DAO
{
public abstract class DAOBase<T> : MySQL
{
protected DAOBase(DBConnectionInformation connectionInformation) : base(connectionInformation)
{
}
protected DAOBase(string server, string database, string username, string password) : base(server, database, username, password)
{
}
public abstract List<T> GetAll();
public abstract T Get(int id);
public abstract void Create(T itemToCreate);
public abstract void Update(T itemToUpdate);
public abstract void Delete(int id);
}
}

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using OSI.API.Business.Database;
using OSI.API.Business.Objects;
namespace OSI.API.Business.DAO
{
public class InvoiceDAO : DAOBase<InvoiceObject>
{
public InvoiceDAO(DBConnectionInformation connectionInformation) : base(connectionInformation)
{
}
public InvoiceDAO(string server, string database, string username, string password) : base(server, database, username, password)
{
}
public override void Create(InvoiceObject itemToCreate)
{
throw new NotImplementedException();
}
public override void Delete(int id)
{
throw new NotImplementedException();
}
public override InvoiceObject Get(int id)
{
throw new NotImplementedException();
}
public override List<InvoiceObject> GetAll()
{
throw new NotImplementedException();
}
public override void Update(InvoiceObject itemToUpdate)
{
throw new NotImplementedException();
}
}
}

@ -89,20 +89,7 @@ namespace OSI.API.Business.Database
if (!DBReader.IsDBNull(columnID)) if (!DBReader.IsDBNull(columnID))
{ {
const int CHUNK_SIZE = 2 * 1024; rv = (byte[])DBReader[columnID];
byte[] buffer = new byte[CHUNK_SIZE];
long bytesRead;
long fieldOffset = 0;
using (var stream = new MemoryStream())
{
while ((bytesRead = DBReader.GetBytes(columnID, fieldOffset, buffer, 0, buffer.Length)) == buffer.Length)
{
stream.Write(buffer, 0, (int)bytesRead);
fieldOffset += bytesRead;
}
rv = stream.ToArray();
}
} }
return rv; return rv;

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using OSI.API.Business.Objects; using OSI.API.Business.Objects;
using OSI.API.Business.DAO;
namespace OSI.API.Controllers namespace OSI.API.Controllers
{ {
@ -20,12 +21,14 @@ namespace OSI.API.Controllers
public override IActionResult Get() public override IActionResult Get()
{ {
//> get all invoices as a list of InvoiceObjects //> get all invoices as a list of InvoiceObjects
throw new NotImplementedException(); using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation());
return new JsonResult(dao.GetAll());
} }
public override IActionResult Get(int id) public override IActionResult Get(int id)
{ {
return new JsonResult(id); using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation());
return new JsonResult(dao.Get(id));
} }
public override IActionResult Create([FromBody] InvoiceObject input) public override IActionResult Create([FromBody] InvoiceObject input)
@ -37,7 +40,7 @@ namespace OSI.API.Controllers
{ {
return CreatedAtAction( return CreatedAtAction(
"Get", "Get",
routeValues: new { id = input.InvoiceAmount }, routeValues: new { id = input.InvoiceNumber },
value: input value: input
); );
} }

@ -30,7 +30,7 @@ namespace OSI.API
services.AddControllers(); services.AddControllers();
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
{ {
c.SwaggerDoc("v1", new OpenApiInfo { Title = "OSI_API", Version = "v1" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "OSI.API", Version = "v1" });
}); });
services.AddApiVersioning(options => services.AddApiVersioning(options =>
@ -48,16 +48,13 @@ namespace OSI.API
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseSwagger(); app.UseSwagger();
// app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "OSI_API v1"));
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Delta.Net.Core.API v1"); c.SwaggerEndpoint("/swagger/v1/swagger.json", "OSI.API v1");
c.RoutePrefix = "api"; c.RoutePrefix = "api";
}); });
} }
// app.UseHttpsRedirection();
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();

Loading…
Cancel
Save