tanayp327 / bloggy

MIT License
0 stars 0 forks source link

FRQ Reflection and Connection #13

Open tanayp327 opened 8 months ago

tanayp327 commented 8 months ago

FRQ 1: 2D Array

In the first FRQ, which centers on 2D arrays, the focus is on the manipulation of 2D arrays, specifically examining the diversity between rows. Although our project does not explicitly utilize 2D arrays, the underlying methodology closely aligns with our database management approach. Consider our CompanyController class:

@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
    }
}

Within this controller, we implement logic to compare different rows of data, resembling the comparison operations performed on rows within a 2D array. This functionality allows us to conduct diverse operations on our database, akin to the algorithmic procedures outlined in the FRQ.

Moreover, the FRQ's emphasis on array attributes represented as 1D arrays resonates with our project's abstraction techniques. For instance, we often isolate specific attributes of our data objects, similar to reducing the dimensionality of a 2D array to abstract certain characteristics. This abstraction facilitates efficient data handling and analysis, aligning with the principles illustrated in the FRQ.

FRQ 2: List/ArrayList

In the second FRQ, which highlights List/ArrayList algorithms, our PATTask class exemplifies their significance:

package com.nighthawk.spring_portfolio.mvc.linkrAuthentication;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class PATTask {
    @Autowired
    PatJpaRepository PATRepo; 

    @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");
    }

    public String generateUniqueToken(int length) {
        SecureRandom secureRandom = new SecureRandom();
        byte[] randomBytes = new byte[length / 2];
        secureRandom.nextBytes(randomBytes);
        BigInteger bigInteger = new BigInteger(1, randomBytes);
        String token = bigInteger.toString(16);

        // Ensure the token has the specified length
        while (token.length() < length) {
            token = "0" + token;
        }

        return token;
    }

}

Within this task, we manipulate lists to manage employee-related operations, mirroring the algorithmic thinking highlighted in the FRQ. Whether it's adding new employees, retrieving employee data, or deleting records, our utilization of list-based operations reflects the fundamental concepts outlined in the FRQ.

Furthermore, the FRQ's emphasis on string manipulation and concatenation resonates with our project's handling of textual data. For instance, in real-time input scenarios or search functionalities, efficient string manipulation is crucial for constructing and processing queries. By leveraging Java's string manipulation capabilities, we ensure robust functionality across various aspects of our project, akin to the scenarios depicted in the FRQ.

FRQ 3: Methods and Control Structures/2D Arrays

The third FRQ, focused on Methods and Control Structures, finds reflection in the backbone of our project's backend architecture, facilitating modular design and streamlined execution. In the context of the FRQ, these concepts are exemplified through custom methods and control structures utilized within our project. In the CompanyControllerandEmployeeController we employ a variety of methods and control structures to orchestrate database operations, validate user inputs, and enforce business rules. The modular design facilitated by these constructs ensures code reusability, maintainability, and scalability, aligning with the principles emphasized in the FRQ.

FRQ 4: Interfaces

Although interfaces are not directly utilized within our project, the concepts of abstraction, polymorphism, and contract-based programming are inherent in our design philosophy. While the FRQ focuses on interfaces as contracts for defining behavior, our project achieves similar objectives through class hierarchies, inheritance, and method overriding. Consider the following snippets from our JWT (JSON Web Token) authentication components:

@RestController
@CrossOrigin(origins = "*")
public class JwtApiController {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @Autowired
    private PersonDetailsService personDetailsService;

    @PostMapping("/authenticate")
    public ResponseEntity<?> createAuthenticationToken(@RequestBody Person authenticationRequest) throws Exception {
        System.out.println(authenticationRequest.getEmail());
        System.out.println(authenticationRequest.getPassword());
        authenticate(authenticationRequest.getEmail(), authenticationRequest.getPassword());
        final UserDetails userDetails = personDetailsService
                .loadUserByUsername(authenticationRequest.getEmail());
        final String token = jwtTokenUtil.generateToken(userDetails);
        final ResponseCookie tokenCookie = ResponseCookie.from("jwt", token)
            .httpOnly(true)
            .secure(true)
            .path("/")
            .maxAge(3600)
            .sameSite("None; Secure")
            // .domain("example.com") // Set to backend domain
            .build();
            System.out.println("returning!");
        return ResponseEntity.ok().header(HttpHeaders.SET_COOKIE, tokenCookie.toString()).build();
    }

    private void authenticate(String username, String password) throws Exception {
        try {
            authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
        } catch (DisabledException e) {
            throw new Exception("USER_DISABLED", e);
        } catch (BadCredentialsException e) {
            throw new Exception("INVALID_CREDENTIALS", e);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
}

In these classes, the interactions are governed by predefined contracts and shared interfaces, ensuring consistent behavior and interoperability. While the terminology may differ, the underlying principles of interface-based programming are evident in our project's architecture.

hsinaDitaM commented 8 months ago

FRQ's

3.6/4.0 Tanay did the FRQ. it had good explanations and the code ran. the code did not have junk and he understood the code that he wrote. It didn't look like code that out generated from AI.

FRQ 1:

0.9/1.0 The code was elucidated, and subsequently, its functionality was expounded upon in a comprehensive manner. Following this detailed explanation, the code was executed, and the intended operations were successfully carried out. but for real, the code was detailed with excellent detail. when he spoke about his code, I understood it and it didn't seem like it was written by an AI 👍

FRQ 2:

0.9/1.0 could have explained it to me a bit better but the code seemed excellent and after reviewing the code again by myself, everything was correct. Although the initial explanation might have lacked some clarity, a personal reassessment led to a clear understanding of the code's correctness. Upon closer inspection, the code appeared solid, and I felt confident in its accuracy and functionality. Again for this, the code did not seem ai generated.

FRQ 3:

0.9/1.0 same as FRQ 1, did everything pretty good. code ran. he did the best he could, he did skip over some part of the code but over all, he did will, the reason that I gave him a 0.9 and not a 0.8 is because he looked like he could talk about his code for 20 more minutes if I did not stop him

FRQ 4:

0.9/1.0 the code could use a bit more editing to make it less clunky but the code seemed ok and it ran. While acknowledging that the code could benefit from some refinement to enhance its readability, it was found to be acceptable and executed successfully without any issues. Despite its potential for improvement in terms of clarity, the code demonstrated satisfactory functionality during execution.

Association

3.6/4.0 He effectively correlated his Free Response Question (FRQ) concepts with his Problem-Based Learning (PBL) approach, creating a cohesive and meaningful connection. I appreciated his clear articulation of the code, illustrating how it aligns with the overarching project. The inclusion of the actual code further enhanced the transparency of his explanation. somethings that he could have done better is to explain the association to me better since I did not understand some of the parts that he said, other than that, perfect

GOOD STUFF!!!!!