Skip to content

Commit

Permalink
Merge pull request #67 from AyushSharma72/placeholder
Browse files Browse the repository at this point in the history
Added placeholder in community page
  • Loading branch information
Anuj3553 authored Oct 11, 2024
2 parents adf7b16 + 2446f66 commit 8584245
Show file tree
Hide file tree
Showing 9 changed files with 4,194 additions and 2,529 deletions.
2,721 changes: 1,670 additions & 1,051 deletions client/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@fortawesome/fontawesome-free": "^6.5.1",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-brands-svg-icons": "^6.5.1",
"@fortawesome/free-regular-svg-icons": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mui/icons-material": "^5.15.12",
"@mui/material": "^6.1.3",
"@splinetool/react-spline": "^2.2.6",
"@splinetool/runtime": "^1.0.67",
"@splinetool/viewer": "^1.0.67",
Expand Down
1,264 changes: 876 additions & 388 deletions client/src/component/Community.jsx

Large diffs are not rendered by default.

550 changes: 370 additions & 180 deletions client/src/component/Navbar.jsx

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions server/.env.sample

This file was deleted.

343 changes: 180 additions & 163 deletions server/Controllers/projects.js
Original file line number Diff line number Diff line change
@@ -1,184 +1,201 @@
const fetchallglobalprojects = async (req, res) => {
try {
// Find all the projects of the all user
const projects = await Project.find()
res.json(projects)
}
catch (error) {
// Give internal server error (500)
console.log(error.message)
res.status(500).send("Internal Server Error")
}
}
const Project = require("../Models/Project");
const fetchallglobalprojects = async (req, res) => {
try {
// Find all the projects of the all user
const projects = await Project.find();
res.json(projects);
} catch (error) {
// Give internal server error (500)
console.log(error.message);
res.status(500).send("Internal Server Error");
}
};

const fetchalluserprojects = async (req, res) => {
try {
// Find projects associated only with the current user's public ID.
const projects = await Project.find({ user: req.user.id })
res.json(projects)
}
catch (error) {
// Give internal server error (500)
console.log(error.message)
res.status(500).send("Internal Server Error")
}
}
try {
// Find projects associated only with the current user's public ID.
const projects = await Project.find({ user: req.user.id });
res.json(projects);
} catch (error) {
// Give internal server error (500)
console.log(error.message);
res.status(500).send("Internal Server Error");
}
};

const addproject = async (req, res) => {
try {
// Destructring the title, description, gitHubLink, youTubeLink from Database body
const { title, description, gitHubLink, youTubeLink } = req.body;

// If title is not provided, return a bad request response
if (!title) {
return res.status(400).json({ error: "Title is required" });
}

// Perform validation on request inputs
const errors = validationResult(req);

// If data is empty or not filled
if (!errors.isEmpty()) {
// Return a status 400 and return json of error in the array form
return res.status(400).json({ errors: errors.array() });
}

// Create a new project and saved it
const project = new Project({
title, description, gitHubLink, youTubeLink, user: req.user.id
})

// Save the project to the database
const savedProject = await project.save();

// Check if the project is saved successfully
if (!savedProject) {
return res.status(500).json({ error: "Project not added successfully" });
}

// If project is saved successfully, return a success response
res.json(savedProject);
try {
// Destructring the title, description, gitHubLink, youTubeLink from Database body
const { title, description, gitHubLink, youTubeLink } = req.body;

// If title is not provided, return a bad request response
if (!title) {
return res.status(400).json({ error: "Title is required" });
}
catch (error) {
// Give internal server error (500)
console.log(error.message)
res.status(500).send("Internal Server Error")

// Perform validation on request inputs
const errors = validationResult(req);

// If data is empty or not filled
if (!errors.isEmpty()) {
// Return a status 400 and return json of error in the array form
return res.status(400).json({ errors: errors.array() });
}
}

// Create a new project and saved it
const project = new Project({
title,
description,
gitHubLink,
youTubeLink,
user: req.user.id,
});

// Save the project to the database
const savedProject = await project.save();

// Check if the project is saved successfully
if (!savedProject) {
return res.status(500).json({ error: "Project not added successfully" });
}

// If project is saved successfully, return a success response
res.json(savedProject);
} catch (error) {
// Give internal server error (500)
console.log(error.message);
res.status(500).send("Internal Server Error");
}
};

const updateproject = async (req, res) => {
try {
// Destructring the title, description, gitHubLink, youTubeLink from Database body
const { title, description, gitHubLink, youTubeLink } = req.body;

// Create a newNote object
const newProject = {};

// If there is title then update it.
if (title) { newProject.title = title };
// If there is description then update it.
if (description) { newProject.description = description };
// If there is gitHubLink then update it.
if (gitHubLink) { newProject.gitHubLink = gitHubLink };
// If there is youTubeLink then update it.
if (youTubeLink) { newProject.youTubeLink = youTubeLink };

// Find the project to be updated and update it --> return the promise
let project = await Project.findById(req.params.id)
// If project not found then send the 404 status
if (!project) { return res.status(404).send("Not Found") }

// Allow deletion only if user owns this project
if (project.user.toString() !== req.user.id) {
return res.status(401).send("Not Allowed")
}

// Find by id and update the project from the existing project and set to the newProject object, the updated new information
project = await Project.findByIdAndUpdate(req.params.id, { $set: newProject }, { new: true });
res.json(project);
try {
// Destructring the title, description, gitHubLink, youTubeLink from Database body
const { title, description, gitHubLink, youTubeLink } = req.body;

// Create a newNote object
const newProject = {};

// If there is title then update it.
if (title) {
newProject.title = title;
}
catch (error) {
// Give internal server error (500)
console.log(error.message)
res.status(500).send("Internal Server Error")
// If there is description then update it.
if (description) {
newProject.description = description;
}
// If there is gitHubLink then update it.
if (gitHubLink) {
newProject.gitHubLink = gitHubLink;
}
// If there is youTubeLink then update it.
if (youTubeLink) {
newProject.youTubeLink = youTubeLink;
}
}

// Find the project to be updated and update it --> return the promise
let project = await Project.findById(req.params.id);
// If project not found then send the 404 status
if (!project) {
return res.status(404).send("Not Found");
}

// Allow deletion only if user owns this project
if (project.user.toString() !== req.user.id) {
return res.status(401).send("Not Allowed");
}

// Find by id and update the project from the existing project and set to the newProject object, the updated new information
project = await Project.findByIdAndUpdate(
req.params.id,
{ $set: newProject },
{ new: true }
);
res.json(project);
} catch (error) {
// Give internal server error (500)
console.log(error.message);
res.status(500).send("Internal Server Error");
}
};

const deleteproject = async (req, res) => {
try {
// Find the project to be deleted and delete it --> return the promise
let project = await Project.findById(req.params.id)
// If project not found then send the 404 status
if (!project) { return res.status(404).send("Not Found") }

// Allow deletion only if user owns this project
if (project.user.toString() !== req.user.id) {
return res.status(401).send("Not Allowed")
}

// Find by id and update the project from the existing project and set to the newProject object, the updated new information
project = await Project.findByIdAndDelete(req.params.id);
res.json({ "Success": "Project has been deleted", project: project });
try {
// Find the project to be deleted and delete it --> return the promise
let project = await Project.findById(req.params.id);
// If project not found then send the 404 status
if (!project) {
return res.status(404).send("Not Found");
}
catch (error) {
// Give internal server error (500)
console.log(error.message)
res.status(500).send("Internal Server Error")

// Allow deletion only if user owns this project
if (project.user.toString() !== req.user.id) {
return res.status(401).send("Not Allowed");
}
}

// Find by id and update the project from the existing project and set to the newProject object, the updated new information
project = await Project.findByIdAndDelete(req.params.id);
res.json({ Success: "Project has been deleted", project: project });
} catch (error) {
// Give internal server error (500)
console.log(error.message);
res.status(500).send("Internal Server Error");
}
};

const uploadProjectImage = async (req, res) => {
try {
// Destructring the projectImage from Database body
const { projectImage } = req.body.projectImage;

// Perform validation on request inputs
const errors = validationResult(req);

// If data is empty or not filled
if (!errors.isEmpty()) {
// Return a status 400 and return json of error in the array form
return res.status(400).json({ errors: errors.array() });
}

// Create a new project and saved it
const project = new Project.create({
projectImage, user: req.user.id
})

// Save the project to the database
const savedProject = await project.save();

// Check if the project is saved successfully
if (!savedProject) {
return res.status(500).json({ error: "Project not added successfully" });
}

// If project is saved successfully, return a success response
res.json(savedProject);
} catch (err) {
console.log(err);
res.status(500).json({ error: 'Internal server error' });
try {
// Destructring the projectImage from Database body
const { projectImage } = req.body.projectImage;

// Perform validation on request inputs
const errors = validationResult(req);

// If data is empty or not filled
if (!errors.isEmpty()) {
// Return a status 400 and return json of error in the array form
return res.status(400).json({ errors: errors.array() });
}
}

const getProjectImage = async (req, res) => {
try {
const project = await Project.find({ user: req.user.id });
// res.json(project.projectImage);
res.json(project);
} catch (err) {
console.log(err);
res.status(500).json({ error: 'Internal server error' });
// Create a new project and saved it
const project = new Project.create({
projectImage,
user: req.user.id,
});

// Save the project to the database
const savedProject = await project.save();

// Check if the project is saved successfully
if (!savedProject) {
return res.status(500).json({ error: "Project not added successfully" });
}
}

// If project is saved successfully, return a success response
res.json(savedProject);
} catch (err) {
console.log(err);
res.status(500).json({ error: "Internal server error" });
}
};

const getProjectImage = async (req, res) => {
try {
const project = await Project.find({ user: req.user.id });
// res.json(project.projectImage);
res.json(project);
} catch (err) {
console.log(err);
res.status(500).json({ error: "Internal server error" });
}
};

module.exports = {
fetchallglobalprojects,
fetchalluserprojects,
addproject,
updateproject,
deleteproject,
uploadProjectImage,
getProjectImage
};
fetchallglobalprojects,
fetchalluserprojects,
addproject,
updateproject,
deleteproject,
uploadProjectImage,
getProjectImage,
};
Loading

0 comments on commit 8584245

Please sign in to comment.