diff --git a/API/APIEndpointRecords/NewLibraryRecord.cs b/API/APIEndpointRecords/NewLibraryRecord.cs index 88769d9..b30b7b5 100644 --- a/API/APIEndpointRecords/NewLibraryRecord.cs +++ b/API/APIEndpointRecords/NewLibraryRecord.cs @@ -1,3 +1,13 @@ namespace API.APIEndpointRecords; -public record NewLibraryRecord(string path, string name); \ No newline at end of file +public record NewLibraryRecord(string path, string name) +{ + public bool Validate() + { + if (path.Length < 1) //TODO Better Path validation + return false; + if (name.Length < 1) + return false; + return true; + } +} \ No newline at end of file diff --git a/API/Controllers/LocalLibrariesController.cs b/API/Controllers/LocalLibrariesController.cs index 192f6db..6cb3a1a 100644 --- a/API/Controllers/LocalLibrariesController.cs +++ b/API/Controllers/LocalLibrariesController.cs @@ -29,6 +29,33 @@ public class LocalLibrariesController(PgsqlContext context) : Controller return Ok(library); } + [HttpPatch("{LibraryId}")] + [ProducesResponseType(Status200OK)] + [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status400BadRequest)] + [ProducesResponseType(Status500InternalServerError, "text/plain")] + public IActionResult UpdateLocalLibrary(string LibraryId, [FromBody]NewLibraryRecord record) + { + LocalLibrary? library = context.LocalLibraries.Find(LibraryId); + if (library is null) + return NotFound(); + if (record.Validate() == false) + return BadRequest(); + + try + { + library.LibraryName = record.name; + library.BasePath = record.path; + context.SaveChanges(); + + return Ok(); + } + catch (Exception e) + { + return StatusCode(500, e.Message); + } + } + [HttpPatch("{LibraryId}/ChangeBasePath")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] @@ -85,9 +112,12 @@ public class LocalLibrariesController(PgsqlContext context) : Controller [HttpPut] [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status400BadRequest)] [ProducesResponseType(Status500InternalServerError, "text/plain")] - public IActionResult CreateNewLibrary([FromBody] NewLibraryRecord library) + public IActionResult CreateNewLibrary([FromBody]NewLibraryRecord library) { + if (library.Validate() == false) + return BadRequest(); try { LocalLibrary newLibrary = new (library.path, library.name);