1
0
mirror of https://github.com/C9Glax/tranga.git synced 2025-07-05 02:14:17 +02:00

Multiple Base-Paths (Libraries) Support

This commit is contained in:
2025-03-16 16:48:19 +01:00
parent 5012bbb2eb
commit 5b03befbf1
64 changed files with 668 additions and 16084 deletions
API
APIEndpointRecords
Controllers
Migrations
20250303141044_dev-030325-1.Designer.cs20250303145324_dev-030325-2.Designer.cs20250303145324_dev-030325-2.cs20250303152212_dev-030325-3.Designer.cs20250303152212_dev-030325-3.cs20250307104111_dev-070325-1.Designer.cs20250307104111_dev-070325-1.cs20250307125727_dev-070325-2.Designer.cs20250307125727_dev-070325-2.cs20250307143019_dev-070325-3.Designer.cs20250307143019_dev-070325-3.cs20250307143254_dev-070325-4.Designer.cs20250307143254_dev-070325-4.cs20250307143442_dev-070325-5.Designer.cs20250307143442_dev-070325-5.cs20250307175004_dev-070325-6.Designer.cs20250307175004_dev-070325-6.cs20250308121028_dev-080325-1.Designer.cs20250308121028_dev-080325-1.cs20250308154843_dev-080325-2.Designer.cs20250308154843_dev-080325-2.cs20250308162728_dev-080325-3.Designer.cs20250308162728_dev-080325-3.cs20250308170713_dev-080325-4.Designer.cs20250308170713_dev-080325-4.cs20250313145235_dev-130325-1.Designer.cs20250313145235_dev-130325-1.cs20250313175936_dev-130325-2.Designer.cs20250313175936_dev-130325-2.cs20250313180256_dev-130325-3.Designer.cs20250313180256_dev-130325-3.cs20250313180926_dev-130325-4.Designer.cs20250313180926_dev-130325-4.cs20250313181126_dev-130325-5.Designer.cs20250313181126_dev-130325-5.cs20250313191146_dev-130325-6.Designer.cs20250313191146_dev-130325-6.cs20250313212324_dev-130325-7.Designer.cs20250313212324_dev-130325-7.cs20250313222533_dev-130325-8.cs20250313233529_dev-130325-9.cs20250316143014_dev-160325-Initial.Designer.cs20250316143014_dev-160325-Initial.cs20250316150158_dev-160325-2.Designer.cs20250316150158_dev-160325-2.csPgsqlContextModelSnapshot.cs
Program.cs
Schema
Tranga.cs

@ -0,0 +1,127 @@
using API.APIEndpointRecords;
using API.Schema;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using static Microsoft.AspNetCore.Http.StatusCodes;
namespace API.Controllers;
[ApiVersion(2)]
[ApiController]
[Route("v{v:apiVersion}/[controller]")]
public class LocalLibrariesController(PgsqlContext context) : Controller
{
[HttpGet]
[ProducesResponseType<LocalLibrary[]>(Status200OK, "application/json")]
public IActionResult GetLocalLibraries()
{
return Ok(context.LocalLibraries);
}
[HttpGet("{LibraryId}")]
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
[ProducesResponseType(Status404NotFound)]
public IActionResult GetLocalLibrary(string LibraryId)
{
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
if (library is null)
return NotFound();
return Ok(library);
}
[HttpPatch("{LibraryId}/ChangeBasePath")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status404NotFound)]
[ProducesResponseType(Status400BadRequest)]
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
public IActionResult ChangeLibraryBasePath(string LibraryId, [FromBody] string newBasePath)
{
try
{
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
if (library is null)
return NotFound();
if (false) //TODO implement path check
return BadRequest();
library.BasePath = newBasePath;
context.SaveChanges();
return Ok();
}
catch (Exception e)
{
return StatusCode(500, e.Message);
}
}
[HttpPatch("{LibraryId}/ChangeName")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status404NotFound)]
[ProducesResponseType(Status400BadRequest)]
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
public IActionResult ChangeLibraryName(string LibraryId, [FromBody] string newName)
{
try
{
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
if (library is null)
return NotFound();
if(newName.Length < 1)
return BadRequest();
library.LibraryName = newName;
context.SaveChanges();
return Ok();
}
catch (Exception e)
{
return StatusCode(500, e.Message);
}
}
[HttpPut]
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
public IActionResult CreateNewLibrary([FromBody] NewLibraryRecord library)
{
try
{
LocalLibrary newLibrary = new (library.path, library.name);
context.LocalLibraries.Add(newLibrary);
context.SaveChanges();
return Ok(newLibrary);
}
catch (Exception e)
{
return StatusCode(500, e.Message);
}
}
[HttpDelete("{LibraryId}")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status404NotFound)]
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
public IActionResult DeleteLocalLibrary(string LibraryId)
{
try
{
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
if (library is null)
return NotFound();
context.Remove(library);
context.SaveChanges();
return Ok();
}
catch (Exception e)
{
return StatusCode(500, e.Message);
}
}
}