41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using StorageServer.IO;
|
||
|
using StorageServer.Models;
|
||
|
using StorageServer.Models.Request;
|
||
|
using StorageServer.Models.Response;
|
||
|
|
||
|
namespace StorageServer.Controllers;
|
||
|
|
||
|
public class FileListController : Controller
|
||
|
{
|
||
|
private readonly DatabaseFactory database;
|
||
|
public FileListController(DatabaseFactory database) {
|
||
|
this.database = database;
|
||
|
}
|
||
|
|
||
|
public IActionResult Read(FileListReadModel model) {
|
||
|
if (!ModelState.IsValid) {
|
||
|
return BadRequest();
|
||
|
}
|
||
|
|
||
|
if (model.Page < 0) {
|
||
|
return BadRequest();
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
IEnumerable<FileModel> fileModels = this.database.ReadAll();
|
||
|
int readCount = 100;
|
||
|
IEnumerable<FileModel> seekedModels = fileModels.Skip(readCount * model.Page).Take(readCount);
|
||
|
|
||
|
List<FileListResponseModel> fileLists = new List<FileListResponseModel>();
|
||
|
foreach (FileModel fileModel in seekedModels) {
|
||
|
fileLists.Add(new FileListResponseModel(fileModel));
|
||
|
}
|
||
|
|
||
|
return Json(fileLists);
|
||
|
} catch (Exception) {
|
||
|
return Problem();
|
||
|
}
|
||
|
}
|
||
|
}
|