Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zl8244 committed Apr 15, 2024
2 parents d2da0bd + 3c43cec commit 7f5c8eb
Show file tree
Hide file tree
Showing 12 changed files with 3,030 additions and 6,816 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/postman-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ jobs:
reporters: cli

- name: Output summary to console
if: always()
run: |
echo ${{ steps.run-newman.outputs.summary }}
run: echo ${{ steps.run-newman.outputs.summary }}
10 changes: 9 additions & 1 deletion next/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ next-env.d.ts
# jetbrains
.idea

# nix envs
# jetbrains
.idea

# jetbrains
.idea

# Nix
flake.nix
flake.lock
.envrc
.direnv
2 changes: 0 additions & 2 deletions next/app/api/golinks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const prisma = new PrismaClient();
function validateGoLink(goLink: string) {
return /^[a-z\-]+$/.test(goLink);
}

/**
* HTTP POST request to /api/golinks
* Create a new Golink
Expand Down Expand Up @@ -32,7 +31,6 @@ export async function POST(request: Request) {
status: 422,
});
}

const newGolink = await prisma.goLinks.create({
data: {
golink: golink,
Expand Down
2 changes: 1 addition & 1 deletion next/app/api/skill/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function GET(request: Request, { params }: { params: { id: string }
id,
},
select: {
id: true,
skill: true,
mentorSkill: {
select: {
Expand All @@ -28,4 +29,3 @@ export async function GET(request: Request, { params }: { params: { id: string }
return new Response("Invalid Skill ID", { status: 400 });
}
}

12 changes: 12 additions & 0 deletions next/app/api/skill/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const prisma = new PrismaClient();
export async function GET() {
const skills = await prisma.skill.findMany({
select: {
id: true,
skill: true,
mentorSkill: {
select: {
Expand Down Expand Up @@ -68,6 +69,17 @@ export async function PUT(request: Request) {
return new Response(`Coulnd't find skill ID ${body.id}`, { status: 404 });
}

if (body.skill != undefined) {
const skill_in_use = await prisma.skill.findUnique({
where: {
skill: body.skill,
},
});
if (skill_in_use != undefined && skill_in_use?.id != body.id) {
return new Response(`skill ${body.skill} already exists`, { status: 422 });
}
}

const skill = await prisma.skill.update({
where: {
id: body.id,
Expand Down
31 changes: 31 additions & 0 deletions next/app/api/skills/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const id = parseInt(params.id);
const skill = await prisma.skill.findUnique({
where: {
id,
},
select: {
skill: true,
mentorSkill: {
select: {
id: true,
mentor_Id: true,
skill_Id: true,
},
},
},
});
if (skill == null) {
return new Response(`Couldn't find Skill ID ${id}`, { status: 404 });
}
return Response.json(skill);
} catch {
return new Response("Invalid Skill ID", { status: 400 });
}
}

88 changes: 88 additions & 0 deletions next/app/api/skills/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function GET() {
const skills = await prisma.skill.findMany({
select: {
skill: true,
mentorSkill: {
select: {
id: true,
mentor_Id: true,
skill_Id: true,
},
},
},
});
return Response.json(skills);
}

export async function POST(request: Request) {
let body;
try {
body = await request.json();
} catch {
return new Response("Invalid JSON", { status: 422 });
}

console.log(body);

if (!("skill" in body)) {
return new Response("skill must be included in the body", { status: 400 });
}
const skillName = body.skill;

console.log(`skill name: ${skillName}`);

const skillCount = await prisma.skill.count();

console.log(skillCount);

const skill = await prisma.skill.create({
data: {
id: skillCount+1,
skill: skillName,
},
});

console.log(skill);

return Response.json(skill, { status: 201 });
}

export async function DELETE(request: Request) {
let body;
try {
body = await request.json();
} catch {
return new Response("Invalid JSON", { status: 420 });
}

if (!("id" in body)) {
return new Response("ID must be in body", { status: 400 });
}
const id = body.id;

console.log(id);

const skillExists = await prisma.skill.findUnique({
where: {
id: id,
},
});
if (skillExists == null) {
return new Response(`Coulnd't find skill ID ${id}`, { status: 404 });
}

const _deleteMentorSkills = await prisma.mentorSkill.deleteMany({
where: { skill_Id: id },
});

const skill = await prisma.skill.delete({
where: {
id: id,
},
});
return Response.json(skill);
}
1 change: 1 addition & 0 deletions next/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
openssl
prisma-engines
nodePackages.prisma
nodePackages.ts-node
];
Expand Down
Loading

0 comments on commit 7f5c8eb

Please sign in to comment.