| @@ -50,7 +50,7 @@ namespace Diligent.WebAPI.Business.Services | |||
| { | |||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | |||
| var files = await connection.QueryAsync<FileFilterReturnDto, TagResponse, CategoryResponse, FileFilterReturnDto>("SELECT Files.Id as FileId, stream_id, DocumentOrganizerDocStore.name as FileName, file_stream, file_type, cached_file_size, Tags.Id as TagId, Tags.Name as TagName, Categories.Id as CategoryId, Categories.Name as CategoryName FROM Files inner join FileEntityTag on Files.Id = FileEntityTag.FilesId inner join Tags on FileEntityTag.TagsId = Tags.Id inner join DocumentOrganizerDocStore on DocumentOrganizerDocStore.stream_id = Files.DocumentId inner join Categories on Files.CategoryId = Categories.Id;", (file, tag, category) => | |||
| var files = await connection.QueryAsync<FileFilterReturnDto, TagResponse, CategoryResponse, FileFilterReturnDto>("SELECT Files.Id as FileId, stream_id, DocumentOrganizerDocStore.name as FileName, file_stream, file_type, cached_file_size, Title, Tags.Id as TagId, Tags.Name as TagName, Categories.Id as CategoryId, Categories.Name as CategoryName FROM Files inner join FileEntityTag on Files.Id = FileEntityTag.FilesId inner join Tags on FileEntityTag.TagsId = Tags.Id inner join DocumentOrganizerDocStore on DocumentOrganizerDocStore.stream_id = Files.DocumentId inner join Categories on Files.CategoryId = Categories.Id;", (file, tag, category) => | |||
| { | |||
| file.Tags.Add(tag); | |||
| file.Category = category; | |||
| @@ -65,7 +65,7 @@ namespace Diligent.WebAPI.Business.Services | |||
| return new | |||
| { | |||
| Data = filtered.ApplyPagging(filters) | |||
| .Select(n => new { n.stream_id, n.FileName, n.cached_file_size, n.file_type }), | |||
| .Select(n => new { n.stream_id, n.FileName, n.cached_file_size, n.file_type, n.Title }), | |||
| Total = filtered.Count | |||
| }; | |||
| } | |||
| @@ -9,6 +9,8 @@ namespace Diligent.WebAPI.Contracts.DTOs.File | |||
| { | |||
| public class CreateFileRequest | |||
| { | |||
| public string Title { get; set; } | |||
| public int CategoryId { get; set; } | |||
| public int[] TagsIds { get; set; } | |||
| @@ -12,6 +12,7 @@ namespace Diligent.WebAPI.Contracts.DTOs.Files | |||
| { | |||
| public Guid stream_id { get; set; } | |||
| public string FileName { get; set; } | |||
| public string Title { get; set; } | |||
| public string file_type { get; set; } | |||
| public int cached_file_size { get; set; } | |||
| public List<TagResponse> Tags { get; set; } = new(); | |||
| @@ -11,6 +11,8 @@ namespace Diligent.WebAPI.Data.Entities | |||
| { | |||
| public int Id { get; set; } | |||
| public string Title { get; set; } | |||
| public Guid DocumentId { get; set; } | |||
| [ForeignKey(nameof(Category))] | |||
| @@ -0,0 +1,26 @@ | |||
| using Microsoft.EntityFrameworkCore.Migrations; | |||
| #nullable disable | |||
| namespace Diligent.WebAPI.Data.Migrations | |||
| { | |||
| public partial class AddedTitleToFileEntity : Migration | |||
| { | |||
| protected override void Up(MigrationBuilder migrationBuilder) | |||
| { | |||
| migrationBuilder.AddColumn<string>( | |||
| name: "Title", | |||
| table: "Files", | |||
| type: "nvarchar(max)", | |||
| nullable: false, | |||
| defaultValue: ""); | |||
| } | |||
| protected override void Down(MigrationBuilder migrationBuilder) | |||
| { | |||
| migrationBuilder.DropColumn( | |||
| name: "Title", | |||
| table: "Files"); | |||
| } | |||
| } | |||
| } | |||
| @@ -263,6 +263,10 @@ namespace Diligent.WebAPI.Data.Migrations | |||
| b.Property<Guid>("DocumentId") | |||
| .HasColumnType("uniqueidentifier"); | |||
| b.Property<string>("Title") | |||
| .IsRequired() | |||
| .HasColumnType("nvarchar(max)"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("CategoryId"); | |||
| @@ -46,7 +46,7 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| var file = await _documentService.UploadDocument(request.FileToUpload); | |||
| await _fileEntityService.UploadPdfAsync(new FileEntity { CategoryId = request.CategoryId, DocumentId = file.stream_id, Category = category, Tags = tags}); | |||
| await _fileEntityService.UploadPdfAsync(new FileEntity { CategoryId = request.CategoryId, DocumentId = file.stream_id, Category = category, Tags = tags, Title = request.Title}); | |||
| return Ok(); | |||
| } | |||
| } | |||