Skip to content

fix(pay-slip)[backend]: delete file from storage on record deletion#39

Open
MohamadNazik wants to merge 1 commit intoLSFLK:mainfrom
MohamadNazik:fix/delete-payslip-file-from-storage
Open

fix(pay-slip)[backend]: delete file from storage on record deletion#39
MohamadNazik wants to merge 1 commit intoLSFLK:mainfrom
MohamadNazik:fix/delete-payslip-file-from-storage

Conversation

@MohamadNazik
Copy link
Contributor

@MohamadNazik MohamadNazik commented Mar 10, 2026

Summary

This PR fixes the issue where deleting a pay slip left orphaned files in Firebase Storage. The deletion process now cleans up both the storage object and the database record.

Changes

  • Storage: Added functionality to delete files from the storage bucket.
  • Handler: Updated the delete handler to remove the storage file before the DB record, with graceful handling for files already missing.
  • API Spec: Updated documentation to reflect file deletion and added missing auth response codes.

Closes #31

@MohamadNazik MohamadNazik requested a review from a team March 10, 2026 04:39
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where deleting pay slip records from the database would leave their corresponding files orphaned in Firebase Storage. The changes introduce a more robust deletion process that ensures both the database record and the associated storage file are removed. This improves data consistency and prevents unnecessary storage consumption, while also enhancing the API documentation for the delete endpoint.

Highlights

  • Orphaned File Prevention: Implemented a mechanism to delete associated files from Firebase Storage when a pay slip record is removed from the database, preventing orphaned storage objects.
  • Robust Deletion Logic: The delete handler now attempts to remove the file from storage first. If the file is already missing (e.g., a 404 error from storage), the database record deletion proceeds, ensuring cleanup even in inconsistent states.
  • API Specification Update: The OpenAPI specification for the delete pay slip endpoint has been updated to accurately reflect the file deletion process and include new 401 (Unauthorized) and 403 (Forbidden) response codes for better API clarity.
Changelog
  • pay-slip-app/backend/api/openapi.yaml
    • Updated the summary and added a description for the delete pay slip endpoint to reflect file deletion.
    • Added 401 (Unauthorized) and 403 (Forbidden) HTTP response codes to the delete endpoint.
    • Refined the description for the 204 success response.
    • Updated the summary and added a description for the delete pay slip endpoint to reflect file deletion.
    • Added 401 (Unauthorized) and 403 (Forbidden) HTTP response codes to the delete endpoint.
    • Refined the description for the 204 success response.
  • pay-slip-app/backend/internal/handlers/payslip_handlers.go
    • Modified the DeletePaySlip handler to fetch the full pay slip object before deletion.
    • Implemented storage file deletion before database record deletion in the DeletePaySlip handler.
    • Added error handling for storage deletion, allowing database record deletion if the file is already missing from storage.
    • Updated the error message for database deletion failures to be more specific.
  • pay-slip-app/backend/internal/storage/storage.go
    • Introduced a new DeleteFile method to the FirebaseStorage struct to facilitate object deletion from Firebase Storage.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a two-phase deletion process for pay slips, first removing the associated file from Firebase Storage and then deleting the record from the database. This involved adding a DeleteFile method to the FirebaseStorage service and updating the OpenAPI specification to reflect the new deletion logic and include additional error responses. The review comments highlight that the error handling for storage deletion in payslip_handlers.go is fragile due to its reliance on string-matching error messages and should be refactored to use the specific storage.ErrObjectNotExist error type for robustness. Additionally, the review suggests replacing fmt.Printf with log.Printf for consistent logging and removing development-related comments for improved code clarity.

@MohamadNazik MohamadNazik force-pushed the fix/delete-payslip-file-from-storage branch 2 times, most recently from e9bd3ff to ee66717 Compare March 10, 2026 05:26
@MohamadNazik MohamadNazik force-pushed the fix/delete-payslip-file-from-storage branch from ee66717 to d26d7b3 Compare March 10, 2026 09:33
@MohamadNazik MohamadNazik requested a review from ginaxu1 March 10, 2026 09:38
Copy link

@ginaxu1 ginaxu1 left a comment

Choose a reason for hiding this comment

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

Lgtm

@MohamadNazik MohamadNazik changed the title fix(pay-slip): delete file from storage on record deletion #31 fix(pay-slip)[backend]: delete file from storage on record deletion #31 Mar 10, 2026
@MohamadNazik MohamadNazik changed the title fix(pay-slip)[backend]: delete file from storage on record deletion #31 fix(pay-slip)[backend]: delete file from storage on record deletion Mar 10, 2026
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.

fix(pay-slip): delete file from storage when a pay slip is deleted

2 participants