Skip to content

Commit 81d30f2

Browse files
committed
first commit
1 parent ed21a8a commit 81d30f2

File tree

6,699 files changed

+566860
-565740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,699 files changed

+566860
-565740
lines changed

.DS_Store

6 KB
Binary file not shown.

controller/blogController.js

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
const Blog = require("../models/blogModel");
2-
const cloudinary = require('cloudinary');
3-
4-
exports.addBlog = async (req, res) => {
5-
try {
6-
const { title, img, description, public_id, user_id } = req.body;
7-
const blog = await Blog.create({ title, img, description, public_id, user_id });
8-
res.status(201).json({
9-
success: true,
10-
blog
11-
})
12-
} catch (error) {
13-
console.log(error);
14-
}
15-
}
16-
17-
exports.deleteBlog = async (req, res) => {
18-
try {
19-
const { _id, public_id } = req.body;
20-
cloudinary.uploader.destroy(public_id, ({ result }) => {
21-
console.log(result);
22-
});
23-
const blog = await Blog.findByIdAndDelete(_id);
24-
res.status(200).json({ success: true, blog });
25-
} catch (error) {
26-
console.log(error);
27-
}
28-
}
29-
30-
exports.updateBlog = async (req, res) => {
31-
try {
32-
33-
if (req.body.imgChange) {
34-
cloudinary.uploader.destroy(req.body.del_id, ({ result }) => {
35-
console.log(result);
36-
});
37-
}
38-
39-
const newBlog = await Blog.findByIdAndUpdate(req.body._id, req.body, {
40-
new: true
41-
});
42-
43-
res.status(200).json({
44-
success: true,
45-
newBlog
46-
})
47-
48-
} catch (error) {
49-
console.log(error);
50-
}
51-
}
52-
53-
exports.getBlogs = async (req, res) => {
54-
try {
55-
const blogs = await Blog.find();
56-
res.status(200).json({
57-
success: true,
58-
blogs
59-
})
60-
} catch (error) {
61-
console.log(error);
62-
}
1+
const Blog = require("../models/blogModel");
2+
const cloudinary = require('cloudinary');
3+
4+
exports.addBlog = async (req, res) => {
5+
try {
6+
const { title, img, description, public_id, user_id } = req.body;
7+
const blog = await Blog.create({ title, img, description, public_id, user_id });
8+
res.status(201).json({
9+
success: true,
10+
blog
11+
})
12+
} catch (error) {
13+
console.log(error);
14+
}
15+
}
16+
17+
exports.deleteBlog = async (req, res) => {
18+
try {
19+
const { _id, public_id } = req.body;
20+
cloudinary.uploader.destroy(public_id, ({ result }) => {
21+
console.log(result);
22+
});
23+
const blog = await Blog.findByIdAndDelete(_id);
24+
res.status(200).json({ success: true, blog });
25+
} catch (error) {
26+
console.log(error);
27+
}
28+
}
29+
30+
exports.updateBlog = async (req, res) => {
31+
try {
32+
33+
if (req.body.imgChange) {
34+
cloudinary.uploader.destroy(req.body.del_id, ({ result }) => {
35+
console.log(result);
36+
});
37+
}
38+
39+
const newBlog = await Blog.findByIdAndUpdate(req.body._id, req.body, {
40+
new: true
41+
});
42+
43+
res.status(200).json({
44+
success: true,
45+
newBlog
46+
})
47+
48+
} catch (error) {
49+
console.log(error);
50+
}
51+
}
52+
53+
exports.getBlogs = async (req, res) => {
54+
try {
55+
const blogs = await Blog.find();
56+
res.status(200).json({
57+
success: true,
58+
blogs
59+
})
60+
} catch (error) {
61+
console.log(error);
62+
}
6363
}

controller/userController.js

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,63 @@
1-
const User = require("../models/userModel");
2-
const bcrypt = require('bcryptjs');
3-
const jwt = require("jsonwebtoken");
4-
5-
6-
exports.register = async (req, res) => {
7-
try {
8-
const { name, email, password } = req.body;
9-
const userfind = await User.findOne({ email });
10-
11-
if (userfind) {
12-
res.status(400).json({ success: false, message: "email is already registered !" });
13-
} else {
14-
const user = await User.create({ name, email, password });
15-
res.status(201).json({ sucess: true, user });
16-
}
17-
18-
} catch (error) {
19-
console.log(error);
20-
}
21-
}
22-
23-
24-
exports.login = async (req, res) => {
25-
try {
26-
const { email, password } = req.body;
27-
const user = await User.findOne({ email: email }).select("+password");
28-
29-
if (user) {
30-
const valid = await bcrypt.compare(password, user.password);
31-
32-
if (valid) {
33-
const token = await user.generateToken();
34-
res.status(200).json({ success: true, token, user });
35-
} else {
36-
res.status(400).json({ success: false, message: "Invalid password" })
37-
}
38-
39-
} else {
40-
res.status(400).json({ success: false, message: "Invalid email" });
41-
}
42-
43-
} catch (error) {
44-
console.log(error);
45-
}
46-
}
47-
48-
49-
exports.getUserData = async (req, res) => {
50-
try {
51-
const { token } = req.body;
52-
const { id } = jwt.verify(token, process.env.SECRET);
53-
const user = await User.findOne({ _id: id });
54-
if(user){
55-
res.status(200).json({ success: true, user });
56-
}else{
57-
res.status(400).json({success:false, message:"user not present"});
58-
}
59-
} catch (error) {
60-
console.log(error);
61-
}
62-
}
1+
const User = require("../models/userModel");
2+
const bcrypt = require('bcryptjs');
3+
const jwt = require("jsonwebtoken");
4+
5+
6+
7+
exports.register = async (req, res) => {
8+
try {
9+
const { name, email, password } = req.body;
10+
const userfind = await User.findOne({ email });
11+
12+
if (userfind) {
13+
res.status(400).json({ success: false, message: "email is already registered !" });
14+
} else {
15+
const user = await User.create({ name, email, password });
16+
res.status(201).json({ sucess: true, user });
17+
}
18+
19+
} catch (error) {
20+
console.log(error);
21+
}
22+
}
23+
24+
25+
exports.login = async (req, res) => {
26+
try {
27+
const { email, password } = req.body;
28+
const user = await User.findOne({ email: email }).select("+password");
29+
30+
if (user) {
31+
const valid = await bcrypt.compare(password, user.password);
32+
33+
if (valid) {
34+
const token = await user.generateToken();
35+
res.status(200).json({ success: true, token, user });
36+
} else {
37+
res.status(400).json({ success: false, message: "Invalid password" })
38+
}
39+
40+
} else {
41+
res.status(400).json({ success: false, message: "Invalid email" });
42+
}
43+
44+
} catch (error) {
45+
console.log(error);
46+
}
47+
}
48+
49+
50+
exports.getUserData = async (req, res) => {
51+
try {
52+
const { token } = req.body;
53+
const { id } = jwt.verify(token, process.env.SECRET);
54+
const user = await User.findOne({ _id: id });
55+
if(user){
56+
res.status(200).json({ success: true, user });
57+
}else{
58+
res.status(400).json({success:false, message:"user not present"});
59+
}
60+
} catch (error) {
61+
console.log(error);
62+
}
63+
}

database/conn.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
const mongoose = require("mongoose");
2-
3-
mongoose.connect(process.env.DB).then(() => {
4-
console.log("connection established...!");
5-
}).catch((error) => {
6-
console.log(error);
7-
})
1+
const mongoose = require('mongoose');
2+
require('dotenv').config();
3+
4+
const uri = process.env.MONGO_URI;
5+
6+
console.log('MongoDB URI:', uri); // Add this line to debug
7+
8+
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })
9+
.then(() => console.log('Connected to MongoDB'))
10+
.catch(err => console.error('MongoDB connection error:', err));

models/blogModel.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
const mongoose = require("mongoose");
2-
3-
const blogSchema = new mongoose.Schema({
4-
title: {
5-
type: String,
6-
require: true,
7-
},
8-
description: {
9-
type: String,
10-
require: true
11-
},
12-
img: {
13-
type: String,
14-
require: true
15-
},
16-
public_id: {
17-
type: String,
18-
require: true
19-
},
20-
user_id: {
21-
type: String,
22-
}
23-
});
24-
25-
26-
const Blog = new mongoose.model("BLOG", blogSchema);
1+
const mongoose = require("mongoose");
2+
3+
const blogSchema = new mongoose.Schema({
4+
title: {
5+
type: String,
6+
require: true,
7+
},
8+
description: {
9+
type: String,
10+
require: true
11+
},
12+
img: {
13+
type: String,
14+
require: true
15+
},
16+
public_id: {
17+
type: String,
18+
require: true
19+
},
20+
user_id: {
21+
type: String,
22+
}
23+
});
24+
25+
26+
const Blog = new mongoose.model("BLOG", blogSchema);
2727
module.exports = Blog;

0 commit comments

Comments
 (0)