forked from ddrilling/AsbCloudServer
CS2-59: Added Delete() to File controller
This commit is contained in:
parent
e8d98a0887
commit
8b5af8d32e
@ -23,5 +23,8 @@ namespace AsbCloudApp.Services
|
||||
|
||||
Task<FileInfoDto> GetFileInfoAsync(int fileId,
|
||||
CancellationToken token);
|
||||
|
||||
Task<int> DeleteFileAsync(int idFile,
|
||||
CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
@ -125,5 +125,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
dto.AuthorName = entity.Author.Name;
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteFileAsync(int idFile,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var fileInfo = db.Files.FirstOrDefault(f => f.Id == idFile);
|
||||
|
||||
if (fileInfo is null)
|
||||
return 0;
|
||||
|
||||
fileInfo.IsDeleted = true;
|
||||
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
return Forbid();
|
||||
|
||||
var fileInfoCollection = files.Select(f =>
|
||||
(f.FileName, idWell, idCategory, DateTime.Now, (int)idUser));
|
||||
@ -91,7 +91,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
return Forbid();
|
||||
|
||||
var filesInfo = await fileService.GetFilesInfoAsync(idWell, idCategory,
|
||||
begin, end, skip, take, token).ConfigureAwait(false);
|
||||
@ -124,7 +124,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
return Forbid();
|
||||
|
||||
var fileInfo = await fileService.GetFileInfoAsync(fileId, token);
|
||||
|
||||
@ -141,5 +141,28 @@ namespace AsbCloudWebApi.Controllers
|
||||
return NotFound($"Файл не найден. Текст ошибки: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаляет файл с диска на сервере
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="idFile">id запрашиваемого файла</param>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{idFile}")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> DeleteAsync(int idWell, int idFile,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await fileService.DeleteFileAsync(idFile, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user