Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from hacettepeoyt/db-integration
Browse files Browse the repository at this point in the history
Halfway Database Integration
  • Loading branch information
furkansimsekli authored Sep 25, 2022
2 parents 956e2de + 24c7c46 commit 83834aa
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
2. Create `.env` file in the root.
3. Fill the variables from Signal group chat.
4. Run it with `npm start`.

### Seed
0. Make sure your machine has MongoDB installed.
1. Make sure MongoDB is currently working in your machine with `sudo systemctl status mongod`.
2. Seed your local database with `npm run seed`.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ app.listen(port, (err) => {
console.log(err)
} else {
console.log(`Server listening on ${port}`);
// connectToMongo();
connectToMongo();
}
});

Expand Down
19 changes: 14 additions & 5 deletions controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const content = require('../models/content');
const Member = require('../models/member');
const Faq = content.Faq;
const Event = content.Event;
const Project = content.Project;
const Course = content.Course;

const boilerplate = "layouts/boilerplate";
const errorPage = "../error";

// Page contents are hardcoded right now, will be fixed later!

const renderHomePage = async (req, res) => {
res.redirect("/about");
Expand All @@ -10,7 +16,6 @@ const renderHomePage = async (req, res) => {
const renderAboutPage = async (req, res) => {
try {
const page = "../sections/about";
fooText = "Hakkımızda";
res.render(boilerplate, { page });
} catch (err) {
res.render(boilerplate, { page: errorPage, err });
Expand All @@ -20,7 +25,8 @@ const renderAboutPage = async (req, res) => {
const renderFaqPage = async (req, res) => {
try {
const page = "../sections/faq";
res.render(boilerplate, { page });
const faqs = await Faq.find({});
res.render(boilerplate, { page, faqs });
} catch (err) {
res.render(boilerplate, { page: errorPage, err });
}
Expand All @@ -29,7 +35,9 @@ const renderFaqPage = async (req, res) => {
const renderEventsPage = async (req, res) => {
try {
const page = "../sections/events";
res.render(boilerplate, { page });
const events = await Event.find({});
const courses = await Course.find({});
res.render(boilerplate, { page, events, courses });
} catch (err) {
res.render(boilerplate, { page: errorPage, err });
}
Expand All @@ -38,7 +46,8 @@ const renderEventsPage = async (req, res) => {
const renderArgePage = async (req, res) => {
try {
const page = "../sections/arge";
res.render(boilerplate, { page });
const projects = await Project.find({});
res.render(boilerplate, { page, projects });
} catch (err) {
res.render(boilerplate, { page: errorPage, err });
}
Expand Down
Empty file removed models/about.js
Empty file.
Empty file removed models/activity.js
Empty file.
Empty file removed models/announcement.js
Empty file.
136 changes: 136 additions & 0 deletions models/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// TODO add default images for projects, courses and events.

const faqSchema = new Schema({
question: {
type: String,
required: true
},

answer: {
type: String,
required: true
}
});

const projectSchema = new Schema({
img: {
type: String,
required: true
},

name: {
type: String,
required: true
},

description: {
type: String,
required: true
},

status: {
type: Number,
min: 0,
max: 100,
default: 0
},

repository: {
type: String,
required: true
}
});

const courseSchema = new Schema({
img: {
type: String,
required: true
},

name: {
type: String,
required: true
},

description: {
type: String,
required: true
},

preRequisite: {
type: Array,
default: []
},

location: {
type: String,
required: true
},

time: {
type: String,
required: true
},

date: {
type: String,
required: true
},

duration: { // 8 hafta, 3 gün, 4 ay...
type: String,
required: true
}
});

const eventSchema = new Schema({
img: {
type: String,
required: true
},

name: {
type: String,
required: true
},

description: {
type: String,
required: true
},

location: {
type: String,
required: true
},

time: {
type: String,
required: true
},

date: {
type: String,
required: true
},

duration: {
type: String,
required: true
}
});

const Faq = mongoose.model('Faq', faqSchema);
const Project = mongoose.model('Project', projectSchema);
const Course = mongoose.model('Course', courseSchema);
const Event = mongoose.model('Event', eventSchema);

module.exports = {
Faq,
Project,
Course,
Event
}
Empty file removed models/faq.js
Empty file.
43 changes: 43 additions & 0 deletions models/member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const mongoose = require("mongoose");


const memberSchema = mongoose.Schema({
firstName: {
type: String,
required: true
},

lastName: {
type: String,
required: true
},

studentID: {
type: String,
required: true
},

email: {
type: String,
required: true
},

department: {
type: String,
required: true
},

mobileNumber: {
type: String,
required: true
},

groupChat: {
type: Boolean,
required: true
}
})

const Member = mongoose.model('Member', memberSchema);

module.exports = Member;
Empty file removed models/projects.js
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "app.js",
"scripts": {
"start": "nodemon app.js",
"seed": "node seeds.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down
Loading

0 comments on commit 83834aa

Please sign in to comment.