mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Seperation of concerns: Seperated used File Management form Overall FIle Management
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.Net.Http.Headers;
|
||||
using HaWeb.Filters;
|
||||
using HaWeb.FileHelpers;
|
||||
using HaWeb.XMLParser;
|
||||
using HaWeb.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using HaDocument.Interfaces;
|
||||
@@ -25,14 +26,16 @@ public class APIController : Controller {
|
||||
private readonly long _fileSizeLimit;
|
||||
private readonly string _targetFilePath;
|
||||
private readonly IXMLService _xmlService;
|
||||
private readonly IXMLProvider _xmlProvider;
|
||||
|
||||
// Options
|
||||
private static readonly string[] _permittedExtensions = { ".xml" };
|
||||
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
||||
|
||||
|
||||
public APIController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IConfiguration config) {
|
||||
public APIController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IXMLProvider xmlProvider, IConfiguration config) {
|
||||
_lib = lib;
|
||||
_xmlProvider = xmlProvider;
|
||||
_readerService = readerService;
|
||||
_xmlService = xmlService;
|
||||
_fileSizeLimit = config.GetValue<long>("FileSizeLimit");
|
||||
@@ -117,7 +120,13 @@ public class APIController : Controller {
|
||||
|
||||
//// 5. Stage: Saving the File(s)
|
||||
foreach (var doc in retdocs) {
|
||||
await _xmlService.UpdateAvailableFiles(doc, _targetFilePath, ModelState);
|
||||
// Physical saving
|
||||
var task = _xmlProvider.Save(doc, _targetFilePath, ModelState);
|
||||
// Setting the new docuemnt as used
|
||||
_xmlService.Use(doc);
|
||||
// Unsetting all old docuemnts as ununsed
|
||||
_xmlService.AutoUse(doc.Prefix);
|
||||
await task;
|
||||
if (!ModelState.IsValid) return StatusCode(500, ModelState);
|
||||
if (docs == null) docs = new List<XMLRootDocument>();
|
||||
docs.Add(doc);
|
||||
|
||||
@@ -18,16 +18,18 @@ public class UploadController : Controller {
|
||||
private readonly long _fileSizeLimit;
|
||||
private readonly string _targetFilePath;
|
||||
private readonly IXMLService _xmlService;
|
||||
private readonly IXMLProvider _xmlProvider;
|
||||
|
||||
// Options
|
||||
private static readonly string[] _permittedExtensions = { ".xml" };
|
||||
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
||||
|
||||
|
||||
public UploadController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IConfiguration config) {
|
||||
public UploadController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IXMLProvider xmlProvider, IConfiguration config) {
|
||||
_lib = lib;
|
||||
_readerService = readerService;
|
||||
_xmlService = xmlService;
|
||||
_xmlProvider = xmlProvider;
|
||||
_fileSizeLimit = config.GetValue<long>("FileSizeLimit");
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
_targetFilePath = config.GetValue<string>("StoredFilePathWindows");
|
||||
@@ -42,23 +44,25 @@ public class UploadController : Controller {
|
||||
[GenerateAntiforgeryTokenCookie]
|
||||
public IActionResult Index(string? id) {
|
||||
if (id != null) {
|
||||
id = id.ToLower();
|
||||
|
||||
var root = _xmlService.GetRoot(id);
|
||||
if (root == null) return error404();
|
||||
|
||||
var roots = _xmlService.GetRoots();
|
||||
var roots = _xmlService.GetRootsList();
|
||||
if (roots == null) return error404();
|
||||
|
||||
var usedFiles = _xmlService.GetUsed();
|
||||
var availableFiles = _xmlService.GetAvailableFiles(id);
|
||||
var usedFiles = _xmlService.GetUsedDictionary();
|
||||
var availableFiles = _xmlProvider.GetFiles(id);
|
||||
|
||||
var model = new UploadViewModel(root.Type, id, roots, availableFiles, usedFiles);
|
||||
return View("../Admin/Upload/Index", model);
|
||||
}
|
||||
else {
|
||||
var roots = _xmlService.GetRoots();
|
||||
var roots = _xmlService.GetRootsList();
|
||||
if (roots == null) return error404();
|
||||
|
||||
var usedFiles = _xmlService.GetUsed();
|
||||
var usedFiles = _xmlService.GetUsedDictionary();
|
||||
|
||||
var model = new UploadViewModel("Upload", id, roots, null, usedFiles);
|
||||
return View("../Admin/Upload/Index", model);
|
||||
|
||||
Reference in New Issue
Block a user