Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
24 changes: 12 additions & 12 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: "eslint:recommended",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {},
};
module.exports = {
env: {
es2021: true,
node: true,
},
extends: "eslint:recommended",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {},
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules
.env
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2022 Rocket Academy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2022 Rocket Academy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Rocket Academy Coding Bootcamp: Project 3 Backend

Run `npm i` to install NPM packages, then `npm start` to start the Express server.
# Rocket Academy Coding Bootcamp: Project 3 Backend
Run `npm i` to install NPM packages, then `npm start` to start the Express server.
11 changes: 11 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require("dotenv").config();

module.exports = {
development: {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: process.env.DB_DIALECT,
},
};
34 changes: 34 additions & 0 deletions controllers/authController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// import category from "./models/category.js";
// import chat_image from "./models/chat_image.js";
// import chatroom_message from "./models/chatroom_message.js";
// import chatroom from "./models/chatroom.js";
// import index from "./models/index.js";
// import like from "./models/like.js";
// import listing_image from "./models/listing_image.js";
// import listing from "./models/listing.js";
// import order from "./models/order.js";
// import review from "./models/review.js";
// import user from "./models/user.js";

// const getCurrentUser = (req, res) => {
// res.send("Get current user");
// };

// const postCurrentUser = (req, res) => {
// res.send("Post current user");
// };

// export default {
// getCurrentUser,
// postCurrentUser,
// };

const BaseController = require("./baseController");

class authController extends BaseController {
constructor(model) {
super(model);
}
}

module.exports = authController;
18 changes: 18 additions & 0 deletions controllers/baseController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class BaseController {
constructor(model) {
this.model = model;
}

/* All controllers that extend this BASE controller will have access to the below function **/

async getAll(req, res) {
try {
const output = await this.model.findAll();
return res.json(output);
} catch (err) {
return res.status(400).json({ error: true, msg: err });
}
}
}

module.exports = BaseController;
44 changes: 44 additions & 0 deletions controllers/chatController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// import category from "./models/category.js";
// import chat_image from "./models/chat_image.js";
// import chatroom_message from "./models/chatroom_message.js";
// import chatroom from "./models/chatroom.js";
// import index from "./models/index.js";
// import like from "./models/like.js";
// import listing_image from "./models/listing_image.js";
// import listing from "./models/listing.js";
// import order from "./models/order.js";
// import review from "./models/review.js";
// import user from "./models/user.js";

// const getAllChat = (req, res) => {
// res.send("All chat");
// };

// const getSpecificChat = (req, res) => {
// res.send("Specific chat");
// };

// const postMessage = (req, res) => {
// res.send("Send message");
// };

// const deleteMessage = (req, res) => {
// res.send("Delete message");
// };

// export default {
// getAllChat,
// getSpecificChat,
// postMessage,
// deleteMessage,
// };

const BaseController = require("./baseController");

class chatController extends BaseController {
constructor(model) {
super(model);
}
}

module.exports = chatController;
49 changes: 49 additions & 0 deletions controllers/homeController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// import category from "./models/category.js";
// import chat_image from "./models/chat_image.js";
// import chatroom_message from "./models/chatroom_message.js";
// import chatroom from "./models/chatroom.js";
// import index from "./models/index.js";
// import like from "./models/like.js";
// import listing_image from "./models/listing_image.js";
// import listing from "./models/listing.js";
// import order from "./models/order.js";
// import review from "./models/review.js";
// import user from "./models/user.js";

// const getListing = (req, res) => {
// res.send("See listing");
// };

// const postListing = (req, res) => {
// res.send("Post listing");
// };

// const deleteListing = (req, res) => {
// res.send("Delete listing");
// };

// const searchListing = (req, res) => {
// res.send("Search listing");
// };

// const getListingCategory = (req, res) => {
// res.send("Listing category");
// };

// export default {
// getListing,
// postListing,
// deleteListing,
// searchListing,
// getListingCategory,
// };

const BaseController = require("./baseController");

class homeController extends BaseController {
constructor(model) {
super(model);
}
}

module.exports = homeController;
29 changes: 29 additions & 0 deletions controllers/profileController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import category from "./models/category.js";
// import chat_image from "./models/chat_image.js";
// import chatroom_message from "./models/chatroom_message.js";
// import chatroom from "./models/chatroom.js";
// import index from "./models/index.js";
// import like from "./models/like.js";
// import listing_image from "./models/listing_image.js";
// import listing from "./models/listing.js";
// import order from "./models/order.js";
// import review from "./models/review.js";
// import user from "./models/user.js";

// const getUserProfile = (req, res) => {
// res.send("User profile");
// };

// export default {
// getUserProfile,
// };

const BaseController = require("./baseController");

class profileController extends BaseController {
constructor(model) {
super(model);
}
}

module.exports = profileController;
51 changes: 39 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import express from "express";

const PORT = 3000;
const app = express();

app.get("/", (req, res) => {
res.send("Hello, World!");
});

app.listen(PORT, () => {
console.log(`Express app listening on port ${PORT}!`);
});
// import cors from "cors";
// import express from "express";
import authController from "./controllers/authController.js";
import homeController from "./controllers/homeController.js";
import chatController from "./controllers/chatController.js";
import profileController from "./controllers/profileController.js";

const PORT = 3000;
const app = express();
const cors = require("cors");
const express = require("express");

// Middleware / cors
app.use(cors());

// AUTHENTICATION ROUTES
app.get("/authentication", authController.getCurrentUser);
app.post("/authentication", authController.postCurrentUser);

// HOMEPAGE ROUTES
app.get("/home/listing", homeController.getListing);
app.post("/home/listing", homeController.postListing);
app.delete("/home/listing", homeController.deleteListing);
app.get("/home/search", homeController.searchListing);
app.get("/home/category", homeController.getListingCategory);

// CHATPAGE ROUTES
app.get("/chat", chatController.getAllChat);
app.get("/chat/chatroom", chatController.getSpecificChat);
app.post("/chat/message", chatController.postMessage);
app.delete("/chat/message", chatController.deleteMessage);

// PROFILEPAGE ROUTES
app.get("/profile", profileController.getUserProfile);

// Start the server
app.listen(PORT, () => {
console.log(`Express app listening on port ${PORT}!`);
});
Loading