Skip to content

Commit

Permalink
Call api to get query result
Browse files Browse the repository at this point in the history
  • Loading branch information
Haritha-Kotte committed Sep 26, 2024
1 parent 98c0bf5 commit d58624e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/controllers/queries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
class QueriesController < ApplicationController
before_action :set_query, only: %i[ show update destroy ]

def get_query_results
# Get query results from python script
query_results = "Something"
render json: { query_results: query_results }

Check failure on line 7 in app/controllers/queries_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
end

# GET /queries
def index
@queries = Query.all
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Rails.application.routes.draw do
resources :queries
resources :queries do
collection do
get :get_query_results
end
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down
13 changes: 11 additions & 2 deletions nextjs-frontend/components/recipeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ const RecipeForm = () => {
const [inputValue, setInputValue] = useState("");
const [output, setOutput] = useState("");

const handleSubmit = (e: React.FormEvent) => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
// Handle form submission logic here and set the output
setOutput(inputValue); // Example output
try {
const response = await fetch(
"http://localhost:3001/queries/get_query_results"
);
const data = await response.json();
console.log("Server response:", data);
setOutput(data.query_results); // Example output
} catch (error) {
console.error("Error:", error);
}
console.log("Submitted:", inputValue);
};

Expand Down

0 comments on commit d58624e

Please sign in to comment.