code update
This commit is contained in:
@@ -86,7 +86,6 @@ function App() {
|
|||||||
|
|
||||||
// Generate product recommendations
|
// Generate product recommendations
|
||||||
const generateProductRecommendations = async () => {
|
const generateProductRecommendations = async () => {
|
||||||
try {
|
|
||||||
setIsGeneratingRecommendations(true);
|
setIsGeneratingRecommendations(true);
|
||||||
|
|
||||||
// Add a short delay to simulate calculation time
|
// Add a short delay to simulate calculation time
|
||||||
@@ -94,46 +93,7 @@ function App() {
|
|||||||
|
|
||||||
console.log("Generating product recommendations for user:", user.ID);
|
console.log("Generating product recommendations for user:", user.ID);
|
||||||
|
|
||||||
// Make API call to get recommendations
|
|
||||||
const response = await fetch(
|
|
||||||
"http://localhost:3030/api/recommendations/generate",
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
userId: user.ID,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to generate recommendations");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
console.log(
|
|
||||||
"Recommendations generated successfully:",
|
|
||||||
result.recommendations,
|
|
||||||
);
|
|
||||||
setRecommendations(result.recommendations);
|
|
||||||
|
|
||||||
// Store recommendations in session storage for access across the app
|
|
||||||
sessionStorage.setItem(
|
|
||||||
"userRecommendations",
|
|
||||||
JSON.stringify(result.recommendations),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.error("Error generating recommendations:", result.message);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error generating product recommendations:", err);
|
|
||||||
} finally {
|
|
||||||
setIsGeneratingRecommendations(false);
|
setIsGeneratingRecommendations(false);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Binary file not shown.
@@ -19,9 +19,9 @@ def delete_user_recommendations(user_id):
|
|||||||
cursor = db_con.cursor()
|
cursor = db_con.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cursor.execute("DELETE FROM Recommendation WHERE UserID = %s", (user_id))
|
|
||||||
db_con.commit()
|
|
||||||
print(f"Deleted existing recommendations for user {user_id}")
|
print(f"Deleted existing recommendations for user {user_id}")
|
||||||
|
cursor.execute(f"DELETE FROM Recommendation WHERE UserID = {user_id}")
|
||||||
|
db_con.commit()
|
||||||
logging.info(f"Deleted existing recommendations for user {user_id}")
|
logging.info(f"Deleted existing recommendations for user {user_id}")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -86,10 +86,10 @@ def has_user_history_or_recommendations(user_id):
|
|||||||
cursor = db_con.cursor()
|
cursor = db_con.cursor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cursor.execute("SELECT COUNT(*) FROM History WHERE UserID = %s", (user_id,))
|
cursor.execute(f"SELECT COUNT(*) FROM History WHERE UserID = {user_id}" )
|
||||||
history_count = cursor.fetchone()[0]
|
history_count = cursor.fetchone()[0]
|
||||||
|
|
||||||
cursor.execute("SELECT COUNT(*) FROM Recommendation WHERE UserID = %s", (user_id,))
|
cursor.execute(f"SELECT COUNT(*) FROM Recommendation WHERE UserID = {user_id}")
|
||||||
recommendation_count = cursor.fetchone()[0]
|
recommendation_count = cursor.fetchone()[0]
|
||||||
|
|
||||||
return history_count > 0 or recommendation_count > 0
|
return history_count > 0 or recommendation_count > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user