Skip to content

[Feature] Edit Quest backend logicΒ #82

@karastoyanov

Description

@karastoyanov

✨ Feature Description

Allow admins to edit an existing coding quest via a PUT /api/quests/<quest_id> endpoint. All mutable fields can be updated while immutable metadata (id, created_at, quest_author) is preserved.

🧩 Problem Statement

There is currently no way to update a quest once it has been created. Admins need the ability to fix errors in quest content, adjust difficulty, or update test inputs/outputs without having to delete and recreate the quest.

πŸ’‘ Proposed Solution

Add a PUT /api/quests/<quest_id> endpoint accessible only by the admins. The route validates the payload and persists the changes. Only fields present in the request body are updated (partial update support).

Mutable Fields

language          = db.Column(db.String(50),  nullable=False)
difficulty        = db.Column(db.String(50),  nullable=False)
quest_name        = db.Column(db.String(255), nullable=False)
condition         = db.Column(db.Text,        nullable=False)
function_template = db.Column(db.Text,        nullable=False)

# Inputs (input_0 is the null/edge-case test)
input_0  … input_9  = db.Column(db.Text, nullable=True)

# Outputs (output_0 is the null/edge-case test)
output_0 … output_9 = db.Column(db.Text, nullable=True)

example_solution  = db.Column(db.Text, nullable=True)

Immutable Fields

id           # Primary key β€” never editable
created_at   # Set on creation β€” never editable
quest_author # Original quest author β€” never editable

Error Responses

Status Scenario
400 Validation failure β€” missing/invalid required field
403 Requester is not an admin
404 No quest found for the given quest_id

πŸ”„ Alternatives Considered

  • A PUT /api/quests/<quest_id> endpoint exists and is accessible only to admins
  • All mutable fields can be updated via the endpoint
  • id, created_at, and quest_author are immutable and cannot be modified
  • updated_at is automatically refreshed on every successful edit
  • Request body is validated β€” missing required fields return 400 Bad Request with descriptive errors
  • Attempting to edit a non-existent quest returns 404 Not Found
  • Unauthorized edit attempts return 403 Forbidden
  • Unit tests cover: successful edit, partial update, missing required fields, unauthorized access, and quest not found

πŸ“‹ Acceptance Criteria

  • Criterion 1
  • Criterion 2
  • Criterion 3

πŸ”— Related Issues / Links

πŸ“Ž Additional Context

  • solved_times is intentionally excluded from the edit endpoint β€” it is managed by the quest-solve flow, not manual edits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality or behavior
    No fields configured for Feature.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions