| public class FileService : IFileService | public class FileService : IFileService | ||||
| { | { | ||||
| private readonly IConfiguration _configuration; | private readonly IConfiguration _configuration; | ||||
| public FileService(IConfiguration configuration) | |||||
| private readonly DatabaseContext _context; | |||||
| public FileService(IConfiguration configuration, DatabaseContext context) | |||||
| { | { | ||||
| _configuration = configuration; | _configuration = configuration; | ||||
| _context = context; | |||||
| } | } | ||||
| public async Task<string> GetCV(string fileName) | public async Task<string> GetCV(string fileName) | ||||
| { | { | ||||
| string base64 = Convert.ToBase64String(bytes); | string base64 = Convert.ToBase64String(bytes); | ||||
| return base64; | return base64; | ||||
| } | } | ||||
| public async Task<IEnumerable<FileEntity>> GetAll() | |||||
| { | |||||
| return await _context.Files.ToListAsync(); | |||||
| } | |||||
| } | } | ||||
| } | } |
| { | { | ||||
| Task<string> GetCV(string fileName); | Task<string> GetCV(string fileName); | ||||
| Task UploadCV(string fileName,IFormFile file); | Task UploadCV(string fileName,IFormFile file); | ||||
| Task<IEnumerable<FileEntity>> GetAll(); | |||||
| } | } | ||||
| } | } |
| | |||||
| using Diligent.WebAPI.Contracts.DTOs.Files; | |||||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||||
| { | |||||
| public interface ITagService | |||||
| { | |||||
| Task<FileFiltersReturnDTO> GetFilters(); | |||||
| } | |||||
| } |
| 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 | |||||
| }; | |||||
| } | |||||
| } | |||||
| } |
| 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; } | |||||
| } | |||||
| } |
| 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()); | |||||
| } | |||||
| } |
| 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()); | |||||
| } | |||||
| } |
| services.AddScoped<ISaveImportedDataService, SaveImportedDataService>(); | services.AddScoped<ISaveImportedDataService, SaveImportedDataService>(); | ||||
| services.AddScoped<IScreeningTestService, ScreeningTestService>(); | services.AddScoped<IScreeningTestService, ScreeningTestService>(); | ||||
| services.AddScoped<IFileService, FileService>(); | services.AddScoped<IFileService, FileService>(); | ||||
| services.AddScoped<ITagService, TagService>(); | |||||
| } | } | ||||
| /// <summary> | /// <summary> |