[backend/api] Add endpoint to move DriveFile and change move DriveFolder to POST

This commit is contained in:
pancakes 2024-12-23 00:38:27 +10:00 committed by Laura Hausmann
parent da6d080fa2
commit 038637339e
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -235,6 +235,33 @@ public class DriveController(
return StatusCode(StatusCodes.Status202Accepted);
}
[HttpPost("{id}/move")]
[Authenticate]
[Authorize]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.NotFound)]
public async Task<DriveFileResponse> UpdateFileParent(string id, DriveMoveRequest request)
{
var user = HttpContext.GetUserOrFail();
var file = await db.DriveFiles
.FirstOrDefaultAsync(p => p.Id == id && p.UserId == user.Id)
?? throw GracefulException.RecordNotFound();
if (request.FolderId != null)
{
var parent = await db.DriveFolders
.FirstOrDefaultAsync(p => p.Id == request.FolderId && p.UserId == user.Id);
if (parent == null)
throw GracefulException.NotFound("The new parent folder doesn't exist");
}
file.FolderId = request.FolderId;
await db.SaveChangesAsync();
return await GetFileById(file.Id);
}
[HttpGet("folder")]
[Authenticate]
[Authorize]
@ -373,7 +400,7 @@ public class DriveController(
await db.SaveChangesAsync();
}
[HttpPut("folder/{id}/move")]
[HttpPost("folder/{id}/move")]
[Authenticate]
[Authorize]
[ProducesResults(HttpStatusCode.OK)]