Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add feeds schema #14

Merged
merged 6 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"@testing-library/user-event": "^13.5.0",
"axios": "^0.26.1",
"express": "^4.17.3",
"moment": "^2.29.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-redux": "^8.0.0",
"react-router-dom": "^5.3.1",
"react-scripts": "5.0.1",
"redux": "^4.1.2",
"redux-thunk": "^2.4.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
26 changes: 26 additions & 0 deletions server/Controllers/feeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Feeds from "../Schema/feeds.js";

export const getFeeds = async (req, res) => {
//Creating a getFeeds function to fetch data database
try {
const AllFeeds = await Feeds.find();

res.status(200).json(AllFeeds);
} catch (error) {
res.status(404).json({ message: error.message });
}
};

export const createFeeds = async (req, res) => {
//Pushing post data to the Database
const feeds = req.body;
const newFeed = new Feeds(feeds);
console.log(feeds);

try {
await newFeed.save(); //saving data in Azure
res.status(201).json(newFeed);
} catch (error) {
res.status(409).json({ message: error.message });
}
};
8 changes: 4 additions & 4 deletions server/Routes/Routes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import express from "express";
import Post from "../Schema/test.js";
import { createFeeds, getFeeds } from "../Controllers/feeds.js";

const Router = express.Router();

let allpost;

Router.post("/check", async (req, res) => {
try {
allpost = await req.body;

console.log(req.body);
const data = await new Post(req.body);

Expand All @@ -19,4 +16,7 @@ Router.post("/check", async (req, res) => {
}
});

Router.get("/feeds", getFeeds);
Router.post("/feeds", createFeeds);

export default Router;
37 changes: 37 additions & 0 deletions server/Schema/feeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import mongoose from "mongoose";

const FeedSchema = new mongoose.Schema({
userName: {
type: String,
required: true,
},
dp: {
type: String,
},
message: {
type: String,
required: true,
},
selectedFile: {
type: String,
},
like: {
type: String,
default: 0,
},
comment: {
type: [String],
},
dateCreated: {
type: Date,
default: new Date(),
},
tags: {
type: [String],
required: true,
},
});

const Feeds = mongoose.model("Feeds", FeedSchema);

export default Feeds;
2 changes: 1 addition & 1 deletion server/database/DB.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const connection = async (URL) => {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("Connected To MongoDb");
console.log("Connected To Azure");
} catch (error) {
console.log("Error While Connecting to MongoDb", error);
}
Expand Down
26 changes: 12 additions & 14 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import React from 'react'
import { BrowserRouter as Router, Route, Switch} from "react-router-dom";
import Trying from './trying'
import News from './News/News'
import React from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Trying from "./trying";
import News from "./News/News";
const App = () => {
return (
<>

<Router>
<Switch>
<Route path="/" exact component= {Trying}/>
<Route path="/news" exact component= {News}/>
<Router>
<Switch>
<Route path="/" exact component={Trying} />
<Route path="/news" exact component={News} />
</Switch>
</Router>

</Router>
</>
)
}
);
};

export default App
export default App;
Loading