Skip to content
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

chore(feat): impl. delete challenge endpoint #47

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

nully0x
Copy link
Collaborator

@nully0x nully0x commented Nov 21, 2024

This PR implements DELETE endpoint that allows administrators to remove challenges from the platform.

Changes

  • Added DELETE endpoint /api/challenge?id={uuid}
  • Added challenge deletion functionality to Challenge model
  • Added new error types for delete operations
  • Implemented admin-only authorization check

API Usage

DELETE /api/challenge/delete?id=550e8400-e29b-41d4-a716-446655440000
x-session-token: hxckr_your_session_token

Response

Success (200):

{
    "status": "success",
    "message": "Challenge deleted successfully"
}

Checks

  • Requires valid session token
  • Limited to admin users only
  • Validates challenge existence before deletion

Testing

  • [ x] Verify admin-only access
  • [x ] Verify successful challenge deletion
  • [ x] Verify error handling for non-existent challenges
  • [x ] Verify unauthorized access handling

use crate::schema::challenges::dsl::id;

match diesel::delete(challenges_table.filter(id.eq(challenge_id))).execute(connection) {
Ok(count) => Ok(count),
Copy link
Member

Choose a reason for hiding this comment

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

No need to return anything in the Ok response since it's not being used anywhere

Suggested change
Ok(count) => Ok(count),
Ok(_) => (),

@@ -140,4 +140,16 @@ impl Challenge {
FailedToGetChallenge(GetChallengeError(e)).into()
})
}

pub fn delete(connection: &mut PgConnection, challenge_id: &Uuid) -> Result<usize> {
Copy link
Member

Choose a reason for hiding this comment

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

No need for a return type if we're not returning anything based on my recommendation.

Suggested change
pub fn delete(connection: &mut PgConnection, challenge_id: &Uuid) -> Result<usize> {
pub fn delete(connection: &mut PgConnection, challenge_id: &Uuid) -> Result<()> {

@Extheoisah Extheoisah merged commit f436028 into main Nov 22, 2024
1 check passed
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