#5 Upload pdf files

Samengevoegd
bronjaermin heeft 1 commits samengevoegd van feature/upload_pdf naar BE_dev 3 jaren geleden
  1. 24
    0
      Diligent.WebAPI.Business/MappingProfiles/CategoryMappingProfile.cs
  2. 22
    0
      Diligent.WebAPI.Business/MappingProfiles/FileMappingProfile.cs
  3. 24
    0
      Diligent.WebAPI.Business/MappingProfiles/TagMappingProfile.cs
  4. 27
    0
      Diligent.WebAPI.Business/Services/CategoryService.cs
  5. 39
    0
      Diligent.WebAPI.Business/Services/FileEntityService.cs
  6. 0
    5
      Diligent.WebAPI.Business/Services/FileService.cs
  7. 15
    0
      Diligent.WebAPI.Business/Services/Interfaces/ICategoryService.cs
  8. 16
    0
      Diligent.WebAPI.Business/Services/Interfaces/IFileEntityService.cs
  9. 0
    1
      Diligent.WebAPI.Business/Services/Interfaces/IFileService.cs
  10. 4
    0
      Diligent.WebAPI.Business/Services/Interfaces/ITagService.cs
  11. 13
    2
      Diligent.WebAPI.Business/Services/TagService.cs
  12. 15
    0
      Diligent.WebAPI.Contracts/DTOs/Categories/CategoriesNamesResponse.cs
  13. 19
    0
      Diligent.WebAPI.Contracts/DTOs/Categories/CategoryResponse.cs
  14. 17
    0
      Diligent.WebAPI.Contracts/DTOs/File/CreateFileDto.cs
  15. 18
    0
      Diligent.WebAPI.Contracts/DTOs/File/CreateFileRequest.cs
  16. 23
    0
      Diligent.WebAPI.Contracts/DTOs/File/FileEntityResponse.cs
  17. 15
    0
      Diligent.WebAPI.Contracts/DTOs/Tags/TagNameResponse.cs
  18. 15
    0
      Diligent.WebAPI.Contracts/DTOs/Tags/TagResponse.cs
  19. 1
    4
      Diligent.WebAPI.Data/Entities/Category.cs
  20. 5
    1
      Diligent.WebAPI.Data/Entities/FileEntity.cs
  21. 20
    20
      Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.Designer.cs
  22. 20
    20
      Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.cs
  23. 18
    18
      Diligent.WebAPI.Data/Migrations/DatabaseContextModelSnapshot.cs
  24. 21
    0
      Diligent.WebAPI.Host/Controllers/V1/CategoriesController.cs
  25. 33
    5
      Diligent.WebAPI.Host/Controllers/V1/FilesController.cs
  26. 9
    2
      Diligent.WebAPI.Host/Controllers/V1/TagsController.cs
  27. 1
    0
      Diligent.WebAPI.Host/Diligent.WebAPI.Host.csproj
  28. 2
    0
      Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs
  29. 21
    0
      Diligent.WebAPI.Host/Methods/Upload.cs
  30. 0
    0
      Diligent.WebAPI.Host/wwwroot/files/fileToUplo231121108.pdf
  31. 0
    0
      Diligent.WebAPI.Host/wwwroot/files/fileToUplo233550096.pdf

+ 24
- 0
Diligent.WebAPI.Business/MappingProfiles/CategoryMappingProfile.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Categories;
using Diligent.WebAPI.Contracts.DTOs.File;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.MappingProfiles
{
public class CategoryMappingProfile : Profile
{
public CategoryMappingProfile()
{
#region DTO to Model
CreateMap<Category, CategoryResponse>();
CreateMap<Category, CategoriesNamesResponse>();
#endregion

#region Model to DTO
#endregion
}
}
}

+ 22
- 0
Diligent.WebAPI.Business/MappingProfiles/FileMappingProfile.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.File;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.MappingProfiles
{
public class FileMappingProfile : Profile
{
public FileMappingProfile()
{
#region DTO to Model
CreateMap<FileEntity, FileEntityResponse>();
#endregion

#region Model to DTO
#endregion
}
}
}

+ 24
- 0
Diligent.WebAPI.Business/MappingProfiles/TagMappingProfile.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Categories;
using Diligent.WebAPI.Contracts.DTOs.Tags;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.MappingProfiles
{
public class TagMappingProfile : Profile
{
public TagMappingProfile()
{
#region DTO to Model
CreateMap<Tag, TagResponse>();
CreateMap<Tag, TagNameResponse>();
#endregion

#region Model to DTO
#endregion
}
}
}

+ 27
- 0
Diligent.WebAPI.Business/Services/CategoryService.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Categories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services
{
public class CategoryService : ICategoryService
{
private readonly DatabaseContext _context;
private readonly IMapper _mapper;

public CategoryService(DatabaseContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}

public async Task<List<CategoriesNamesResponse>> GetCategoriesNamesAsync() =>
_mapper.Map<List<CategoriesNamesResponse>>(await _context.Categories.ToListAsync());

public async Task<Category> GetCategoryEntityById(int id) =>
await _context.Categories.Where(x => x.Id == id).FirstOrDefaultAsync();
}
}

+ 39
- 0
Diligent.WebAPI.Business/Services/FileEntityService.cs Bestand weergeven

using Azure.Core;
using Diligent.WebAPI.Contracts.DTOs.File;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services
{
public class FileEntityService : IFileEntityService
{
private readonly ILogger<FileEntityService> _logger;
private readonly DatabaseContext _context;
private readonly IMapper _mapper;

public FileEntityService(DatabaseContext context, ILogger<FileEntityService> logger, IMapper mapper)
{
_context = context;
_logger = logger;
_mapper = mapper;
}

public async Task<List<FileEntityResponse>> GetAllAsync() =>
_mapper.Map<List<FileEntityResponse>>(await _context.Files.Include(x => x.Tags).ToListAsync());

public async Task UploadPdfAsync(FileEntity file)
{
await _context.Files.AddAsync(file);

await _context.SaveChangesAsync();
}

public async Task<IEnumerable<FileEntity>> GetAll()
{
return await _context.Files.ToListAsync();
}
}
}

+ 0
- 5
Diligent.WebAPI.Business/Services/FileService.cs Bestand weergeven

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();
}
} }
} }

+ 15
- 0
Diligent.WebAPI.Business/Services/Interfaces/ICategoryService.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Categories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services.Interfaces
{
public interface ICategoryService
{
Task<List<CategoriesNamesResponse>> GetCategoriesNamesAsync();
Task<Category> GetCategoryEntityById(int id);
}
}

+ 16
- 0
Diligent.WebAPI.Business/Services/Interfaces/IFileEntityService.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.File;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services.Interfaces
{
public interface IFileEntityService
{
Task<List<FileEntityResponse>> GetAllAsync();
Task UploadPdfAsync(FileEntity file);
Task<IEnumerable<FileEntity>> GetAll();
}
}

+ 0
- 1
Diligent.WebAPI.Business/Services/Interfaces/IFileService.cs Bestand weergeven

{ {
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();
} }
} }

+ 4
- 0
Diligent.WebAPI.Business/Services/Interfaces/ITagService.cs Bestand weergeven

 
using Diligent.WebAPI.Contracts.DTOs.Files; using Diligent.WebAPI.Contracts.DTOs.Files;
using Diligent.WebAPI.Contracts.DTOs.Tags;


namespace Diligent.WebAPI.Business.Services.Interfaces namespace Diligent.WebAPI.Business.Services.Interfaces
{ {
public interface ITagService public interface ITagService
{ {
Task<FileFiltersReturnDTO> GetFilters(); Task<FileFiltersReturnDTO> GetFilters();
Task<List<TagNameResponse>> GetTagsNames();
Task<Tag> GetTagEntityById(int id);

} }
} }

+ 13
- 2
Diligent.WebAPI.Business/Services/TagService.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Files;
using Diligent.WebAPI.Contracts.DTOs.Categories;
using Diligent.WebAPI.Contracts.DTOs.Files;
using Diligent.WebAPI.Contracts.DTOs.Tags;
using Microsoft.EntityFrameworkCore;


namespace Diligent.WebAPI.Business.Services namespace Diligent.WebAPI.Business.Services
{ {
public class TagService : ITagService public class TagService : ITagService
{ {
private readonly DatabaseContext _databaseContext; private readonly DatabaseContext _databaseContext;
private readonly IMapper _mapper;


public TagService(DatabaseContext databaseContext)
public TagService(DatabaseContext databaseContext, IMapper mapper)
{ {
_databaseContext = databaseContext; _databaseContext = databaseContext;
_mapper = mapper;
} }


public async Task<FileFiltersReturnDTO> GetFilters() public async Task<FileFiltersReturnDTO> GetFilters()
Extensions = extensions Extensions = extensions
}; };
} }

public async Task<List<TagNameResponse>> GetTagsNames() =>
_mapper.Map<List<TagNameResponse>>(await _databaseContext.Tags.ToListAsync());

public async Task<Tag> GetTagEntityById(int id) =>
await _databaseContext.Tags.Where(x => x.Id == id).FirstOrDefaultAsync();
} }
} }

+ 15
- 0
Diligent.WebAPI.Contracts/DTOs/Categories/CategoriesNamesResponse.cs Bestand weergeven

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.Categories
{
public class CategoriesNamesResponse
{
public int Id { get; set; }

public string Name { get; set; }
}
}

+ 19
- 0
Diligent.WebAPI.Contracts/DTOs/Categories/CategoryResponse.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.File;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.Categories
{
public class CategoryResponse
{
public int Id { get; set; }

public string Name { get; set; }

public List<FileEntityResponse> Files { get; set; }
}
}

+ 17
- 0
Diligent.WebAPI.Contracts/DTOs/File/CreateFileDto.cs Bestand weergeven

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.File
{
public class CreateFileDto
{
public int CategoryId { get; set; }

public int[] TagsIds { get; set; }

public string UploadedFile { get; set; }
}
}

+ 18
- 0
Diligent.WebAPI.Contracts/DTOs/File/CreateFileRequest.cs Bestand weergeven

using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.File
{
public class CreateFileRequest
{
public int CategoryId { get; set; }

public int[] TagsIds { get; set; }

public IFormFile FileToUpload { get; set; }
}
}

+ 23
- 0
Diligent.WebAPI.Contracts/DTOs/File/FileEntityResponse.cs Bestand weergeven

using Diligent.WebAPI.Contracts.DTOs.Categories;
using Diligent.WebAPI.Contracts.DTOs.Tags;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.File
{
public class FileEntityResponse
{
public int Id { get; set; }

public string Name { get; set; }

public long Size { get; set; }

public string Extension { get; set; }

public List<TagResponse> Tags { get; set; }
}
}

+ 15
- 0
Diligent.WebAPI.Contracts/DTOs/Tags/TagNameResponse.cs Bestand weergeven

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.Tags
{
public class TagNameResponse
{
public int Id { get; set; }

public string Name { get; set; }
}
}

+ 15
- 0
Diligent.WebAPI.Contracts/DTOs/Tags/TagResponse.cs Bestand weergeven

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.Tags
{
public class TagResponse
{
public int Id { get; set; }

public string Name { get; set; }
}
}

+ 1
- 4
Diligent.WebAPI.Data/Entities/Category.cs Bestand weergeven



public string Name { get; set; } public string Name { get; set; }


[ForeignKey(nameof(File))]
public int FileId { get; set; }

public FileEntity File { get; set; }
public List<FileEntity> Files { get; set; }
} }
} }

+ 5
- 1
Diligent.WebAPI.Data/Entities/FileEntity.cs Bestand weergeven

using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;


public string Extension { get; set; } public string Extension { get; set; }


public List<Category> Categories { get; set; }
[ForeignKey(nameof(Category))]
public int CategoryId { get; set; }

public Category Category { get; set; }


public List<Tag> Tags { get; set; } public List<Tag> Tags { get; set; }
} }

Diligent.WebAPI.Data/Migrations/20230203064003_AddedFileEntity.Designer.cs → Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.Designer.cs Bestand weergeven

namespace Diligent.WebAPI.Data.Migrations namespace Diligent.WebAPI.Data.Migrations
{ {
[DbContext(typeof(DatabaseContext))] [DbContext(typeof(DatabaseContext))]
[Migration("20230203064003_AddedFileEntity")]
partial class AddedFileEntity
[Migration("20230203145727_AddedFileAndCategoryAndTagEntities")]
partial class AddedFileAndCategoryAndTagEntities
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {


SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);


b.Property<int>("FileId")
.HasColumnType("int");

b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");


b.HasKey("Id"); b.HasKey("Id");


b.HasIndex("FileId");

b.ToTable("Categories"); b.ToTable("Categories");
}); });




SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);


b.Property<int>("CategoryId")
.HasColumnType("int");

b.Property<string>("Extension") b.Property<string>("Extension")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");


b.HasKey("Id"); b.HasKey("Id");


b.HasIndex("CategoryId");

b.ToTable("Files"); b.ToTable("Files");
}); });


.IsRequired(); .IsRequired();
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.FileEntity", "File")
.WithMany("Categories")
.HasForeignKey("FileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("File");
});

modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Comment", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Comment", b =>
{ {
b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant") b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant")
b.Navigation("User"); b.Navigation("User");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.FileEntity", b =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Category", "Category")
.WithMany("Files")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Category");
});

modelBuilder.Entity("Diligent.WebAPI.Data.Entities.InsurancePolicy", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.InsurancePolicy", b =>
{ {
b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer") b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer")
b.Navigation("TechnologyApplicants"); b.Navigation("TechnologyApplicants");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.FileEntity", b =>
modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b =>
{ {
b.Navigation("Categories");
b.Navigation("Files");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b =>

Diligent.WebAPI.Data/Migrations/20230203064003_AddedFileEntity.cs → Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.cs Bestand weergeven



namespace Diligent.WebAPI.Data.Migrations namespace Diligent.WebAPI.Data.Migrations
{ {
public partial class AddedFileEntity : Migration
public partial class AddedFileAndCategoryAndTagEntities : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Files",
name: "Categories",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Size = table.Column<long>(type: "bigint", nullable: false),
Extension = table.Column<string>(type: "nvarchar(max)", nullable: false)
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Files", x => x.Id);
table.PrimaryKey("PK_Categories", x => x.Id);
}); });


migrationBuilder.CreateTable( migrationBuilder.CreateTable(
}); });


migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Categories",
name: "Files",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false), Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
FileId = table.Column<int>(type: "int", nullable: false)
Size = table.Column<long>(type: "bigint", nullable: false),
Extension = table.Column<string>(type: "nvarchar(max)", nullable: false),
CategoryId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Categories", x => x.Id);
table.PrimaryKey("PK_Files", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Categories_Files_FileId",
column: x => x.FileId,
principalTable: "Files",
name: "FK_Files_Categories_CategoryId",
column: x => x.CategoryId,
principalTable: "Categories",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });


migrationBuilder.CreateIndex(
name: "IX_Categories_FileId",
table: "Categories",
column: "FileId");

migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_FileEntityTag_TagsId", name: "IX_FileEntityTag_TagsId",
table: "FileEntityTag", table: "FileEntityTag",
column: "TagsId"); column: "TagsId");

migrationBuilder.CreateIndex(
name: "IX_Files_CategoryId",
table: "Files",
column: "CategoryId");
} }


protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable(
name: "Categories");

migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "FileEntityTag"); name: "FileEntityTag");




migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Tags"); name: "Tags");

migrationBuilder.DropTable(
name: "Categories");
} }
} }
} }

+ 18
- 18
Diligent.WebAPI.Data/Migrations/DatabaseContextModelSnapshot.cs Bestand weergeven



SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);


b.Property<int>("FileId")
.HasColumnType("int");

b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");


b.HasKey("Id"); b.HasKey("Id");


b.HasIndex("FileId");

b.ToTable("Categories"); b.ToTable("Categories");
}); });




SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);


b.Property<int>("CategoryId")
.HasColumnType("int");

b.Property<string>("Extension") b.Property<string>("Extension")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");


b.HasKey("Id"); b.HasKey("Id");


b.HasIndex("CategoryId");

b.ToTable("Files"); b.ToTable("Files");
}); });


.IsRequired(); .IsRequired();
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.FileEntity", "File")
.WithMany("Categories")
.HasForeignKey("FileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("File");
});

modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Comment", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Comment", b =>
{ {
b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant") b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant")
b.Navigation("User"); b.Navigation("User");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.FileEntity", b =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Category", "Category")
.WithMany("Files")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Category");
});

modelBuilder.Entity("Diligent.WebAPI.Data.Entities.InsurancePolicy", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.InsurancePolicy", b =>
{ {
b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer") b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer")
b.Navigation("TechnologyApplicants"); b.Navigation("TechnologyApplicants");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.FileEntity", b =>
modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b =>
{ {
b.Navigation("Categories");
b.Navigation("Files");
}); });


modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b => modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b =>

+ 21
- 0
Diligent.WebAPI.Host/Controllers/V1/CategoriesController.cs Bestand weergeven

using Microsoft.AspNetCore.Mvc;

namespace Diligent.WebAPI.Host.Controllers.V1
{
[ApiVersion("1.0")]
[Route("v{version:apiVersion}/categories")]
[ApiController]
public class CategoriesController : ControllerBase
{
private readonly ICategoryService _categoryService;

public CategoriesController(ICategoryService categoryService)
{
_categoryService = categoryService;
}

[HttpGet("names")]
public async Task<IActionResult> GetCategoriesNames() =>
Ok(await _categoryService.GetCategoriesNamesAsync());
}
}

+ 33
- 5
Diligent.WebAPI.Host/Controllers/V1/FilesController.cs Bestand weergeven

namespace Diligent.WebAPI.Host.Controllers.V1
using Diligent.WebAPI.Contracts.DTOs.File;
using Diligent.WebAPI.Host.Methods;

namespace Diligent.WebAPI.Host.Controllers.V1
{ {
[ApiVersion("1.0")] [ApiVersion("1.0")]
[Route("v{version:apiVersion}/files")] [Route("v{version:apiVersion}/files")]
[ApiController] [ApiController]
public class FilesController : ControllerBase public class FilesController : ControllerBase
{ {
private readonly IFileService _fileService;
private readonly ICategoryService _categoryService;
private readonly ITagService _tagService;
private readonly IFileEntityService _fileEntityService;
private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;


public FilesController(IFileService fileService)
public FilesController(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IFileEntityService fileEntityService, ICategoryService categoryService, ITagService tagService)
{ {
_fileService = fileService;
_hostingEnvironment = hostingEnvironment;
_fileEntityService = fileEntityService;
_categoryService = categoryService;
_tagService = tagService;
} }


[HttpGet] [HttpGet]
public async Task<IActionResult> GetAll() => Ok(await _fileService.GetAll());
public async Task<IActionResult> GetAll() => Ok(await _fileEntityService.GetAll());

[HttpPost]
public async Task<IActionResult> UploadPdf([FromForm] CreateFileRequest request)
{
if (request == null) throw new BadHttpRequestException("Request cannot be null");
var filePath = await Upload.SaveFile(_hostingEnvironment.ContentRootPath, request.FileToUpload, "files");

var category = await _categoryService.GetCategoryEntityById(request.CategoryId);

if (category == null) throw new BadHttpRequestException("Category cannot found");

List<Tag> tags = new();
foreach (var id in request.TagsIds)
tags.Add(await _tagService.GetTagEntityById(id));


await _fileEntityService.UploadPdfAsync(new FileEntity { CategoryId = request.CategoryId, Category = category, Tags = tags, Name = filePath, Extension = "pdf", Size = 100});
return Ok();
}
} }
} }

+ 9
- 2
Diligent.WebAPI.Host/Controllers/V1/TagsController.cs Bestand weergeven

namespace Diligent.WebAPI.Host.Controllers.V1
using Diligent.WebAPI.Contracts.DTOs.Tags;

namespace Diligent.WebAPI.Host.Controllers.V1
{ {
[ApiVersion("1.0")] [ApiVersion("1.0")]
[Route("v{version:apiVersion}/tags")] [Route("v{version:apiVersion}/tags")]
public class TagsController : ControllerBase public class TagsController : ControllerBase
{ {
private readonly ITagService _tagService; private readonly ITagService _tagService;
private readonly IMapper _mapper;


public TagsController(ITagService tagService)
public TagsController(ITagService tagService, IMapper mapper)
{ {
_tagService = tagService; _tagService = tagService;
_mapper = mapper;
} }


[HttpGet] [HttpGet]
public async Task<IActionResult> GetFileFilters() => Ok(await _tagService.GetFilters()); public async Task<IActionResult> GetFileFilters() => Ok(await _tagService.GetFilters());

[HttpGet("names")]
public async Task<IActionResult> GetTagsNames() => Ok(await _tagService.GetTagsNames());
} }
} }

+ 1
- 0
Diligent.WebAPI.Host/Diligent.WebAPI.Host.csproj Bestand weergeven



<ItemGroup> <ItemGroup>
<Folder Include="Files\" /> <Folder Include="Files\" />
<Folder Include="wwwroot\files\" />
</ItemGroup> </ItemGroup>


</Project> </Project>

+ 2
- 0
Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs Bestand weergeven

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<IFileEntityService, FileEntityService>();
services.AddScoped<ITagService, TagService>(); services.AddScoped<ITagService, TagService>();
services.AddScoped<ICategoryService, CategoryService>();
} }


/// <summary> /// <summary>

+ 21
- 0
Diligent.WebAPI.Host/Methods/Upload.cs Bestand weergeven

namespace Diligent.WebAPI.Host.Methods
{
public class Upload
{
public static async Task<string> SaveFile(string root, IFormFile file, string path)
{
string fileName = new String(Path.GetFileNameWithoutExtension(file.Name).Take(10).ToArray()).Replace(' ', '-');

fileName = fileName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(file.FileName);

var filePath = Path.Combine(root, $"wwwroot/{path}", fileName);

using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}

return fileName;
}
}
}

+ 0
- 0
Diligent.WebAPI.Host/wwwroot/files/fileToUplo231121108.pdf Bestand weergeven


+ 0
- 0
Diligent.WebAPI.Host/wwwroot/files/fileToUplo233550096.pdf Bestand weergeven


Laden…
Annuleren
Opslaan