#5 Upload pdf files

Zusammengeführt
bronjaermin hat 1 Commits von feature/upload_pdf nach BE_dev vor 3 Jahren zusammengeführt
  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 Datei anzeigen

@@ -0,0 +1,24 @@
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 Datei anzeigen

@@ -0,0 +1,22 @@
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 Datei anzeigen

@@ -0,0 +1,24 @@
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 Datei anzeigen

@@ -0,0 +1,27 @@
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 Datei anzeigen

@@ -0,0 +1,39 @@
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 Datei anzeigen

@@ -51,10 +51,5 @@ namespace Diligent.WebAPI.Business.Services
string base64 = Convert.ToBase64String(bytes);
return base64;
}

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

+ 15
- 0
Diligent.WebAPI.Business/Services/Interfaces/ICategoryService.cs Datei anzeigen

@@ -0,0 +1,15 @@
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 Datei anzeigen

@@ -0,0 +1,16 @@
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 Datei anzeigen

@@ -6,6 +6,5 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
{
Task<string> GetCV(string fileName);
Task UploadCV(string fileName,IFormFile file);
Task<IEnumerable<FileEntity>> GetAll();
}
}

+ 4
- 0
Diligent.WebAPI.Business/Services/Interfaces/ITagService.cs Datei anzeigen

@@ -1,10 +1,14 @@

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

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

}
}

+ 13
- 2
Diligent.WebAPI.Business/Services/TagService.cs Datei anzeigen

@@ -1,14 +1,19 @@
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
{
public class TagService : ITagService
{
private readonly DatabaseContext _databaseContext;
private readonly IMapper _mapper;

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

public async Task<FileFiltersReturnDTO> GetFilters()
@@ -25,5 +30,11 @@ namespace Diligent.WebAPI.Business.Services
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 Datei anzeigen

@@ -0,0 +1,15 @@
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 Datei anzeigen

@@ -0,0 +1,19 @@
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 Datei anzeigen

@@ -0,0 +1,17 @@
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 Datei anzeigen

@@ -0,0 +1,18 @@
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 Datei anzeigen

@@ -0,0 +1,23 @@
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 Datei anzeigen

@@ -0,0 +1,15 @@
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 Datei anzeigen

@@ -0,0 +1,15 @@
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 Datei anzeigen

@@ -13,9 +13,6 @@ namespace Diligent.WebAPI.Data.Entities

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 Datei anzeigen

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -16,7 +17,10 @@ namespace Diligent.WebAPI.Data.Entities

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

Diligent.WebAPI.Data/Migrations/20230203064003_AddedFileEntity.Designer.cs → Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.Designer.cs Datei anzeigen

@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Diligent.WebAPI.Data.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230203064003_AddedFileEntity")]
partial class AddedFileEntity
[Migration("20230203145727_AddedFileAndCategoryAndTagEntities")]
partial class AddedFileAndCategoryAndTagEntities
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@@ -211,17 +211,12 @@ namespace Diligent.WebAPI.Data.Migrations

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

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

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

b.HasKey("Id");

b.HasIndex("FileId");

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

@@ -264,6 +259,9 @@ namespace Diligent.WebAPI.Data.Migrations

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

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

b.Property<string>("Extension")
.IsRequired()
.HasColumnType("nvarchar(max)");
@@ -277,6 +275,8 @@ namespace Diligent.WebAPI.Data.Migrations

b.HasKey("Id");

b.HasIndex("CategoryId");

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

@@ -954,17 +954,6 @@ namespace Diligent.WebAPI.Data.Migrations
.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 =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant")
@@ -984,6 +973,17 @@ namespace Diligent.WebAPI.Data.Migrations
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 =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer")
@@ -1159,9 +1159,9 @@ namespace Diligent.WebAPI.Data.Migrations
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 =>

Diligent.WebAPI.Data/Migrations/20230203064003_AddedFileEntity.cs → Diligent.WebAPI.Data/Migrations/20230203145727_AddedFileAndCategoryAndTagEntities.cs Datei anzeigen

@@ -4,23 +4,21 @@

namespace Diligent.WebAPI.Data.Migrations
{
public partial class AddedFileEntity : Migration
public partial class AddedFileAndCategoryAndTagEntities : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Files",
name: "Categories",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.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 =>
{
table.PrimaryKey("PK_Files", x => x.Id);
table.PrimaryKey("PK_Categories", x => x.Id);
});

migrationBuilder.CreateTable(
@@ -37,21 +35,23 @@ namespace Diligent.WebAPI.Data.Migrations
});

migrationBuilder.CreateTable(
name: "Categories",
name: "Files",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
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 =>
{
table.PrimaryKey("PK_Categories", x => x.Id);
table.PrimaryKey("PK_Files", x => x.Id);
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",
onDelete: ReferentialAction.Cascade);
});
@@ -80,22 +80,19 @@ namespace Diligent.WebAPI.Data.Migrations
onDelete: ReferentialAction.Cascade);
});

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

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

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

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

migrationBuilder.DropTable(
name: "FileEntityTag");

@@ -104,6 +101,9 @@ namespace Diligent.WebAPI.Data.Migrations

migrationBuilder.DropTable(
name: "Tags");

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

+ 18
- 18
Diligent.WebAPI.Data/Migrations/DatabaseContextModelSnapshot.cs Datei anzeigen

@@ -209,17 +209,12 @@ namespace Diligent.WebAPI.Data.Migrations

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

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

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

b.HasKey("Id");

b.HasIndex("FileId");

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

@@ -262,6 +257,9 @@ namespace Diligent.WebAPI.Data.Migrations

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

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

b.Property<string>("Extension")
.IsRequired()
.HasColumnType("nvarchar(max)");
@@ -275,6 +273,8 @@ namespace Diligent.WebAPI.Data.Migrations

b.HasKey("Id");

b.HasIndex("CategoryId");

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

@@ -952,17 +952,6 @@ namespace Diligent.WebAPI.Data.Migrations
.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 =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Applicant", "Applicant")
@@ -982,6 +971,17 @@ namespace Diligent.WebAPI.Data.Migrations
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 =>
{
b.HasOne("Diligent.WebAPI.Data.Entities.Insurer", "Insurer")
@@ -1157,9 +1157,9 @@ namespace Diligent.WebAPI.Data.Migrations
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 =>

+ 21
- 0
Diligent.WebAPI.Host/Controllers/V1/CategoriesController.cs Datei anzeigen

@@ -0,0 +1,21 @@
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 Datei anzeigen

@@ -1,18 +1,46 @@
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")]
[Route("v{version:apiVersion}/files")]
[ApiController]
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]
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 Datei anzeigen

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Host.Controllers.V1
using Diligent.WebAPI.Contracts.DTOs.Tags;

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

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

[HttpGet]
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 Datei anzeigen

@@ -50,6 +50,7 @@

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

</Project>

+ 2
- 0
Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs Datei anzeigen

@@ -41,7 +41,9 @@ namespace Diligent.WebAPI.Host.Extensions
services.AddScoped<ISaveImportedDataService, SaveImportedDataService>();
services.AddScoped<IScreeningTestService, ScreeningTestService>();
services.AddScoped<IFileService, FileService>();
services.AddScoped<IFileEntityService, FileEntityService>();
services.AddScoped<ITagService, TagService>();
services.AddScoped<ICategoryService, CategoryService>();
}

/// <summary>

+ 21
- 0
Diligent.WebAPI.Host/Methods/Upload.cs Datei anzeigen

@@ -0,0 +1,21 @@
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 Datei anzeigen


+ 0
- 0
Diligent.WebAPI.Host/wwwroot/files/fileToUplo233550096.pdf Datei anzeigen


Laden…
Abbrechen
Speichern