Skip to content

Implement DELETE endpoint for heroes API #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 27, 2025

Implemented DELETE functionality for heroes

This PR adds the ability to delete heroes from the database through a REST API endpoint. The implementation follows the existing code patterns and includes proper error handling.

Changes made:

  1. Added deleteHeroById method to HeroService that:

    • Takes a hero ID as parameter
    • Attempts to find and delete the hero using findOneAndDelete
    • Returns success/failure result with appropriate error messages
  2. Added deleteHero method to HeroController that:

    • Validates that the ID is a valid number
    • Calls the service method
    • Returns appropriate HTTP status codes (200 for success, 404 for not found)
  3. Added DELETE route to hero.routes.ts:

    router.delete('/:id', (req, res, next) => heroController.deleteHero(req, res, next));
  4. Updated documentation:

    • Added DELETE endpoint details to API reference
    • Added usage examples with cURL
    • Added example DELETE request to heroes.http file

Testing:

The endpoint can be tested with:

curl -X DELETE http://localhost:3000/api/heroes/1

Response formats:

Success (200):

{
  "message": "Hero deleted successfully"
}

Not Found (404):

{
  "error": "Hero not found"
}

Invalid ID (400):

{
  "error": "Invalid hero ID. ID must be a number."
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits May 27, 2025 09:22
Co-authored-by: 0GiS0 <175379+0GiS0@users.noreply.github.com>
Co-authored-by: 0GiS0 <175379+0GiS0@users.noreply.github.com>
Co-authored-by: 0GiS0 <175379+0GiS0@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Implementar eliminación de héroes (endpoint DELETE /api/heroes/:id) Implement DELETE endpoint for heroes API May 27, 2025
@Copilot Copilot AI requested a review from 0GiS0 May 27, 2025 09:25
Copilot finished work on behalf of 0GiS0 May 27, 2025 09:25
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