Skip to content

Commit

Permalink
chore:testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SySagar committed Nov 13, 2023
1 parent dabfbd2 commit 98e32ec
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 1 deletion.
12 changes: 12 additions & 0 deletions prisma/migrations/20231113164424_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "Blog" (
"id" STRING NOT NULL,
"title" STRING NOT NULL,
"tags" STRING[],
"content" STRING NOT NULL,
"date" STRING NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Blog_pkey" PRIMARY KEY ("id")
);
11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ model Induction {
preferred_primary_domain String
preferred_secondary_domain String
}


model Blog{
id String @id @default(cuid())
title String
tags String[]
content String
date String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
30 changes: 30 additions & 0 deletions src/app/blog/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {saveToDatabase} from './repository.js'

export const saveBlog = async (req, res) => {
const { title, content, tags,date } = req.body;
const blog = {
title,
tags,
content,
date
};
const result = await saveToDatabase(blog);
if(result) {
return res.send({
status: 201,
message: "blog saved successfully"
});
}
else
{
return res.send({
status: 500,
message: "blog could not be saved"
});
}
}

// const getBlogs = async (req, res) => {
// const blogs = await Blog.findAll();
// return res.json(blogs);
// }
1 change: 1 addition & 0 deletions src/app/blog/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as blogRouter } from './routes.js'
19 changes: 19 additions & 0 deletions src/app/blog/repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import db from "../../db/client.js"

export const saveToDatabase = (blog) => {
// Save to database
return db.Blog.create({
data:blog
});

}

// export const getAllBlogs = async () => {
// try {
// const blogs = await db.Blog.findAll();
// return blogs;
// } catch (error) {
// console.log(error);
// return [];
// }
// }
10 changes: 10 additions & 0 deletions src/app/blog/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { saveBlog } from "./controller.js";


const router = Router()

router.post('/create', saveBlog)
// router.get('/', getAllInductionController)

export default router;
4 changes: 3 additions & 1 deletion src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { eventRouter } from "./event/index.js";
import { mediaRouter } from "./media/index.js";
import { inductionRouter } from "./induction/index.js";
import { githubRouter } from "./github/index.js";
import {classicRouter} from"./classic/index.js";
import { classicRouter } from"./classic/index.js";
import { blogRouter } from "./blog/index.js";

const appRouter = Router()

Expand All @@ -14,5 +15,6 @@ appRouter.use('/event', eventRouter)
appRouter.use('/media', mediaRouter)
appRouter.use('/induction', inductionRouter)
appRouter.use('/github', githubRouter)
appRouter.use('/blog', blogRouter)

export default appRouter

0 comments on commit 98e32ec

Please sign in to comment.