Skip to content

Commit

Permalink
Code cleanup goodies: file-scoped namespaces, default constructors, c…
Browse files Browse the repository at this point in the history
…ollection initializers, etc.
  • Loading branch information
impworks committed Dec 29, 2023
1 parent 1badadd commit a70f4eb
Show file tree
Hide file tree
Showing 123 changed files with 4,752 additions and 5,301 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Isotope.Code.Utils.Filters;
using Microsoft.AspNetCore.Mvc;

namespace Isotope.Areas.Admin.Controllers
namespace Isotope.Areas.Admin.Controllers;

/// <summary>
/// Base class for all admin page controllers.
/// </summary>
[Area("Admin"), JwtAuthorize(true)]
public class AdminControllerBase: Controller
{
/// <summary>
/// Base class for all admin page controllers.
/// </summary>
[Area("Admin"), JwtAuthorize(true)]
public class AdminControllerBase: Controller
{
}
}
44 changes: 15 additions & 29 deletions src/Isotope/Isotope/Areas/Admin/Controllers/ConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,23 @@
using Isotope.Areas.Admin.Services;
using Microsoft.AspNetCore.Mvc;

namespace Isotope.Areas.Admin.Controllers
namespace Isotope.Areas.Admin.Controllers;

/// <summary>
/// Controller for working with shared links.
/// </summary>
[Route("~/@api/admin/config")]
public class ConfigController(ConfigManager cfgMgr) : AdminControllerBase
{
/// <summary>
/// Controller for working with shared links.
/// Returns the current configuration state.
/// </summary>
[Route("~/@api/admin/config")]
public class ConfigController: AdminControllerBase
{
public ConfigController(ConfigManager cfgMgr)
{
_cfgMgr = cfgMgr;
}

private readonly ConfigManager _cfgMgr;

/// <summary>
/// Returns the current configuration state.
/// </summary>
[HttpGet, Route("")]
public Task<ConfigVM> Get()
{
return _cfgMgr.GetAsync();
}
[HttpGet, Route("")]
public Task<ConfigVM> Get() => cfgMgr.GetAsync();

/// <summary>
/// Updates the configuration state.
/// </summary>
[HttpPut, Route("")]
public Task Set([FromBody] ConfigVM vm)
{
return _cfgMgr.SetAsync(vm);
}
}
/// <summary>
/// Updates the configuration state.
/// </summary>
[HttpPut, Route("")]
public Task Set([FromBody] ConfigVM vm) => cfgMgr.SetAsync(vm);
}
96 changes: 35 additions & 61 deletions src/Isotope/Isotope/Areas/Admin/Controllers/FoldersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,47 @@
using Isotope.Areas.Admin.Services;
using Microsoft.AspNetCore.Mvc;

namespace Isotope.Areas.Admin.Controllers
namespace Isotope.Areas.Admin.Controllers;

/// <summary>
/// Controller for working with folders.
/// </summary>
[Route("~/@api/admin/folders")]
public class FoldersController(FolderManager folderMgr) : AdminControllerBase
{
/// <summary>
/// Controller for working with folders.
/// Returns the tree of all folders in the system.
/// </summary>
[Route("~/@api/admin/folders")]
public class FoldersController: AdminControllerBase
{
public FoldersController(FolderManager folderMgr)
{
_folderMgr = folderMgr;
}

private readonly FolderManager _folderMgr;
[HttpGet, Route("")]
public Task<IReadOnlyList<FolderTitleVM>> GetTree() => folderMgr.GetTreeAsync();

/// <summary>
/// Returns the tree of all folders in the system.
/// </summary>
[HttpGet, Route("")]
public Task<IReadOnlyList<FolderTitleVM>> GetTree()
{
return _folderMgr.GetTreeAsync();
}
/// <summary>
/// Creates a new folder.
/// </summary>
[HttpPost, Route("{key?}")]
public Task<FolderTitleVM> Create(string key, [FromBody] FolderVM vm) => folderMgr.CreateAsync(key, vm);

/// <summary>
/// Creates a new folder.
/// </summary>
[HttpPost, Route("{key?}")]
public Task<FolderTitleVM> Create(string key, [FromBody] FolderVM vm)
{
return _folderMgr.CreateAsync(key, vm);
}
/// <summary>
/// Returns the folder info for editing.
/// </summary>
[HttpGet, Route("{key}")]
public Task<FolderVM> GetDetails(string key) => folderMgr.GetAsync(key);

/// <summary>
/// Returns the folder info for editing.
/// </summary>
[HttpGet, Route("{key}")]
public Task<FolderVM> GetDetails(string key)
{
return _folderMgr.GetAsync(key);
}
/// <summary>
/// Updates an existing folder.
/// </summary>
[HttpPut, Route("{key}")]
public Task Update(string key, [FromBody] FolderVM vm) => folderMgr.UpdateAsync(key, vm);

/// <summary>
/// Updates an existing folder.
/// </summary>
[HttpPut, Route("{key}")]
public Task Update(string key, [FromBody] FolderVM vm)
{
return _folderMgr.UpdateAsync(key, vm);
}
/// <summary>
/// Removes an existing folder with all its contents.
/// </summary>
[HttpDelete, Route("{key}")]
public Task Delete(string key) => folderMgr.RemoveAsync(key);

/// <summary>
/// Removes an existing folder with all its contents.
/// </summary>
[HttpDelete, Route("{key}")]
public Task Delete(string key)
{
return _folderMgr.RemoveAsync(key);
}

/// <summary>
/// Moves a folder to another location.
/// </summary>
[HttpPost, Route("move")]
public Task Move([FromBody] MoveFolderVM vm)
{
return _folderMgr.MoveAsync(vm.SourceKey, vm.TargetKey);
}
}
/// <summary>
/// Moves a folder to another location.
/// </summary>
[HttpPost, Route("move")]
public Task Move([FromBody] MoveFolderVM vm) => folderMgr.MoveAsync(vm.SourceKey, vm.TargetKey);
}
39 changes: 16 additions & 23 deletions src/Isotope/Isotope/Areas/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
using Microsoft.AspNetCore.Mvc;

namespace Isotope.Areas.Admin.Controllers
namespace Isotope.Areas.Admin.Controllers;

/// <summary>
/// Base controller for bootstrapping the SPA page.
/// </summary>
[Route("~/@admin")]
public class HomeController: ControllerBase
{
/// <summary>
/// Base controller for bootstrapping the SPA page.
/// Hack to workaround regex not matching an empty string.
/// </summary>
[Route("~/@admin")]
public class HomeController: ControllerBase
{
/// <summary>
/// Hack to workaround regex not matching an empty string.
/// </summary>
[Route("")]
public IActionResult Index()
{
return File("~/@assets/admin.html", "text/html");
}
[Route("")]
public IActionResult Index() => File("~/@assets/admin.html", "text/html");

/// <summary>
/// Catch-all method for displaying SPA.
/// </summary>
[Route("{**path:regex(^(?!@))}")]
public IActionResult Index(string path)
{
return File("~/@assets/admin.html", "text/html");
}
}
}
/// <summary>
/// Catch-all method for displaying SPA.
/// </summary>
[Route("{**path:regex(^(?!@))}")]
public IActionResult Index(string path) => File("~/@assets/admin.html", "text/html");
}
Loading

0 comments on commit a70f4eb

Please sign in to comment.