Skip to the content.

PPR BLOG

PPR Blog - AP CSP Component C

πŸš€ AP CSP Component C: Personalized Project Reference

Date: March 12, 2025

πŸ” Overview

This submission includes four required code segments demonstrating key programming concepts:

  • Student-Developed Procedure: A function implementing **sequencing, selection, and iteration**.
  • Function Call: Shows where the student-developed procedure is used in the program.
  • List Implementation: A **list (or collection type)** used to store and manage data efficiently.
  • List Processing: Using data from the list to fulfill program functionality.

1️⃣ Student-Developed Procedure

πŸ“Œ Code Segment: Comment Creation Function

@token_required()
def add_comment(user_id, post_id, content):
    if not content.strip():
        return jsonify({"message": "Comment cannot be empty"}), 400

    comment = CarComments(user_id=user_id, post_id=post_id, content=content)
    comment.create()
    
    return jsonify(comment.read())
                

πŸ“Œ Explanation

  • Sequencing: The function follows a structured order: validating input, creating a comment, saving it, and returning a response.
  • Selection: An `if` condition ensures that an empty comment is not submitted.
  • Iteration: The `get` function later iterates over all comments for retrieval.

2️⃣ Function Call

πŸ“Œ Code Segment: Calling the Procedure

@app.route("/api/add_comment", methods=["POST"])
@token_required()
def post_comment():
    data = request.get_json()
    return add_comment(g.current_user.id, data["post_id"], data["content"])
                

πŸ“Œ Explanation

  • This function calls `add_comment()`, passing the current user’s ID, post ID, and comment content.
  • It ensures secure authentication with `@token_required()`.
  • The API processes user input and interacts with the database.

3️⃣ List Implementation

πŸ“Œ Code Segment: Storing Data in a List

def get_comments_for_post(post_id):
    comments = CarComments.query.filter_by(post_id=post_id).all()
    return [comment.read() for comment in comments]
                

πŸ“Œ Explanation

  • This function retrieves all comments related to a specific post.
  • A list comprehension processes multiple comments efficiently.

4️⃣ List Processing

πŸ“Œ Code Segment: Processing the List

def format_comments(comments):
    formatted = []
    
    for comment in comments:
        formatted.append(f"{comment['user_id']} said: {comment['content']}")

    return formatted
                

πŸ“Œ Explanation

  • A for loop iterates over the comments list.
  • Each comment is formatted into a structured text output.
  • The function creates a processed list for display.

πŸ“Œ Summary of PPR Components

Component Purpose
Student-Developed Procedure Validates, creates, and stores user-submitted comments.
Function Call Securely calls the procedure through an API endpoint.
List Implementation Retrieves and stores multiple comments efficiently.
List Processing Uses iteration (for loop) to process and format comment data.

πŸ† Final Thoughts

This submission highlights my ability to design, implement, and process structured data in a web-based comment system.

By using sequencing, selection, iteration, lists, and function calls, I successfully created a functional, interactive, and well-structured program for my AP CSP Create Performance Task.