diff --git a/OSI-API/Business/DAO/DAOBase.cs b/OSI-API/Business/DAO/DAOBase.cs new file mode 100644 index 0000000..913b214 --- /dev/null +++ b/OSI-API/Business/DAO/DAOBase.cs @@ -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 : 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 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); + } + +} \ No newline at end of file diff --git a/OSI-API/Business/DAO/InvoiceDAO.cs b/OSI-API/Business/DAO/InvoiceDAO.cs new file mode 100644 index 0000000..c1d57f2 --- /dev/null +++ b/OSI-API/Business/DAO/InvoiceDAO.cs @@ -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 + { + 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 GetAll() + { + throw new NotImplementedException(); + } + + public override void Update(InvoiceObject itemToUpdate) + { + throw new NotImplementedException(); + } + } + +} \ No newline at end of file diff --git a/OSI-API/Business/Database/MySQL/MySQL.cs b/OSI-API/Business/Database/MySQL/MySQL.cs index ecd1e8d..665b9b9 100644 --- a/OSI-API/Business/Database/MySQL/MySQL.cs +++ b/OSI-API/Business/Database/MySQL/MySQL.cs @@ -89,20 +89,7 @@ namespace OSI.API.Business.Database if (!DBReader.IsDBNull(columnID)) { - const int CHUNK_SIZE = 2 * 1024; - 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(); - } + rv = (byte[])DBReader[columnID]; } return rv; diff --git a/OSI-API/Controllers/InvoicesController.cs b/OSI-API/Controllers/InvoicesController.cs index cbc7eef..c85a905 100644 --- a/OSI-API/Controllers/InvoicesController.cs +++ b/OSI-API/Controllers/InvoicesController.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using OSI.API.Business.Objects; +using OSI.API.Business.DAO; namespace OSI.API.Controllers { @@ -20,12 +21,14 @@ namespace OSI.API.Controllers public override IActionResult Get() { //> 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) { - 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) @@ -37,7 +40,7 @@ namespace OSI.API.Controllers { return CreatedAtAction( "Get", - routeValues: new { id = input.InvoiceAmount }, + routeValues: new { id = input.InvoiceNumber }, value: input ); } diff --git a/OSI-API/Startup.cs b/OSI-API/Startup.cs index d122abf..60590b6 100644 --- a/OSI-API/Startup.cs +++ b/OSI-API/Startup.cs @@ -30,7 +30,7 @@ namespace OSI.API services.AddControllers(); 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 => @@ -48,16 +48,13 @@ namespace OSI.API { app.UseDeveloperExceptionPage(); app.UseSwagger(); - // app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "OSI_API v1")); 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"; }); } - // app.UseHttpsRedirection(); - app.UseRouting(); app.UseAuthorization();