Skip to content

Commit

Permalink
Adding Public Review
Browse files Browse the repository at this point in the history
Completed the task.
  • Loading branch information
Taranpreet10451 committed Jun 24, 2024
1 parent 980d09b commit 59ed033
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/autocomment-iss-close.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Comment on Issue Close

on:
Expand Down Expand Up @@ -26,4 +27,34 @@ jobs:
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
=======
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const greetingMessage = `Hello @${issueCreator}! Your issue #${issueNumber} has been closed. Thank you for your contribution!`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
>>>>>>> Stashed changes
});
39 changes: 39 additions & 0 deletions .github/workflows/close-old-issue.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Close Old Issues
on:
schedule:
Expand Down Expand Up @@ -34,4 +35,42 @@ jobs:
-d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments"
fi
=======
name: Close Old Issues
on:
schedule:
- cron: "0 0 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Close Old Issues
run: |
open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues?state=open" \
| jq -r '.[] | .number')
for issue in $open_issues; do
# Get the last updated timestamp of the issue
last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \
| jq -r '.updated_at')
days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 ))
if [ $days_since_update -gt 30 ]; then
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"state":"closed"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue"
# Add a comment explaining when the issue will be closed
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments"
fi
>>>>>>> Stashed changes
done
37 changes: 37 additions & 0 deletions .github/workflows/close-old-pr.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Close Stale PRs

on:
Expand Down Expand Up @@ -32,3 +33,39 @@ jobs:
operations-per-run: 30
remove-stale-when-updated: true
debug-only: false
=======
name: Close Stale PRs

on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
pull-requests: write
issues: write

jobs:
close_stale_prs:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: actions/stale@v7
with:
repo-token: ${{ secrets.GH_TOKEN }}
stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 15 days.'
days-before-pr-stale: 15
days-before-pr-close: 0
exempt-pr-author: false
exempt-pr-labels: ''
only-labels: ''
operations-per-run: 30
remove-stale-when-updated: true
debug-only: false
>>>>>>> Stashed changes
29 changes: 29 additions & 0 deletions server/models/Review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');

const reviewSchema = new mongoose.Schema({
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
product_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
required: true
},
rating: {
type: Number,
required: true,
min: 1,
max: 5
},
review_text: {
type: String,
required: true
}
}, {
timestamps: true
});

const Review = mongoose.model('Review', reviewSchema);
module.exports = Review;
22 changes: 22 additions & 0 deletions server/routes/reviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const express = require('express');
const router = express.Router();
const { auth, studentAuth } = require('../middlewares/auth');
const Review = require('../models/review');

// POST /api/v1/reviews - Create a review
router.post('/reviews', auth, studentAuth, async (req, res) => {
try {
const { product_id, rating, review_text } = req.body;
const user_id = req.user.id; // Assuming req.user contains the authenticated user's details

const newReview = new Review({ user_id, product_id, rating, review_text });
await newReview.save();

res.status(201).json({ success: true, message: 'Review created successfully' });
} catch (error) {
console.error(error);
res.status(500).json({ success: false, message: 'Error creating review' });
}
});

module.exports = router;
42 changes: 42 additions & 0 deletions src/components/AddReview.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState } from 'react';

const AddReview = ({ productId }) => {
const [rating, setRating] = useState(1);
const [reviewText, setReviewText] = useState('');

const handleSubmit = async (e) => {
e.preventDefault();
const response = await fetch('/reviews', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${yourAuthToken}` // Replace with your auth token logic
},
body: JSON.stringify({ product_id: productId, rating, review_text: reviewText })
});

if (response.ok) {
// Handle success (e.g., refresh reviews)
} else {
// Handle error
}
};

return (
<form onSubmit={handleSubmit}>
<label>
Rating:
<select value={rating} onChange={(e) => setRating(e.target.value)}>
{[1, 2, 3, 4, 5].map(n => <option key={n} value={n}>{n}</option>)}
</select>
</label>
<label>
Review:
<textarea value={reviewText} onChange={(e) => setReviewText(e.target.value)} />
</label>
<button type="submit">Submit</button>
</form>
);
};

export default AddReview;
47 changes: 47 additions & 0 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Navbar = () => {
</div>
</div>

<<<<<<< Updated upstream

<div className="ml-16 flex gap-6 items-baseline space-x-4 ">
<NavItem to="/home" className="nav-item" icon={<IconHome />}>Home</NavItem>
Expand Down Expand Up @@ -102,6 +103,41 @@ const Navbar = () => {
<MobileNavItem to="/news">News</MobileNavItem>
<MobileNavItem to="/contact">Contact</MobileNavItem>

=======
<div className="hidden md:flex items-center gap-5">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-4xl border-none outline-none">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<div>
<Link to="/">
<button
className={`py-1 px-2 rounded w-full h-auto text-l relative z-0 rounded-lg transition-all duration-200 hover:scale-110 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-400 hover:bg-green-600 hover:shadow-green text-white'}`}
>
Log out
</button>
</Link>
</div>
</div>

<div className="-mr-2 flex md:hidden">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-2xl border-none outline-none">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<button
onClick={toggleMenu}
className="inline-flex items-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:bg-gray-700 focus:text-white"
aria-expanded="false"
>
{isOpen ? (
<IoClose className="text-white" />
) : (
<GiHamburgerMenu className="text-white" />
)}
</button>
</div>
</div>
</div>
>>>>>>> Stashed changes

<AnimatePresence>
{isOpen && (
Expand All @@ -116,7 +152,11 @@ const Navbar = () => {
<MobileNavItem to="/about">About us</MobileNavItem>
<MobileNavItem to="/news">News</MobileNavItem>
<MobileNavItem to="/contact">Contact</MobileNavItem>
<<<<<<< Updated upstream
<MobileNavItem to="/rateus">RateUs</MobileNavItem>
=======
<MobileNavItem to="/rateus">RateUs</MobileNavItem>
>>>>>>> Stashed changes
{/* Conditionally render "My Canteen" button */}
{canteenId && (
<MobileNavItem to={`/section/${canteenId}`}>My Canteen</MobileNavItem>
Expand All @@ -134,6 +174,7 @@ const Navbar = () => {
</AnimatePresence>
</nav>
</>
<<<<<<< Updated upstream
<MobileNavItem to="/rateus">Rateus</MobileNavItem>

<MobileNavItem to="/">
Expand All @@ -154,6 +195,8 @@ const Navbar = () => {
</div>
</nav>
</>
=======
>>>>>>> Stashed changes
);
};

Expand Down Expand Up @@ -186,6 +229,10 @@ const IconHome = () => <span>🏠</span>;
const IconAbout = () => <span>ℹ️</span>;
const IconNews = () => <span>📰</span>;
const IconRateUs = () => <span></span>;
<<<<<<< Updated upstream
const IconCanteen = () => <span>🥗</span>
=======
const IconCanteen = () => <span>🥗</span>;
>>>>>>> Stashed changes

export default Navbar;
34 changes: 34 additions & 0 deletions src/components/Reviews.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState, useEffect } from 'react';

const Reviews = ({ productId }) => {
const [reviews, setReviews] = useState([]);
const [rating, setRating] = useState(0);

useEffect(() => {
fetch(`/reviews/${productId}`)
.then(response => response.json())
.then(data => {
setReviews(data);
if (data.length > 0) {
const avgRating = data.reduce((acc, review) => acc + review.rating, 0) / data.length;
setRating(avgRating);
}
});
}, [productId]);

return (
<div>
<h2>Average Rating: {rating.toFixed(1)} / 5</h2>
<ul>
{reviews.map(review => (
<li key={review.review_id}>
<p><strong>Rating:</strong> {review.rating} / 5</p>
<p>{review.review_text}</p>
</li>
))}
</ul>
</div>
);
};

export default Reviews;
Loading

0 comments on commit 59ed033

Please sign in to comment.