<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nwinsen</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nwinsen"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nwinsen"/>
	<updated>2026-08-08T16:51:00Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165167</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165167"/>
		<updated>2025-04-23T03:59:37Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;User Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_User_flow_diagram.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Action_allowed_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Index_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Set_priority_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:Assign_bidding_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Service: AssignBiddingService ======&lt;br /&gt;
&lt;br /&gt;
This service object takes the logic from assign_bidding and compacts it into a single responsibility service object where it can be used to eliminate bloat from the controller&lt;br /&gt;
&lt;br /&gt;
[[File:Assign_bidding_service.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Service: CompletedReviewCounterService ======&lt;br /&gt;
&lt;br /&gt;
This service object counts the number of completed reviews it is passed&lt;br /&gt;
&lt;br /&gt;
[[File:Bids_priority_service.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Service: BidsPriorityService ======&lt;br /&gt;
&lt;br /&gt;
This service object shows the priority of bids&lt;br /&gt;
&lt;br /&gt;
[[File:Bids_priority_service.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Response'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout expertiza and the Python Webservice&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Bids_priority_service.png&amp;diff=165166</id>
		<title>File:Bids priority service.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Bids_priority_service.png&amp;diff=165166"/>
		<updated>2025-04-23T03:58:24Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165165</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165165"/>
		<updated>2025-04-23T03:57:35Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Component Design: ReviewBidsController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;User Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_User_flow_diagram.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Action_allowed_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Index_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Set_priority_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:Assign_bidding_2542.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Service: AssignBiddingService ======&lt;br /&gt;
&lt;br /&gt;
This service object takes the logic from assign_bidding and compacts it into a single responsibility service object where it can be used to eliminate bloat from the controller&lt;br /&gt;
&lt;br /&gt;
[[File:Assign_bidding_service.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Response'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout expertiza and the Python Webservice&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_priority_2542.png&amp;diff=165162</id>
		<title>File:Set priority 2542.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_priority_2542.png&amp;diff=165162"/>
		<updated>2025-04-23T03:51:48Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Index_2542.png&amp;diff=165161</id>
		<title>File:Index 2542.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Index_2542.png&amp;diff=165161"/>
		<updated>2025-04-23T03:51:36Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding_service.png&amp;diff=165160</id>
		<title>File:Assign bidding service.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding_service.png&amp;diff=165160"/>
		<updated>2025-04-23T03:51:29Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding_2542.png&amp;diff=165159</id>
		<title>File:Assign bidding 2542.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding_2542.png&amp;diff=165159"/>
		<updated>2025-04-23T03:51:19Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Action_allowed_2542.png&amp;diff=165158</id>
		<title>File:Action allowed 2542.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Action_allowed_2542.png&amp;diff=165158"/>
		<updated>2025-04-23T03:51:11Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165113</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165113"/>
		<updated>2025-04-23T03:15:22Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Additional Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Response'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout expertiza and the Python Webservice&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165111</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165111"/>
		<updated>2025-04-23T03:13:34Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Response'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165110</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165110"/>
		<updated>2025-04-23T03:13:22Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* API/Webservice Integration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165106</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165106"/>
		<updated>2025-04-23T03:12:57Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165087</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165087"/>
		<updated>2025-04-23T02:59:13Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Component Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
== Component Design ==&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165081</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165081"/>
		<updated>2025-04-23T02:58:48Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Design Principles and Refactoring Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164922</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164922"/>
		<updated>2025-04-23T01:10:22Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Architecture and Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164921</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164921"/>
		<updated>2025-04-23T01:09:48Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Architecture and Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164910</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164910"/>
		<updated>2025-04-23T01:02:59Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164905</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164905"/>
		<updated>2025-04-23T01:01:14Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Timeout and Retry Policies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164892</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164892"/>
		<updated>2025-04-23T00:53:48Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Review Bids Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164889</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164889"/>
		<updated>2025-04-23T00:50:44Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Review Bids Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ==== &amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164888</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164888"/>
		<updated>2025-04-23T00:50:23Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ==== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ==== &amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164885</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164885"/>
		<updated>2025-04-23T00:49:26Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
=== Review Bids Controller ===&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
=== AssignBiddingService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
=== BidsAlgorithmService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
=== BidsPriorityService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
=== CompletedReviewsCounterService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
=== External Webservice === &amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164883</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164883"/>
		<updated>2025-04-23T00:49:08Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
=== Review Bids Controller ===&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
=== AssignBiddingService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
=== BidsAlgorithmService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
=== BidsPriorityService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
=== CompletedReviewsCounterService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC11 - .count_reviews - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
=== External Webservice === &amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164882</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164882"/>
		<updated>2025-04-23T00:48:54Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Review Bids Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
=== Review Bids Controller ===&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
=== AssignBiddingService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
=== BidsAlgorithmService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
=== BidsPriorityService=== &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
=== CompletedReviewsCounterService === &amp;lt;strong&amp;gt;NEW&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC11 - .count_reviews - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
=== External Webservice === &amp;lt;strong&amp;gt;This was tested via pytest in its own repository&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164874</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164874"/>
		<updated>2025-04-23T00:44:41Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
=== Review Bids Controller ===&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;AssignBiddingService&amp;lt;/strong&amp;gt; NEW&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;BidsAlgorithmService&amp;lt;/strong&amp;gt; NEW&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;BidsPriorityService&amp;lt;/strong&amp;gt; NEW&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164687</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164687"/>
		<updated>2025-04-22T17:57:28Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164686</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=164686"/>
		<updated>2025-04-22T17:57:01Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163726</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163726"/>
		<updated>2025-04-08T02:29:50Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Architecture and Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* The data flow of our application is highlighted in the above diagram!&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
==== Testing Plan ====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163724</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163724"/>
		<updated>2025-04-08T02:28:54Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* esting Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
==== Testing Plan ====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163722</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163722"/>
		<updated>2025-04-08T02:28:29Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
==== esting Plan ====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163223</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163223"/>
		<updated>2025-04-04T19:27:53Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Component Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on reviews, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what reviewsstudents intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px]]&lt;br /&gt;
&amp;lt;b&amp;gt;Note: Service Objects were not shown, assumed to be integrated with controllers.&amp;lt;/b&amp;gt;&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
====Testing Plan====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163222</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163222"/>
		<updated>2025-04-04T19:27:12Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on reviews, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what reviewsstudents intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px]]&lt;br /&gt;
&amp;lt;b&amp;gt;Note: Service Objects were not shown, assumed to be integrated with controllers.&amp;lt;/b&amp;gt;&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_action_allowed.JPG|700px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_index.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_show.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_set_priority.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:X9x.png|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
[[File:Controller_private_methods.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
====Testing Plan====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163221</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163221"/>
		<updated>2025-04-04T19:26:55Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on reviews, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what reviewsstudents intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px]]&lt;br /&gt;
*Note: Service Objects were not shown, assumed to be integrated with controllers.&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_action_allowed.JPG|700px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_index.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_show.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_set_priority.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:X9x.png|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
[[File:Controller_private_methods.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
====Testing Plan====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163220</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163220"/>
		<updated>2025-04-04T19:25:41Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of reviews the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on reviews, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what reviewsstudents intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_action_allowed.JPG|700px]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_index.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_show.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_set_priority.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:X9x.png|700px]]]&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
[[File:Controller_private_methods.JPG|700px]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
====Testing Plan====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163219</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163219"/>
		<updated>2025-04-04T18:34:17Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop topics, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Topic sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163218</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163218"/>
		<updated>2025-04-04T18:34:10Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* E2542 - Reimplement Review Bidding Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;# E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop topics, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Topic sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163217</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163217"/>
		<updated>2025-04-04T18:33:48Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop topics, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Topic sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163216</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163216"/>
		<updated>2025-04-04T18:23:59Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Previous Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop topics, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Topic sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163212</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163212"/>
		<updated>2025-04-04T17:59:22Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop topics, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Topic sign up&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163211</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163211"/>
		<updated>2025-04-04T17:56:14Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163210</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163210"/>
		<updated>2025-04-04T17:56:05Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_flow2542.png|900px|center]]&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163209</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163209"/>
		<updated>2025-04-04T17:55:43Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:Content_diagram2542.png|900px|center]]&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163208</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163208"/>
		<updated>2025-04-04T17:54:52Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[Content_flow2542.png]&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163207</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163207"/>
		<updated>2025-04-04T17:53:56Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
===System Overview===&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[Content_flow2542.png]&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163206</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163206"/>
		<updated>2025-04-04T17:53:47Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
===System Overview===&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[Content_flow2542.png]]&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Content_flow2542.png&amp;diff=163205</id>
		<title>File:Content flow2542.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Content_flow2542.png&amp;diff=163205"/>
		<updated>2025-04-04T17:53:28Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163204</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163204"/>
		<updated>2025-04-04T17:53:03Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on topics, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what topics students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes topic selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
===System Overview===&lt;br /&gt;
* Context Diagram&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163203</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163203"/>
		<updated>2025-04-04T17:07:31Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to refactor the review bidding controller along with its associated models, service objects, and views. It is integral to ensure that all components work together correctly.&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163202</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163202"/>
		<updated>2025-04-04T17:06:31Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to refactor the review bidding controller along with its associated models, service objects, and views. It is integral to ensure that all components work together correctly.&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163201</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163201"/>
		<updated>2025-04-04T17:06:10Z</updated>

		<summary type="html">&lt;p&gt;Nwinsen: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2542 - Reimplement Review Bidding Controller =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to refactor the review bidding controller along with its associated models, service objects, and views. It is integral to ensure that all components work together correctly.&lt;br /&gt;
&lt;br /&gt;
==Previous Implementation==&lt;br /&gt;
&lt;br /&gt;
The previous implementation successfully implemented the review bids, however our previous project refactored the python webservice to allow for a new JSON request structure. The files were updated to reflect this structure, but more refactoring is required to complete the project successfully, which will be explained in further detail under the specific objectives tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;/div&gt;</summary>
		<author><name>Nwinsen</name></author>
	</entry>
</feed>