Skip to content

Conversation

@AhtishamShahid
Copy link
Contributor

@AhtishamShahid AhtishamShahid commented Nov 6, 2025

Description

Issue: #37465

This PR adds a new PATCH API endpoint to allow an instructor to update the price for a specific course enrollment mode (e.g., verified).

PATCH /api/instructor/v1/courses/{course_key}/modes/{mode_slug}/price

This endpoint requires InstructorPermission (is_staff) and expects the Content-Type header to be application/merge-patch+json. The price should be sent as an integer in the smallest currency unit (e.g., cents).

Example Request

PATCH /api/instructor/v1/courses/course-v1:TestOrg+CS101+2025/modes/verified/price
Content-Type: application/merge-patch+json
Accept: application/json
X-CSRFToken: [Your-Token-Here]

{
    "price": 3900
}

Success Response

The endpoint returns an empty body with a 204 No Content status upon a successful price update.

HTTP 204 No Content
Allow: PATCH, HEAD, OPTIONS

Error Responses

  • 400 Bad Request: If the price field is missing, not an integer, or negative.
  • 401 Unauthorized: If the user is not authenticated.
  • 403 Forbidden: If the user is not an instructor (is_staff=False).
  • 404 Not Found: If the course_key or mode_slug does not exist.
  • 415 Unsupported Media Type: If the Content-Type is not application/merge-patch+json.

Testing

  • Added new unit tests in lms/djangoapps/instructor/tests/test_api.py under the TestCourseModePriceView class.
  • Tests cover success (204), auth (401), permissions (403), not found (404), and various bad request (400) scenarios.

@AhtishamShahid AhtishamShahid changed the title Ahtisham/add course modes api patch feat: added update mode price api for instructors Nov 6, 2025
@AhtishamShahid AhtishamShahid changed the base branch from master to ahtisham/add_course_modes_apis November 7, 2025 07:04
@AhtishamShahid AhtishamShahid force-pushed the ahtisham/add_course_modes_apis branch from 34201ee to 6d0bf82 Compare November 7, 2025 07:34
fix: resolved linter errors

chore: added docs to api

feat: added update mode price api for instructors

fix: resolved linter errors

fix: resolved linter errors

fix: removed redundant code
@AhtishamShahid AhtishamShahid force-pushed the ahtisham/add_course_modes_api_patch branch from 95fdf39 to 43cc724 Compare November 7, 2025 07:42
@awais786 awais786 requested a review from Copilot November 7, 2025 09:42
Copy link
Contributor

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 adds a new API endpoint for updating the price of a specific course enrollment mode via PATCH request. The endpoint allows instructors and staff to modify course mode pricing dynamically.

  • Introduces CourseModePriceView API view with PATCH method for updating mode prices
  • Adds ModePriceUpdateSerializer to validate price update requests
  • Enhances InstructorPermission to include GlobalStaff user support
  • Adds comprehensive test coverage for authentication, authorization, and validation scenarios

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
lms/djangoapps/instructor/views/serializer.py Adds ModePriceUpdateSerializer to validate price field in update requests
lms/djangoapps/instructor/views/api_urls.py Registers new course_mode_price URL pattern for the price update endpoint
lms/djangoapps/instructor/views/api.py Implements CourseModePriceView with PATCH method and adds import; includes minor typo fix in unrelated docstring
lms/djangoapps/instructor/tests/test_api.py Adds TestCourseModePriceView test suite covering success, permission, validation, and error cases
lms/djangoapps/instructor/permissions.py Extends InstructorPermission.has_permission to grant access to GlobalStaff users

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

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