Skip to content

Commit

Permalink
Merge pull request #18 from UoaWDCC/UADS-53-CMS
Browse files Browse the repository at this point in the history
UADS-53/feat/CMS
  • Loading branch information
Harsheel12 authored Jun 27, 2024
2 parents 5613008 + f1c6101 commit d6e22fb
Show file tree
Hide file tree
Showing 36 changed files with 2,342 additions and 550 deletions.
44 changes: 31 additions & 13 deletions backend/controllers/EventController.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import { Request, Response } from "express";
import Event from "../models/Event";
import { Client } from "@notionhq/client";
import { EventRow, eventRowsStructured } from "../utils/BackendTypes";
import { config } from "dotenv";
config();

const notionSecret = process.env.NOTION_SECRET;
const eventID = process.env.EVENT_DB_ID;

const notion = new Client({
auth: notionSecret,
});

const getEvents = async (req: Request, res: Response) => {
res.json({msg: "Implement GET endpoint"});
}
if (!notionSecret || !eventID) {
throw new Error("Missing creds");
}

const query = await notion.databases.query({
database_id: eventID,
});

// @ts-ignore
const rows = query.results.map((res) => res.properties) as EventRow[];

const createEvent = async (req: Request, res: Response) => {
res.json({msg: "Implement POST endpoint"});
}
const rowsStructured: eventRowsStructured = rows.map((row) => ({
name: row.Name.title[0].text.content,
date: row.Date.date.start,
description: row.Description.rich_text[0].text.content,
image: row.Image.files[0].file.url,
}));

const deleteEvent = async (req: Request, res: Response) => {
res.json({msg: "Implement DELETE endpoint"});
}
const orderedRowsStructured = rowsStructured.reverse();

const updateEvent = async (req: Request, res: Response) => {
res.json({msg: "Implement PATCH endpoint"});
}
res.status(200).json(orderedRowsStructured);
};

export {getEvents, createEvent, deleteEvent, updateEvent};
export { getEvents };
37 changes: 37 additions & 0 deletions backend/controllers/ExecController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Request, Response } from "express";
import { Client } from "@notionhq/client";
import { ExecRow, execRowsStructured } from "../utils/BackendTypes";
import { config } from "dotenv";
config();

const notionSecret = process.env.NOTION_SECRET;
const execID = process.env.EXEC_DB_ID;

const notion = new Client({
auth: notionSecret,
});

const getExecs = async (req: Request, res: Response) => {
if (!notionSecret || !execID) {
throw new Error("Missing creds");
}

const query = await notion.databases.query({
database_id: execID,
});

// @ts-ignore
const rows = query.results.map((res) => res.properties) as ExecRow[];

const rowsStructured: execRowsStructured = rows.map((row) => ({
name: row.Name.title[0].text.content,
role: row.Role.rich_text[0].text.content,
image: row.Image.files[0].file.url,
}));

const orderedRowsStructured = rowsStructured.reverse();

res.status(200).json(orderedRowsStructured);
};

export { getExecs };
36 changes: 36 additions & 0 deletions backend/controllers/SocialController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Request, Response } from "express";
import { Client } from "@notionhq/client";
import { SocialRow, socialRowsStructured } from "../utils/BackendTypes";
import { config } from "dotenv";
config();

const notionSecret = process.env.NOTION_SECRET;
const socialID = process.env.SOCIAL_DB_ID;

const notion = new Client({
auth: notionSecret,
});

const getSocials = async (req: Request, res: Response) => {
if (!notionSecret || !socialID) {
throw new Error("Missing creds");
}

const query = await notion.databases.query({
database_id: socialID,
});

// @ts-ignore
const rows = query.results.map((res) => res.properties) as SocialRow[];

const rowsStructured: socialRowsStructured = rows.map((row) => ({
name: row.Name.title[0].text.content,
link: row.Link.url,
}));

const orderedRowsStructured = rowsStructured.reverse();

res.status(200).json(orderedRowsStructured);
};

export { getSocials };
43 changes: 30 additions & 13 deletions backend/controllers/SponsorController.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import { Request, Response } from "express";
import Sponsor from "../models/Sponsor";
import { Client } from "@notionhq/client";
import { SponsorRow, sponsorRowsStructured } from "../utils/BackendTypes";
import { config } from "dotenv";
config();

const notionSecret = process.env.NOTION_SECRET;
const sponsorID = process.env.SPONSOR_DB_ID;

const notion = new Client({
auth: notionSecret,
});

const getSponsors = async (req: Request, res: Response) => {
res.json({msg: "Implement GET endpoint"});
}
if (!notionSecret || !sponsorID) {
throw new Error("Missing creds");
}

const query = await notion.databases.query({
database_id: sponsorID,
});

// @ts-ignore
const rows = query.results.map((res) => res.properties) as SponsorRow[];

const createSponsor = async (req: Request, res: Response) => {
res.json({msg: "Implement POST endpoint"});
}
const rowsStructured: sponsorRowsStructured = rows.map((row) => ({
name: row.Name.title[0].text.content,
description: row.Description.rich_text[0].text.content,
image: row.Image.files[0].file.url,
}));

const deleteSponsor = async (req: Request, res: Response) => {
res.json({msg: "Implement DELETE endpoint"});
}
const orderedRowsStructured = rowsStructured.reverse();

const updateSponsor = async (req: Request, res: Response) => {
res.json({msg: "Implement PATCH endpoint"});
}
res.status(200).json(orderedRowsStructured);
};

export {getSponsors, createSponsor, deleteSponsor, updateSponsor};
export { getSponsors };
28 changes: 13 additions & 15 deletions backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import express, { json } from 'express';
import cors from 'cors';
import { connect } from 'mongoose';
import { config } from 'dotenv';
import express, { json } from "express";
import cors from "cors";
import router from "./routes/routes";
import { config } from "dotenv";
config();

// Import Routers
import router from './routes/routes';
// Sets our port to the PORT .env value or 4000 by default if .env is not configured
const PORT = process.env.PORT ?? 4000;

// Creates the express server
const app = express();
config();

// const databaseUrl: string = process.env.DATABASE_URL!;
// connect(databaseUrl);

// Express middleware
app.use(json());
app.use(cors());
app.use(express.static('public'));
app.use(express.static("public"));

// Routes
app.use('/', router);
app.use("/", router);

const port = Number.parseInt(process.env.PORT || '3000');
app.listen(port, () => {
console.log(`Listening on port ${port}`);
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
31 changes: 0 additions & 31 deletions backend/models/Event.ts

This file was deleted.

31 changes: 0 additions & 31 deletions backend/models/Sponsor.ts

This file was deleted.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@notionhq/client": "^2.2.15",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/nodemailer": "^6.4.14",
Expand Down
19 changes: 5 additions & 14 deletions backend/routes/eventRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { Router } from "express"
import { getEvents, createEvent, deleteEvent, updateEvent } from "../controllers/EventController";
import { Router } from "express";
import { getEvents } from "../controllers/EventController";

const eventRoutes = Router();

// GET all users
eventRoutes.get('/', getEvents);
// Get all Events
eventRoutes.get("/", getEvents);

// CREATE new user
eventRoutes.post('/', createEvent);

// DELETE a user
eventRoutes.delete('/:id', deleteEvent);

// Update a user
eventRoutes.patch('/:id', updateEvent);

export default eventRoutes;
export default eventRoutes;
9 changes: 9 additions & 0 deletions backend/routes/execRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from "express";
import { getExecs } from "../controllers/ExecController";

const execRoutes = Router();

// Get all Execs
execRoutes.get("/", getExecs);

export default execRoutes;
23 changes: 0 additions & 23 deletions backend/routes/hello.ts

This file was deleted.

8 changes: 8 additions & 0 deletions backend/routes/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import express from "express";
import eventRoutes from "./eventRoutes";
import sponsorRoutes from "./sponsorRoutes";
import execRoutes from "./execRoutes";
import socialRoutes from "./socialRoutes";

const router = express.Router();

Expand All @@ -10,4 +12,10 @@ router.use("/api/events", eventRoutes);
// All sponsor routes
router.use("/api/sponsors", sponsorRoutes);

// All exec routes
router.use("/api/execs", execRoutes);

// All exec routes
router.use("/api/socials", socialRoutes);

export default router;
9 changes: 9 additions & 0 deletions backend/routes/socialRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from "express";
import { getSocials } from "../controllers/SocialController";

const socialRoutes = Router();

// Get all Socials
socialRoutes.get("/", getSocials);

export default socialRoutes;
Loading

0 comments on commit d6e22fb

Please sign in to comment.