nVarap / CSABlog

A CSA Blog for a CSA Student
MIT License
0 stars 0 forks source link

FRQ Reflection and Connection | Varalu N #17

Open nVarap opened 9 months ago

nVarap commented 9 months ago

FOR FRQs, SCROLL TO THE VERY BOTTOM

PBL vs. CB

There are many parallels between the project based learning and Collegeboard materials. There are some overall themes that are present in both that can draw connection.

FRQ 1:

Below is something from our project, including the implementation of row-modulation in the company, changing the employees and which can change the employee records our project. By doing this, we are iterating and selecting in arrays, much like FRQ 1 needs us to do. We didn't really use 2D arrays, but it is something we could look for in the future!

@Slf4j
@RestController
@RequestMapping("/api/companies") // Base URL for all endpoints in this controller
@CrossOrigin(origins = "*") // Allowing cross-origin requests from any origin
public class CompanyController {

    private final CompanyService companyService; // Service to handle business logic
    private final ModelMapper modelMapper; // For entity-to-DTO mapping

    @Autowired
    public CompanyController(CompanyService companyService, ModelMapper modelMapper) {
        this.companyService = companyService;
        this.modelMapper = modelMapper;
    }

    // Endpoint to get all companies
    @GetMapping
    public ResponseEntity<List<CompanyDTO>> getAllCompanies() {
        List<Company> companies = companyService.getAllCompanies(); // Retrieve companies from the service
        List<CompanyDTO> companyDTOs = companies.stream()
                .map(company -> modelMapper.map(company, CompanyDTO.class)) // Map entities to DTOs
                .collect(Collectors.toList()); // Collect DTOs into a list
        return new ResponseEntity<>(companyDTOs, HttpStatus.OK); // Return DTO list with OK status
    }

    // Endpoint to get a company by its ID
    @GetMapping("/{companyId}")
    public ResponseEntity<Company> getCompanyById(@PathVariable Long companyId) {
        log.info("Attempting to retrieve company with ID: {}", companyId); // Log the attempt
        Optional<Company> company = companyService.getCompanyById(companyId); // Retrieve the company by ID
        if (company.isPresent()) { // If company is found
            log.info("Found company with ID: {}", companyId); // Log successful retrieval
            return ResponseEntity.ok().body(company.get()); // Return company with OK status
        } else { // If company is not found
            log.warn("Company with ID {} not found", companyId); // Log warning for not found
            return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // Return NOT_FOUND status
        }
    }

    // Endpoint to add a new company
    @PostMapping
    public ResponseEntity<Company> addCompany(@RequestBody Company company) {
        log.info("Attempting to add company: {}", company); // Log the attempt
        Company addedCompany = companyService.createCompany(company); // Create the company
        log.info("Company added successfully: {}", addedCompany); // Log successful addition
        return new ResponseEntity<>(addedCompany, HttpStatus.CREATED); // Return the added company with CREATED status
    }

    // Endpoint to delete a company by its ID
    @DeleteMapping("/{companyId}")
    public ResponseEntity<Void> deleteCompany(@PathVariable Long companyId) {
        System.out.println("Attempting to delete company with ID: " + companyId); // Log the attempt
        companyService.deleteCompany(companyId); // Delete the company
        System.out.println("Company with ID {} deleted successfully" + companyId); // Log successful deletion
        return ResponseEntity.noContent().build(); // Return NO_CONTENT status
    }
}

This also includes array modulation in the backend, iterating through various queries in order to get the correct instances. This requires us to delete rows of data, similar to that represented in this FRQ. These algorithms with arrays are very similar to those that we need to do in college board.

FRQ 2:

FRQ 2 highlights the use of creating classes in order to abstract ideas. From out project, take the employee class, which abstracts a person, or the company class, which also abstracts a company. This allows for behaviors to be modulated, or added. These POJOs are similar to the classes we build in CollegeBoard FRQs.

package com.nighthawk.spring_portfolio.mvc.linkr;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "employee")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
    private String position;
    private String email;
    private String password;
    private int followers;

    // change to hashmap
    private int ideas;
    private int joined; 

    private int investments; 

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id")
    private Company company;

    public Employee(String name, String position, String email, String password){
        this.name = name;
        this.position = position;
        this.email = email;
        this.password = password;
        this.ideas = 0;
        this.joined = 0;
        this.investments = 0;
    }

    public static Employee[] EmployeeInit(){
        Employee e1 = new Employee("Tanay", "CEO", "tpatel@gmail.com", "123Tanay!");
        Employee e2 = new Employee("Varaprasad", "CTO", "vnibhanupudi@gmail.com", "123Vlu!");
        Employee e3 = new Employee("Paaras", "CFO", "ppurohit@gmail.com", "123Paras!");

        Employee[] elist =  {e1, e2, e3};
        return elist;
    }
}

Company not included, but can also be shown. This is a regular POJO with behavior that allows us to abstract various behaviors.

FRQ 3

While we don't use array lists, array manipulation can be seen throughout our project as seen above. An example (arguably shaky) is our employee controller, which can manage the companies user is a part of. We didn't use sparse arrays, but those could be used for easy storage and augmentation of data

@Slf4j
@RestController
@RequestMapping("/api/employees") // Base URL for all endpoints in this controller
public class EmployeeController {

    private final EmployeeService employeeService; // Service for employee-related operations
    private final ModelMapper modelMapper; // For entity-to-DTO mapping
    private final PersonDetailsService personDetailsService; // Service for managing person details

    @Autowired
    public EmployeeController(EmployeeService employeeService, ModelMapper modelMapper, PersonDetailsService personDetailsService) {
        this.employeeService = employeeService;
        this.modelMapper = modelMapper;
        this.personDetailsService = personDetailsService;
    }

    // Endpoint to get all employees
    @GetMapping
    public ResponseEntity<List<EmployeeDTO>> getAllEmployees() {
        // Retrieving all employees and mapping them to DTOs
        List<Employee> employees = employeeService.getAllEmployees();
        List<EmployeeDTO> employeeDTOs = employees.stream()
                .map(employee -> modelMapper.map(employee, EmployeeDTO.class))
                .collect(Collectors.toList());
        return new ResponseEntity<>(employeeDTOs, HttpStatus.OK); // Returning DTO list with OK status
    }

    // Endpoint to get an employee by their ID
    @GetMapping("/{employeeId}")
    public ResponseEntity<Employee> getEmployeeById(@PathVariable Long employeeId) {
        log.info("Attempting to retrieve employee with ID: {}", employeeId); // Logging the attempt
        Optional<Employee> employee = employeeService.getEmployeeById(employeeId); // Retrieving employee by ID
        if (employee.isPresent()) { // If employee is found
            log.info("Found employee with ID: {}", employeeId); // Logging successful retrieval
            return ResponseEntity.ok().body(employee.get()); // Returning employee with OK status
        } else { // If employee is not found
            log.warn("Employee with ID {} not found", employeeId); // Logging warning for not found
            return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // Returning NOT_FOUND status
        }
    }

    // Endpoint to add a new employee
    @PostMapping
    public ResponseEntity<Employee> addEmployee(@RequestBody Employee employee) {
        log.info("Attempting to add employee: {}", employee); // Logging the attempt
        Employee addedEmployee = employeeService.createEmployee(employee); // Creating the employee
        log.info("Employee added successfully: {}", addedEmployee); // Logging successful addition

        // Creating a Person object and saving person details
        Person p6 = new Person();
        p6.setName("No Name");
        p6.setEmail(employee.getEmail());
        p6.setPassword(employee.getPassword());
        try {
            Date d = new SimpleDateFormat("MM-dd-yyyy").parse("05-15-2007");
            p6.setDob(d);
        } catch (Exception e) {
        }
        personDetailsService.save(p6); // Saving person details

        System.out.println("Hello"); // Printing a message

        return new ResponseEntity<>(addedEmployee, HttpStatus.CREATED); // Returning the added employee with CREATED status
    }

    // Endpoint to delete an employee by their ID
    @DeleteMapping("/{employeeId}")
    public ResponseEntity<Void> deleteEmployee(@PathVariable Long employeeId) {
        log.info("Attempting to delete employee with ID: {}", employeeId); // Logging the attempt
        employeeService.deleteEmployee(employeeId); // Deleting the employee
        log.info("Employee with ID {} deleted successfully", employeeId); // Logging successful deletion
        return ResponseEntity.noContent().build(); // Returning NO_CONTENT status
    }
}

By doing this we are managing an array of Employees in the database, removing and adding as seeing fit. We could also use arraylists in the backend for this purpose, but to store information like storing selected companies or followers as employees. and example can be seen below.

ArrayList<Employees> employeesLinked = new Arraylist<Employees>

This PAT work iterates through and resets the PATs

@Scheduled(fixedRate = 10000)
    public void TestTask(){
        List<LinkrPAT> pats = PATRepo.findAll();
        for(LinkrPAT p : pats){
            p.setPAT(generateUniqueToken(6));
            PATRepo.save(p);
        }
        System.out.println("executed");
    }

FRQ 4

For interfaces specifically, we use the AuthenticationEntryPoint interface in order to implement a lot of functionality from our JWTAuthenticationEntryPoint

package com.nighthawk.spring_portfolio.mvc.jwt;

import java.io.IOException;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

@Component
public class LinkrJWTAuthentication implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {

        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
    }
}

Other interfaces we use in our project are: public class PersonDetailsService implements UserDetailsService The details service that allows for JWT tokens to be made.

Key takeaways

Things to work on

Things I am good at

FRQs

FRQ Blog
FRQ 1 Blog
FRQ 2 Blog
FRQ 3 Blog
FRQ 4 Blog
jm1021 commented 9 months ago

I am not a paragraph reader, I get lost in your associations as I need context.. All the FRQs should have some code from your projects, let code do some of the talking. This is 4.0 * 80% work as is 3.2/3.6. You could correct it.

akshat122805 commented 9 months ago

Crossover Grading

Grader: Akshat Parikh

FRQ Grade Comments
1 0.9/0.9 Did the first question correctly, added the sum of an array. Took advantage of continue keyword in order to remove some parts of the arrays (Varalu made his own remove method, clever OOP). Nice description.
2 0.91/0.9 Completed necessary requirement for HiddenWord. Used StringBuilder to build strings to append other characters, and most importantly you are able to iterate.
3 0.9/0.9 We both approached the problem in the same manner, Varlalu explained it well. Nice description
4 0.9/0.9 Talked about interfaces, and talked about implementing it in a different group. Discussed ranges, and approached range problem in a similar manner. Checks if number is within the range. Nice description
FRQ Total 4.06125/3.6 (1.125 multiplier for early submission) <-- Total Grade
Association 3.9/4 Talked well about arraylist implementation, reduction, and 2D arrays being used throughout the project (Tinder for Ideation), and also discussed interfaces in a manner that explains how it relates to authorization being a method. Liked the idea, and additional reflection points after the PBL reflection.
TOTAL (4.06125 + 3.9) = 7.96125/7.2 <-- TOTAL SCORE
jm1021 commented 9 months ago

Crossover Grading

Grader: Akshat Parikh

FRQ Grade Comments 1 0.9/0.9 Did the first question correctly, added the sum of an array. Took advantage of continue keyword in order to remove some parts of the arrays (Varalu made his own remove method, clever OOP). Nice description. 2 0.91/0.9 Completed necessary requirement for HiddenWord. Used StringBuilder to build strings to append other characters, and most importantly you are able to iterate. 3 0.9/0.9 We both approached the problem in the same manner, Varlalu explained it well. Nice description 4 0.9/0.9 Talked about interfaces, and talked about implementing it in a different group. Discussed ranges, and approached range problem in a similar manner. Checks if number is within the range. Nice description FRQ Total 4.06125/3.6 (1.125 multiplier for early submission) <-- Total Grade Association 3.9/4 Talked well about arraylist implementation, reduction, and 2D arrays being used throughout the project (Tinder for Ideation), and also discussed interfaces in a manner that explains how it relates to authorization being a method. Liked the idea, and additional reflection points after the PBL reflection. TOTAL (4.06125 + 3.9) = 7.96125/7.2 <-- TOTAL SCORE

Nice crossover grading!!!