Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task organizer #38

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions app/api/board/[board_id]/group/[group_id]/mytask/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();
import getSessionUser from "@/utils/session";


export async function GET(req: Request, { params }: any) {
const user = await getSessionUser();
const { board_id, group_id } = params;
// const user = {id: 1}
const task = await prisma.userTask.findMany({
where: {
user_id: user.id,
task: {
group_id: +group_id
},
user: {
boardPartition: {
some: {
board_id: +board_id
}
}
}
},
include: {
task: true
}
})
return getResponse(task, "Get my task success", 200);
}
43 changes: 43 additions & 0 deletions app/api/board/[board_id]/group/[group_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();

export async function PUT(req: Request, { params }: any) {
const { group_id } = params;
const group = await prisma.group.findFirst({
where: {
id: +group_id
}
});
if (!group) return getResponse(null, 'Group not found', 404);

const {name, position, img_url} = await req.json();
const newGroup = await prisma.group.update({
where: {
id: +group_id
},
data: {
name,
position,
img_url
}
});
return getResponse(newGroup, "Group updated", 200);
}


export async function DELETE(req: Request, { params }: any) {
const { group_id } = params;
const group = await prisma.group.findFirst({
where: {
id: +group_id
}
});
if (!group) return getResponse(null, 'Group not found', 404);
const newGroup = await prisma.group.delete({
where: {
id: +group_id
}
});
return getResponse(newGroup, "Group deleted", 200);
}
50 changes: 50 additions & 0 deletions app/api/board/[board_id]/group/[group_id]/task/[task_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();


export async function PUT(req: Request, { params }: any) {
const { task_id } = params;
const {name, position, tags, deadline, description} = await req.json();
const newTask = await prisma.task.update({
where: {
id: +task_id
},
data: {
name,
position,
tags,
deadline,
description
}
})
return getResponse(newTask, "Update task success", 200);
}

export async function DELETE(req: Request, { params }: any) {
const { task_id } = params;
const Task = await prisma.task.delete({
where: {
id: +task_id
}
})
return getResponse(Task, "Task deleted", 200);
}


// export async function GET(req: Request, { params }: any) {
// const { group_id } = params;
// if(!group_id) {
// const task = await prisma.task.findMany({
// where: {
// group_id: +group_id
// }
// })
// }
// const task = await prisma.task.findMany({
// where: {
// group_id: +group_id
// }
// })
// return getResponse(task, "Get task success", 200);
// }
41 changes: 41 additions & 0 deletions app/api/board/[board_id]/group/[group_id]/task/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();
import getSessionUser from "@/utils/session";


export async function POST(req: Request, { params }: any) {
const user = await getSessionUser();
// const user = {id: 1}
const { group_id } = params;
const {name, position, tags, deadline, description} = await req.json();
const task = await prisma.task.create({
data: {
name,
position,
tags,
deadline,
description,
group_id: +group_id
}
})

await prisma.userTask.create({
data: {
user_id: user.id,
task_id: task.id
}
})
return getResponse(task, "Create task success", 200);
}


export async function GET(req: Request, { params }: any) {
const { group_id } = params;
const task = await prisma.task.findMany({
where: {
group_id: +group_id
}
})
return getResponse(task, "Get task success", 200);
}
33 changes: 33 additions & 0 deletions app/api/board/[board_id]/group/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();


export async function POST(req: Request, { params }: any) {
const { board_id } = params;
const {name, position, img_url} = await req.json();
const group = await prisma.group.create({
data: {
name,
position,
img_url,
board: {
connect: {
id: +board_id
}
}
}
})
return getResponse(group, "Create group success", 200);
}

export async function GET(req: Request, { params }: any) {
const { board_id } = params;
const group = await prisma.group.findMany({
where: {
board_id: +board_id
}
});
if (!group) return getResponse(null, 'Group not found', 404);
return getResponse(group, "Get group success", 200);
}
41 changes: 41 additions & 0 deletions app/api/board/[board_id]/partition/[partition_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import getResponse from "@/utils/getResponse";
import getSessionUser from "@/utils/session";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient()

export async function DELETE(req:Request,{ params }: any) {
const { partition_id } = params;
const boardPartition = await prisma.boardPartition.findFirst({
where: {
id: +partition_id,
},
});
if (!boardPartition) return getResponse(null, 'Partition not found', 404);
await prisma.boardPartition.delete({
where: {
id: +partition_id,
}
});
return getResponse(boardPartition, "Partition deleted", 200);
}

export async function PUT(req:Request,{ params }: any) {
const { partition_id } = params;
const {isOwner} = await req.json();
const boardPartition = await prisma.boardPartition.findFirst({
where: {
id: +partition_id,
},
});
if (!boardPartition) return getResponse(null, 'Partition not found', 404);
const partitionUpdated = await prisma.boardPartition.update({
where: {
id: +partition_id,
},
data: {
isOwner
}
});
return getResponse(partitionUpdated, "Partition updated", 200);
}

29 changes: 29 additions & 0 deletions app/api/board/[board_id]/partition/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import getResponse from "@/utils/getResponse";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient()

export async function GET(req: Request, { params }: any) {
const { board_id } = params;
if (!board_id) {
const boardPartition = await prisma.boardPartition.findMany({
include: {
user: {
select: {
id: true,
name: true,
username: true
}
}
}
});
return getResponse(boardPartition, "Get Partition", 200);
}

const boardPartition = await prisma.boardPartition.findFirst({
where: {
id: +board_id
}
})
if (!boardPartition) return getResponse(null, 'Partition not found', 404);
return getResponse(boardPartition, "Get Partition", 200);
}
52 changes: 52 additions & 0 deletions app/api/board/[board_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import getResponse from "@/utils/getResponse";
import getSessionUser from "@/utils/session";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient()

export async function GET(req: Request, { params }: any) {
const { board_id } = params;
const board = await prisma.board.findFirst({
where: {
id: +board_id
}
});
if (!board) return getResponse(null, 'Partition not found', 404);
return getResponse(board, "Get board by id success", 200);
}

export async function DELETE(req: Request, { params }: any) {
const { board_id } = params;
const board = await prisma.board.findFirst({
where: {
id: +board_id
},
});
if (!board) return getResponse(null, 'Board not found', 404);
await prisma.board.delete({
where: {
id: +board_id,
},
});
return getResponse(board, "Board deleted", 200);
}

export async function PUT(req: Request, { params }: any) {
const { board_id } = params;
const {name,visibility} = await req.json();
const board = await prisma.board.findFirst({
where: {
id: +board_id,
},
});
if (!board) return getResponse(null, "board not found", 404);
const newBoard = await prisma.board.update({
where: {
id: +board_id,
},
data: {
name,
visibility
},
});
return getResponse(newBoard, "board Updated", 200);
}
19 changes: 19 additions & 0 deletions app/api/board/alltask/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();
import getSessionUser from "@/utils/session";


export async function GET(req: Request) {
const user = await getSessionUser();
// const user = {id: 1}
const task = await prisma.userTask.findMany({
where: {
user_id: user.id
},
include: {
task: true
}
})
return getResponse(task, "Get my task success", 200);
}
18 changes: 18 additions & 0 deletions app/api/board/myboard/own/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getSessionUser from "@/utils/session";
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
const prisma = new PrismaClient();


export async function GET(req: Request) {
const user = await getSessionUser();
// const user = {id: 1}
const boardPartition = await prisma.boardPartition.findMany({
where: {
user_id: user.id,
isOwner: true
}
});
if (!boardPartition) return getResponse(null, 'Board not found', 404);
return getResponse(boardPartition, "Get my own board success", 200);
}
18 changes: 18 additions & 0 deletions app/api/board/myboard/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getSessionUser from "@/utils/session";
import { PrismaClient } from "@prisma/client";
import getResponse from "@/utils/getResponse";
import { get } from "http";
const prisma = new PrismaClient();


export async function GET(req: Request) {
const user = await getSessionUser();
// const user = {id: 1}
const boardPartition = await prisma.boardPartition.findMany({
where: {
user_id: user.id
}
});
if (!boardPartition) return getResponse(null, 'Board not found', 404);
return getResponse(boardPartition, "Get my board success", 200);
}
Loading