| @@ -8,9 +8,11 @@ namespace Diligent.WebAPI.Business.Services | |||
| public class FileService : IFileService | |||
| { | |||
| private readonly IConfiguration _configuration; | |||
| public FileService(IConfiguration configuration) | |||
| private readonly DatabaseContext _context; | |||
| public FileService(IConfiguration configuration, DatabaseContext context) | |||
| { | |||
| _configuration = configuration; | |||
| _context = context; | |||
| } | |||
| public async Task<string> GetCV(string fileName) | |||
| { | |||
| @@ -49,5 +51,10 @@ namespace Diligent.WebAPI.Business.Services | |||
| string base64 = Convert.ToBase64String(bytes); | |||
| return base64; | |||
| } | |||
| public async Task<IEnumerable<FileEntity>> GetAll() | |||
| { | |||
| return await _context.Files.ToListAsync(); | |||
| } | |||
| } | |||
| } | |||
| @@ -6,5 +6,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| Task<string> GetCV(string fileName); | |||
| Task UploadCV(string fileName,IFormFile file); | |||
| Task<IEnumerable<FileEntity>> GetAll(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| | |||
| using Diligent.WebAPI.Contracts.DTOs.Files; | |||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| public interface ITagService | |||
| { | |||
| Task<FileFiltersReturnDTO> GetFilters(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,29 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.Files; | |||
| namespace Diligent.WebAPI.Business.Services | |||
| { | |||
| public class TagService : ITagService | |||
| { | |||
| private readonly DatabaseContext _databaseContext; | |||
| public TagService(DatabaseContext databaseContext) | |||
| { | |||
| _databaseContext = databaseContext; | |||
| } | |||
| public async Task<FileFiltersReturnDTO> GetFilters() | |||
| { | |||
| var categories = await _databaseContext.Categories.ToArrayAsync(); | |||
| var tags = await _databaseContext.Tags.ToArrayAsync(); | |||
| var extensions = await _databaseContext.Files | |||
| .Select(m => m.Extension).Distinct().ToArrayAsync(); | |||
| return new FileFiltersReturnDTO | |||
| { | |||
| Categories = categories, | |||
| Tags = tags, | |||
| Extensions = extensions | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| using Diligent.WebAPI.Data.Entities; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Files | |||
| { | |||
| public class FileFiltersReturnDTO | |||
| { | |||
| public Category[] Categories { get; set; } | |||
| public Tag[] Tags { get; set; } | |||
| public string[] Extensions { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| [ApiVersion("1.0")] | |||
| [Route("v{version:apiVersion}/files")] | |||
| [ApiController] | |||
| public class FilesController : ControllerBase | |||
| { | |||
| private readonly IFileService _fileService; | |||
| public FilesController(IFileService fileService) | |||
| { | |||
| _fileService = fileService; | |||
| } | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetAll() => Ok(await _fileService.GetAll()); | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| [ApiVersion("1.0")] | |||
| [Route("v{version:apiVersion}/tags")] | |||
| [ApiController] | |||
| public class TagsController : ControllerBase | |||
| { | |||
| private readonly ITagService _tagService; | |||
| public TagsController(ITagService tagService) | |||
| { | |||
| _tagService = tagService; | |||
| } | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetFileFilters() => Ok(await _tagService.GetFilters()); | |||
| } | |||
| } | |||
| @@ -41,6 +41,7 @@ namespace Diligent.WebAPI.Host.Extensions | |||
| services.AddScoped<ISaveImportedDataService, SaveImportedDataService>(); | |||
| services.AddScoped<IScreeningTestService, ScreeningTestService>(); | |||
| services.AddScoped<IFileService, FileService>(); | |||
| services.AddScoped<ITagService, TagService>(); | |||
| } | |||
| /// <summary> | |||