Skip to content

Feature/rename music file#122

Merged
Foqsz merged 7 commits intodevelopfrom
feature/renameMusicFile
Nov 3, 2025
Merged

Feature/rename music file#122
Foqsz merged 7 commits intodevelopfrom
feature/renameMusicFile

Conversation

@Foqsz
Copy link
Copy Markdown
Owner

@Foqsz Foqsz commented Nov 3, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 3, 2025 14:23
@Foqsz Foqsz merged commit beb3d11 into develop Nov 3, 2025
3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements functionality to update music names, which includes renaming the file in AWS S3 storage and updating the database record.

Key changes:

  • Added RequestUpdateMusic request model with MusicId and Name properties
  • Implemented RenameFileAsync method in S3Service to copy and delete S3 objects
  • Created UpdateMusicUseCase to orchestrate the music update operation

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
RequestUpdateMusic.cs New request model for music update operations
S3Service.cs Added RenameFileAsync method to handle S3 file renaming via copy-delete pattern
MusicWriteOnlyRepository.cs Added Update method to persist music changes
IS3Service.cs Added interface method for renaming files
IMusicWriteOnlyRepository.cs Added interface method for updating music entities
UpdateMusicUseCase.cs New use case implementing music update logic with S3 file renaming and database updates
IUpdateMusicUseCase.cs Interface definition for the update music use case
DependencyInjectionExtension.cs Registered UpdateMusicUseCase in DI container
MyMusicLibrary.API.csproj Enabled WarningsAsErrors compiler option
MusicController.cs Added HTTP PUT endpoint for music updates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (musicUpdate is null)
return;

Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Update method retrieves musicUpdate from the database but never applies the changes from the music parameter to it. The properties like Name and MusicKey should be copied from music to musicUpdate before calling _dbContext.Music.Update(musicUpdate).

Suggested change
// Copy updatable properties from music to musicUpdate
musicUpdate.Name = music.Name;
musicUpdate.MusicKey = music.MusicKey;
// Add other properties to update as needed

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +54
await _s3Service.RenameFileAsync(oldKey, newKey);

music.Name = request.Name;
music.MusicKey = newKey;

await _musicWriteOnlyRepository.Update(user, music);
await _unitOfWork.Commit();

Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the S3 rename operation succeeds but the database update fails, the S3 file will be renamed while the database still references the old key, causing data inconsistency. Consider implementing a rollback mechanism or reordering operations to update the database first, then rename the S3 file, so failures leave the system in a consistent state.

Suggested change
await _s3Service.RenameFileAsync(oldKey, newKey);
music.Name = request.Name;
music.MusicKey = newKey;
await _musicWriteOnlyRepository.Update(user, music);
await _unitOfWork.Commit();
music.Name = request.Name;
music.MusicKey = newKey;
await _musicWriteOnlyRepository.Update(user, music);
await _unitOfWork.Commit();
await _s3Service.RenameFileAsync(oldKey, newKey);

Copilot uses AI. Check for mistakes.

var oldKey = music.MusicKey!;
var extension = Path.GetExtension(oldKey);
var folder = Path.GetDirectoryName(oldKey)?.Replace("\\", "/");
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for constructing S3 keys by extracting folder paths and extensions could be fragile. S3 keys are not file system paths and don't have backslashes. The Path.GetDirectoryName method is designed for file system paths and may not handle S3 keys correctly in all cases. Consider using string manipulation with forward slashes directly or creating a dedicated method to parse S3 keys.

Suggested change
var folder = Path.GetDirectoryName(oldKey)?.Replace("\\", "/");
var lastSlashIndex = oldKey.LastIndexOf('/');
var folder = lastSlashIndex >= 0 ? oldKey.Substring(0, lastSlashIndex) : string.Empty;

Copilot uses AI. Check for mistakes.
Key = oldKey
};

await _s3Client.DeleteObjectAsync(deleteRequest);
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RenameFileAsync method has no error handling. If the copy operation succeeds but the delete operation fails, the old file will remain in S3, causing duplicate files and potential storage cost issues. Consider wrapping the delete operation in a try-catch or validating that the copy succeeded before attempting deletion.

Suggested change
await _s3Client.DeleteObjectAsync(deleteRequest);
try
{
await _s3Client.DeleteObjectAsync(deleteRequest);
}
catch (Exception ex)
{
// Log the error. Replace with your logging framework if available.
Console.WriteLine($"Failed to delete old S3 object '{oldKey}': {ex.Message}");
// Optionally, rethrow or handle as needed.
}

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Nov 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants