| @@ -11,12 +11,14 @@ | |||
| <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" /> | |||
| <PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" /> | |||
| <PackageReference Include="Bytescout.Spreadsheet" Version="4.6.0.2025" /> | |||
| <PackageReference Include="Dapper" Version="2.0.123" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.10" /> | |||
| <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.10" /> | |||
| <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.10" /> | |||
| <PackageReference Include="RestSharp" Version="108.0.2-alpha.0.6" /> | |||
| <PackageReference Include="System.Data.SqlClient" Version="4.8.5" /> | |||
| <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" /> | |||
| </ItemGroup> | |||
| @@ -0,0 +1,42 @@ | |||
| using Dapper; | |||
| using Diligent.WebAPI.Contracts.DTOs.Document; | |||
| using Microsoft.AspNetCore.Http; | |||
| using Microsoft.Extensions.Configuration; | |||
| using System.Data.SqlClient; | |||
| namespace Diligent.WebAPI.Business.Services | |||
| { | |||
| public class DocumentService : IDocumentService | |||
| { | |||
| private readonly IConfiguration _configuration; | |||
| public DocumentService(IConfiguration configuration) | |||
| { | |||
| _configuration = configuration; | |||
| } | |||
| public async Task<List<DocumentReadDTO>> GetAllDocuments() | |||
| { | |||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | |||
| var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore"); | |||
| return files.ToList(); | |||
| } | |||
| public async Task<List<DocumentReadDTO>> GetDocumentsByText(string text) | |||
| { | |||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | |||
| var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore where contains(file_stream, @text)", | |||
| new { text = text }); | |||
| return files.ToList(); | |||
| } | |||
| public async Task UploadDocument(IFormFile file) | |||
| { | |||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | |||
| var ms = new MemoryStream(); | |||
| file.CopyTo(ms); | |||
| var fileBytes = ms.ToArray(); | |||
| await connection.ExecuteAsync("insert into dbo.DocumentOrganizerDocStore (file_stream,name) values(@fileBytes,'neki2.txt')", | |||
| new { fileBytes = fileBytes }); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.Document; | |||
| using Microsoft.AspNetCore.Http; | |||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| public interface IDocumentService | |||
| { | |||
| Task<List<DocumentReadDTO>> GetAllDocuments(); | |||
| Task<List<DocumentReadDTO>> GetDocumentsByText(string text); | |||
| Task UploadDocument(IFormFile file); | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Document | |||
| { | |||
| public class DocumentReadDTO | |||
| { | |||
| public Guid stream_id { get; set; } | |||
| public byte[] File_stream { get; set; } | |||
| public string name { get; set; } | |||
| public string file_type { get; set; } | |||
| } | |||
| } | |||
| @@ -10,7 +10,7 @@ public static class ServiceCollection | |||
| if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") | |||
| { | |||
| options.EnableSensitiveDataLogging(); | |||
| secret = Environment.GetEnvironmentVariable("SECRET"); | |||
| secret = null; | |||
| } | |||
| var connectionString = configuration.GetConnectionString(nameof(Diligent.WebAPI)); | |||
| options.UseSqlServer(String.Concat(connectionString, secret)); | |||
| @@ -0,0 +1,28 @@ | |||
| namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| [ApiVersion("1.0")] | |||
| [Route("v{version:apiVersion}/documents")] | |||
| [ApiController] | |||
| public class DocumentController:ControllerBase | |||
| { | |||
| private readonly IDocumentService _documentService; | |||
| public DocumentController(IDocumentService documentService) | |||
| { | |||
| _documentService = documentService; | |||
| } | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetAllDocuments() => Ok(await _documentService.GetAllDocuments()); | |||
| [HttpGet("filter")] | |||
| public async Task<IActionResult> GetDocumentsByText(string text) => Ok(await _documentService.GetDocumentsByText(text)); | |||
| [HttpPost] | |||
| public async Task<IActionResult> UploadDocument(IFormFile file) | |||
| { | |||
| await _documentService.UploadDocument(file); | |||
| return Ok(); | |||
| } | |||
| } | |||
| } | |||
| @@ -44,6 +44,7 @@ namespace Diligent.WebAPI.Host.Extensions | |||
| services.AddScoped<IFileEntityService, FileEntityService>(); | |||
| services.AddScoped<ITagService, TagService>(); | |||
| services.AddScoped<ICategoryService, CategoryService>(); | |||
| services.AddScoped<IDocumentService, DocumentService>(); | |||
| } | |||
| /// <summary> | |||
| @@ -24,8 +24,7 @@ | |||
| "Enrich": [ "FromLogContext", "WithMachineName", "WtihThreadId", "WithExceptionDetails" ] | |||
| }, | |||
| "ConnectionStrings": { | |||
| //"WebApi": "Server=192.168.88.105;Database=DocumentOrganizer;User Id=hrcentar;Password=administrator#2021;" | |||
| "WebApi": "Server=.;Database=DocumentOrganizer;Trusted_Connection=True;MultipleActiveResultSets=true" | |||
| "WebApi": "Server=192.168.88.105;Database=DiligDocumentOrganizer;User Id=dzenis_hadzifejzovic;Password=;" | |||
| }, | |||
| "Authorization": { | |||
| "JwtExpiredTime": "5", | |||
| @@ -28,7 +28,7 @@ | |||
| "Enrich": [ "FromLogContext", "WithMachineName", "WtihThreadId", "WithExceptionDetails" ] | |||
| }, | |||
| "ConnectionStrings": { | |||
| "WebApi": "Server=192.168.88.105;Database=DocumentOrganizer;User Id=hrcentar;Password=administrator#2021;" | |||
| "WebApi": "Server=192.168.88.105;Database=DiligDocumentOrganizer;User Id=dzenis_hadzifejzovic;Password=;" | |||
| }, | |||
| "Authorization": { | |||
| "JwtExpiredTime": "5", | |||