Procházet zdrojové kódy

Added edit note

BE_dev
bronjaermin před 2 roky
rodič
revize
c60f17cf37

+ 12
- 4
Diligent.WebAPI.Business/Services/FileEntityService.cs Zobrazit soubor

@@ -41,8 +41,8 @@ namespace Diligent.WebAPI.Business.Services
public async Task<object> GetAllFiltered(FileFilter filters)
{
using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
var sql = @"SELECT Files.Id as FileId, Files.Deleted, 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
var sql = @"SELECT Files.Id as FileId, Note, Files.Deleted, 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 Categories on Files.CategoryId = Categories.Id
@@ -67,7 +67,8 @@ namespace Diligent.WebAPI.Business.Services
FileName = fileItem.FileName,
File_type = fileItem.File_type,
Tags = fileItem.Tags,
Title = fileItem.Title
Title = fileItem.Title,
Note = fileItem.Note
};
// return File_stream in base64 format
MemoryStream stream = new (fileItem.File_stream);
@@ -82,7 +83,7 @@ namespace Diligent.WebAPI.Business.Services
return new
{
Data = filtered.ApplyPagging(filters)
.Select(n => new { n.Stream_id, n.FileName,n.File_stream, n.Cached_file_size, n.File_type, n.Title }),
.Select(n => new { n.Stream_id, n.FileName,n.File_stream, n.Cached_file_size, n.File_type, n.Title, n.Note }),
Total = filtered.Count
};
}
@@ -120,5 +121,12 @@ namespace Diligent.WebAPI.Business.Services

await _context.SaveChangesAsync();
}

public async Task UpdateNoteAsync(Guid id, UpdateFileNoteRequest fileDto)
{
var file = await GetFileEntityByIdAsync(id);
file.Note = fileDto.Note;
await _context.SaveChangesAsync();
}
}
}

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/IFileEntityService.cs Zobrazit soubor

@@ -13,6 +13,7 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
Task UploadFileAsync(FileEntity file);
Task<object> GetAllFiltered(FileFilter filters);
Task<FileEntity> GetFileEntityByIdAsync(Guid id);
Task UpdateNoteAsync(Guid id, UpdateFileNoteRequest fileDto);
Task DeleteFileAsync(Guid id);
}
}

+ 1
- 1
Diligent.WebAPI.Contracts/DTOs/File/CreateFileRequest.cs Zobrazit soubor

@@ -16,6 +16,6 @@ namespace Diligent.WebAPI.Contracts.DTOs.File
public int[] TagsIds { get; set; }

public IFormFile FileToUpload { get; set; }
public string Note { get; set; }
public string? Note { get; set; }
}
}

+ 13
- 0
Diligent.WebAPI.Contracts/DTOs/File/UpdateFileNoteRequest.cs Zobrazit soubor

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.File
{
public class UpdateFileNoteRequest
{
public string Note { get; set; }
}
}

+ 1
- 0
Diligent.WebAPI.Contracts/DTOs/Files/FileFilterReturn.cs Zobrazit soubor

@@ -12,6 +12,7 @@ namespace Diligent.WebAPI.Contracts.DTOs.Files
{
public Guid Stream_id { get; set; }
public string FileName { get; set; }
public string Note { get; set; }
public string Title { get; set; }
public string File_type { get; set; }
public int Cached_file_size { get; set; }

+ 1
- 0
Diligent.WebAPI.Contracts/DTOs/Files/FileFilterReturnDto.cs Zobrazit soubor

@@ -13,6 +13,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? Note { get; set; }
public string File_type { get; set; }
public int Cached_file_size { get; set; }
public string File_stream { get; set; }

+ 1
- 1
Diligent.WebAPI.Data/Entities/FileEntity.cs Zobrazit soubor

@@ -23,6 +23,6 @@ namespace Diligent.WebAPI.Data.Entities
public List<Tag> Tags { get; set; }

public bool Deleted { get; set; } = false;
public string? Note { get; set; }
public string Note { get; set; } = "";
}
}

+ 1231
- 0
Diligent.WebAPI.Data/Migrations/20230223124442_ChangedNoteInitialValueToEmptyString.Designer.cs
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 33
- 0
Diligent.WebAPI.Data/Migrations/20230223124442_ChangedNoteInitialValueToEmptyString.cs Zobrazit soubor

@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Diligent.WebAPI.Data.Migrations
{
public partial class ChangedNoteInitialValueToEmptyString : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Note",
table: "Files",
type: "nvarchar(max)",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Note",
table: "Files",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

+ 1
- 0
Diligent.WebAPI.Data/Migrations/DatabaseContextModelSnapshot.cs Zobrazit soubor

@@ -272,6 +272,7 @@ namespace Diligent.WebAPI.Data.Migrations
.HasColumnType("uniqueidentifier");

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

b.Property<string>("Title")

+ 7
- 0
Diligent.WebAPI.Host/Controllers/V1/FilesController.cs Zobrazit soubor

@@ -47,6 +47,13 @@ namespace Diligent.WebAPI.Host.Controllers.V1
return Ok();
}

[HttpPut("update-note/{id}")]
public async Task<IActionResult> UpdateNote([FromBody]UpdateFileNoteRequest request, Guid id)
{
await _fileEntityService.UpdateNoteAsync(id, request);
return Ok();
}

[HttpDelete("delete-file/{id}")]
public async Task<IActionResult> DeleteFile([FromRoute]Guid id)
{

Načítá se…
Zrušit
Uložit