Skip to the content.
CPT Project Home Personalized Project Reference (PPR) CPT Requirements

Personalized Project Reference

Component C of CPT

4 Question Domains

  • WR 1: Program Design, Function, and Purpose
  • WR 2(a): Algorithm Development
  • WR 2(b): Errors and Testing
  • WR 2(c): Data and Procedural Abstraction

*PPR submitted with digital portfolio and will be referenced when answering written response prompts

What is under the PPR:

4 Code segments to be submitted

  1. List creation
  2. List process
  3. Function (with parameters that goes through the list and has an if else statement)
  4. The call to function

1. List Creation - camping post api, class _FILTER

camping_posts = camping.query.filter_by(_channel_id=data['channel_id']).all()


This line creates a list of camping posts by querying the database for all posts where the _channel_id matches the channel_id from the request.

2. List Process

json_ready = [campingPost.read() for campingPost in camping_posts]

This creates a list called json_ready by iterating (for loop) over each campingPost in the camping_posts list and calling its read() method. The for loop inside the square brackets is list comprehension.

3. Function

class _FILTER(Resource):
        @token_required()
        def post(self):
            
            data = request.get_json()
            if data is None:
                return {'message': 'Channel and User data not found'}, 400
            if 'channel_id' not in data:
                return {'message': 'Channel ID not found'}, 400
            
            camping_posts = camping.query.filter_by(_channel_id=data['channel_id']).all()
            json_ready = [campingPost.read() for campingPost in camping_posts]
            return jsonify(json_ready)

The post(self) method retrieves and validates the JSON data sent in the request; if the data is missing or lacks the channel_id field, it returns an error message with a 400 status code indicating bad input (selection: if else statement). Each line within the function is sequencing, as it goes through each step.

4. Call to Function

async function fetchArguments(channelId) {
    try {
      const response = await fetch(`${pythonURI}/api/campingPosts/filter`, {
        ...fetchOptions,
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ channel_id: channelId })
      });

The fetchArguments function sends a POST request with a channel_id to the API. The server processes the request, gets the posts from the database that match the channel_id, and sends the data back as a JSON response. The fetchArguments function then receives and uses that data.