forked from ddrilling/AsbCloudServer
FileController Add file size and fix search by file name
This commit is contained in:
parent
e87e959bca
commit
41660af49f
@ -10,7 +10,8 @@ namespace AsbCloudApp.Data
|
|||||||
public int IdAuthor { get; set; }
|
public int IdAuthor { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public DateTime UploadDate { get; set; }
|
public DateTime UploadDate { get; set; }
|
||||||
public string AuthorName { get; set; }
|
public long Size { get; set; }
|
||||||
public int CompanyId { get; set; }
|
public UserDto Author { get; set; }
|
||||||
|
public string Company { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,9 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("date", TypeName = "timestamp with time zone")]
|
[Column("date", TypeName = "timestamp with time zone")]
|
||||||
public DateTime UploadDate { get; set; }
|
public DateTime UploadDate { get; set; }
|
||||||
|
|
||||||
|
[Column("file_size"), Comment("Размер файла")]
|
||||||
|
public long Size { get; set; }
|
||||||
|
|
||||||
[Column("is_deleted"), Comment("Удален ли файл")]
|
[Column("is_deleted"), Comment("Удален ли файл")]
|
||||||
public bool IsDeleted { get; set; }
|
public bool IsDeleted { get; set; }
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
@ -16,11 +17,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
public string RootPath { get; private set; }
|
public string RootPath { get; private set; }
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
|
private readonly CacheTable<Company> cacheCompanies;
|
||||||
|
|
||||||
public FileService(IAsbCloudDbContext db)
|
public FileService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
|
||||||
{
|
{
|
||||||
RootPath = "files";
|
RootPath = "files";
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
cacheCompanies = cacheDb.GetCachedTable<AsbCloudDb.Model.Company>((DbContext)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
public async Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
||||||
@ -34,6 +37,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
Name = Path.GetFileName(fileFullName),
|
Name = Path.GetFileName(fileFullName),
|
||||||
UploadDate = DateTime.Now,
|
UploadDate = DateTime.Now,
|
||||||
IsDeleted = false,
|
IsDeleted = false,
|
||||||
|
Size = fileStream.Length,
|
||||||
};
|
};
|
||||||
|
|
||||||
var entry = db.Files.Add(fileInfo);
|
var entry = db.Files.Add(fileInfo);
|
||||||
@ -64,9 +68,11 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var dtos = entities.Adapt<FileInfoDto, AsbCloudDb.Model.FileInfo>((d,s) => {
|
var dtos = entities.Adapt<FileInfoDto, AsbCloudDb.Model.FileInfo>(async (d,s) => {
|
||||||
d.AuthorName = s.Author?.Name;
|
d.Author = s.Author?.Adapt<UserDto>();
|
||||||
d.CompanyId = s.Author?.IdCompany ?? 0;
|
var company = await cacheCompanies.FirstOrDefaultAsync(c => c.Id == s.Author?.IdCompany, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
d.Company = company?.Caption;
|
||||||
});
|
});
|
||||||
|
|
||||||
return dtos;
|
return dtos;
|
||||||
@ -88,7 +94,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Where(e => companies.Contains(e.Author.Company.Id));
|
.Where(e => companies.Contains(e.Author.Company.Id));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(fileName))
|
if (!string.IsNullOrEmpty(fileName))
|
||||||
query = query.Where(e => e.Name.Contains(fileName, StringComparison.OrdinalIgnoreCase));
|
query = query.Where(e => e.Name.ToLower().Contains(fileName.ToLower()));
|
||||||
|
|
||||||
if (begin != default)
|
if (begin != default)
|
||||||
query = query.Where(e => e.UploadDate >= begin);
|
query = query.Where(e => e.UploadDate >= begin);
|
||||||
@ -118,14 +124,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Take(take).AsNoTracking().ToListAsync(token)
|
.Take(take).AsNoTracking().ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
foreach (var item in entities)
|
var dtos = entities.Adapt<FileInfoDto, AsbCloudDb.Model.FileInfo>(async (d, s) =>
|
||||||
{
|
{
|
||||||
var filePropertiesDto = item.Adapt<FileInfoDto>();
|
d.Author = s.Author?.Adapt<UserDto>();
|
||||||
filePropertiesDto.AuthorName = item.Author?.Name;
|
var company = await cacheCompanies.FirstOrDefaultAsync(c => c.Id == s.Author?.IdCompany, token)
|
||||||
filePropertiesDto.CompanyId = item.Author?.IdCompany ?? 0;
|
.ConfigureAwait(false);
|
||||||
result.Items.Add(filePropertiesDto);
|
d.Company = company?.Caption;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
result.Items.AddRange(dtos);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +149,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var dto = entity.Adapt<FileInfoDto>();
|
var dto = entity.Adapt<FileInfoDto>();
|
||||||
dto.AuthorName = entity.Author.Name;
|
dto.Author = entity.Author?.Adapt<UserDto>();
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,9 +125,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
var filesInfo = await fileService.GetInfosAsync(idWell, idCategory,
|
var filesInfo = await fileService.GetInfosAsync(idWell, idCategory,
|
||||||
companies, fileName, begin, end, skip, take, token).ConfigureAwait(false);
|
companies, fileName, begin, end, skip, take, token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (filesInfo is null || !filesInfo.Items.Any())
|
|
||||||
return NoContent();
|
|
||||||
|
|
||||||
return Ok(filesInfo);
|
return Ok(filesInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user