[backend/api] Add conflict check to UpdateFileParent
This commit is contained in:
parent
957e84eab7
commit
6322d5fb91
1 changed files with 9 additions and 1 deletions
|
@ -241,7 +241,8 @@ public class DriveController(
|
|||
[Authenticate]
|
||||
[Authorize]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
[ProducesErrors(HttpStatusCode.NotFound)]
|
||||
[ProducesErrors(HttpStatusCode.NotFound, HttpStatusCode.Conflict)]
|
||||
[SuppressMessage("Performance", "CA1862", Justification = "string.Equals() cannot be used in DbSet LINQ operations")]
|
||||
public async Task<DriveFileResponse> UpdateFileParent(string id, DriveMoveRequest request)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
@ -258,6 +259,13 @@ public class DriveController(
|
|||
throw GracefulException.NotFound("The new parent folder doesn't exist");
|
||||
}
|
||||
|
||||
var existing = await db.DriveFiles
|
||||
.AnyAsync(p => p.Name.ToLower() == file.Name.ToLower()
|
||||
&& p.FolderId == request.FolderId
|
||||
&& p.UserId == user.Id);
|
||||
if (existing)
|
||||
throw GracefulException.Conflict("A file with this name already exists in this folder");
|
||||
|
||||
file.FolderId = request.FolderId;
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue