Skip to content

Commit

Permalink
Merge pull request #367 from Taranpreet10451/PublicReview
Browse files Browse the repository at this point in the history
Public review
  • Loading branch information
hustlerZzZ authored Jun 26, 2024
2 parents 547f3b0 + 7fd4145 commit ede173a
Show file tree
Hide file tree
Showing 16 changed files with 784 additions and 256 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
80 changes: 80 additions & 0 deletions server/controllers/canteenController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const Breakfast = require('../models/breakfast');
const Lunch = require('../models/lunch');
const Dinner = require('../models/dinner');
const Canteen = require("../models/canteenLoginInfo");
<<<<<<< Updated upstream
=======
const Feedback = require("../models/feedback")
const Session = require("../models/session")
>>>>>>> Stashed changes
const { uploader } = require('../config/cloudinaryConfig');


Expand Down Expand Up @@ -43,6 +48,76 @@ const getBreakfast = async(req , res , next) =>{
res.status(500).json({success : false , error : error});
}
}
const feedback = async (req, res) => {
const { canteenId, feedback, rating } = req.body;
const token = req.body.studentId; // This is the token

try {
// Find the session with the given token
const session = await Session.findOne({ token });

if (!session) {
return res.status(404).json({ message: 'Session not found' });
}

const userId = session.userId; // Extract userId from the session

const newFeedback = new Feedback({
canteen: canteenId,
student: userId,
comment: feedback,
rating: rating,
});

const savedFeedback = await newFeedback.save();
res.status(201).json(savedFeedback);
} catch (error) {
res.status(500).json({ message: 'Error saving feedback', error: error.message });
}
};
const canteenFeedbackRender = async (req, res) => {
try {
const reviews = await Feedback.aggregate([
{ $sample: { size: 3 } }, // Fetch 3 random feedback entries
{
$lookup: {
from: 'students', // Collection name for students
localField: 'student',
foreignField: '_id',
as: 'studentInfo'
}
},
{
$lookup: {
from: 'canteens', // Collection name for canteens
localField: 'canteen',
foreignField: '_id',
as: 'canteenInfo'
}
},
{
$addFields: {
studentName: { $arrayElemAt: ['$studentInfo.name', 0] },
canteenName: { $arrayElemAt: ['$canteenInfo.name', 0] }
}
},
{
$project: {
_id: 1,
comment: 1,
rating: 1,
createdAt: 1,
studentName: 1,
canteenName: 1
}
}
]);

res.json(reviews);
} catch (error) {
res.status(500).json({ message: error.message });
}
};

const getLunch = async(req , res , next) =>{

Expand Down Expand Up @@ -297,4 +372,9 @@ module.exports = {
updateBreakfastDish,
updateLunchDish,
updateDinnerDish,
<<<<<<< Updated upstream
=======
feedback,
canteenFeedbackRender
>>>>>>> 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;
12 changes: 12 additions & 0 deletions server/models/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const mongoose = require('mongoose');

const feedbackSchema = new mongoose.Schema({
student: { type: mongoose.Schema.Types.ObjectId, ref: 'Student' },
canteen: { type: mongoose.Schema.Types.ObjectId, ref: 'Canteen' },
comment: String,
rating: Number,
createdAt: { type: Date, default: Date.now }
});

const Feedback = mongoose.model('Feedback', feedbackSchema);
module.exports = Feedback;
3 changes: 2 additions & 1 deletion server/routes/canteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { auth, isCanteen } = require('../middlewares/auth');
const multerUploads = require('../middleware/multer.middleware');

router.get('/getcanteen' , canteenController.getAllCanteen);

router.post("/feedback", canteenController.feedback)
router.get("/reviews", canteenController.canteenFeedbackRender)
//yeh mere routes
router.get('/:id/breakfast' , canteenController.getBreakfast);

Expand Down
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;
49 changes: 49 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,53 @@ li:hover span {

.nav-item{
font-size: 52px !important;
<<<<<<< Updated upstream
=======
}

.star-rating {
display: flex;
flex-direction: row;
}

.star {
font-size: 2rem;
color: #d3d3d3;
background: none;
border: none;
cursor: pointer;
transition: color 0.2s;
}

.star.on {
color: #ffc107;
}

.star.off {
color: #d3d3d3;
}
.reviews-container{
display: flex;
flex-direction: row;
justify-content: space-around;

}
.review-card{
width: calc(90vw/3);
border: 1px solid green;
background-color: white;
background-color: aquamarine;
}
.stdfeedback{
background-color: white;
padding: 2% 3%;
}
.stdname{
margin: 2% 3%;
}

.stars {
color: yellow;
font-size: 24px; /* Increase the font size to make the stars bigger */
>>>>>>> Stashed changes
}
Loading

0 comments on commit ede173a

Please sign in to comment.