Skip to content

Commit

Permalink
Merge pull request #72 from mdsreq-fga-unb/55_adicionar__final
Browse files Browse the repository at this point in the history
USs 55 e 56 com correção de alguns problemas
  • Loading branch information
Victor-oss authored Dec 10, 2023
2 parents b6b3308 + 717e49d commit 7fdd094
Show file tree
Hide file tree
Showing 45 changed files with 2,335 additions and 1,525 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dependencies": {
"@prisma/client": "^5.4.2",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE "DrillElement" (
"id" TEXT NOT NULL,
"index" INTEGER NOT NULL,
"top" INTEGER NOT NULL,
"left" INTEGER NOT NULL,
"drillId" TEXT NOT NULL,

CONSTRAINT "DrillElement_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "DrillElement" ADD CONSTRAINT "DrillElement_drillId_fkey" FOREIGN KEY ("drillId") REFERENCES "Drill"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `image` to the `Drill` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Drill" ADD COLUMN "image" TEXT NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ClassPlan" ALTER COLUMN "userId" SET DEFAULT '';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "ClassPlan" ALTER COLUMN "userId" DROP DEFAULT;

-- AlterTable
ALTER TABLE "Drill" ALTER COLUMN "image" SET DEFAULT '';
13 changes: 12 additions & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@ model ClassPlan {
}

model Drill {
id String @id @default(uuid())
id String @id @default(uuid())
title String
description String
observations String
image String @default("")
classPlanId String
classPlan ClassPlan @relation(fields: [classPlanId], references: [id])
drillElements DrillElement[]
}

model DrillElement{
id String @id @default(uuid())
index Int
top Int
left Int
drillId String
drill Drill @relation(fields: [drillId], references: [id])
}
4 changes: 3 additions & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import "dotenv/config"
const app = express()

app.use(cors())
app.use(express.json())
app.use(express.json({ limit: "200mb" }))
app.use(express.urlencoded({ limit: "200mb", extended: true }))
app.use(express.text({ limit: "200mb" }))
app.use(router)

export { app }
23 changes: 22 additions & 1 deletion backend/src/controllers/classPlanController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class classPlanController {
try {
const { id } = req.params

const classPlan = await prisma.classPlan.delete({
const classPlan = await prisma.classPlan.deleteMany({
where: { id },
})

Expand All @@ -92,4 +92,25 @@ export default class classPlanController {
res.status(500).json({ errors: { server: "Server error" } })
}
}
updateById = async (req: Request, res: Response) => {
try {
const id = req.params.id
const data = classPlanSchema.parse(req.body)
const updatedPlan = await prisma.classPlan.update({
where: {
id,
},
data: {
...data,
},
})
res.status(204).json(updatedPlan)
} catch (err) {
if (err instanceof ZodError) {
res.status(400).json(fromZodError(err))
} else {
res.status(500).json({ error: "Internal Server Error" })
}
}
}
}
22 changes: 21 additions & 1 deletion backend/src/controllers/drillController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class drillController {
})
res.status(204).json(updatedDrill)
} catch (err) {
console.log("newds", err)
if (err instanceof ZodError) {
res.status(400).json(fromZodError(err))
} else {
Expand All @@ -71,16 +72,35 @@ export default class drillController {
}
}

updateImage = async (req: Request, res: Response) => {
try {
const id = req.params.id
const image = req.body.image
const updatedDrill = await prisma.drill.update({
where: {
id,
},
data: {
image,
},
})
res.status(204).json(updatedDrill)
} catch (err) {
res.status(500).json({ error: "Internal Server Error" })
}
}

deleteById = async (req: Request, res: Response) => {
try {
const id = req.params.id
const deletedDrill = await prisma.drill.delete({
const deletedDrill = await prisma.drill.deleteMany({
where: {
id,
},
})
res.status(204).json(deletedDrill)
} catch (err) {
console.log(err)
res.status(500).json({ error: "Internal Server Error" })
}
}
Expand Down
89 changes: 89 additions & 0 deletions backend/src/controllers/drillElementController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Request, Response } from "express"
import { prisma } from "@/prisma"
import { ZodError } from "zod"
import { drillElementSchema } from "@/zodSchemas/drillElement.zod"
import { fromZodError } from "zod-validation-error"
import { Prisma } from "@prisma/client"

export default class drillElementController {
create = async (req: Request, res: Response) => {
try {
const data = drillElementSchema.parse(req.body)
const drillElement = (await prisma.drillElement.create({
data: {
...data,
},
include: {
drill: {
select: {
id: true,
},
},
},
})) as Prisma.DrillElementCreateInput
res.status(201).json(drillElement)
} catch (err) {
if (err instanceof ZodError) {
res.status(400).json(fromZodError(err))
} else {
res.status(500).json({ error: "Internal Server Error" })
}
}
}

getManyByDrillId = async (req: Request, res: Response) => {
try {
const { drillId } = req.params
const drillElements = await prisma.drillElement.findMany({
where: {
drillId,
},
select: {
id: true,
top: true,
left: true,
index: true,
},
})
res.status(200).json(drillElements)
} catch (err) {
res.status(500).json({ error: "Internal Server Error" })
}
}

updateById = async (req: Request, res: Response) => {
try {
const { id } = req.params
const data = drillElementSchema.parse(req.body)
const updatedDrillElement = await prisma.drillElement.update({
where: {
id,
},
data: {
...data,
},
})
res.status(204).json(updatedDrillElement)
} catch (err) {
if (err instanceof ZodError) {
res.status(400).json(fromZodError(err))
} else {
res.status(500).json({ error: "Internal Server Error" })
}
}
}

deleteById = async (req: Request, res: Response) => {
try {
const { id } = req.params
const deletedDrillElement = await prisma.drillElement.deleteMany({
where: {
id,
},
})
res.status(204).json(deletedDrillElement)
} catch (err) {
res.status(500).json({ error: "Internal Server Error" })
}
}
}
1 change: 1 addition & 0 deletions backend/src/routes/classPlanRouters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const classPlan = new classPlanController()
classPlanRouters.post("/", classPlan.create)
classPlanRouters.get("/:id", classPlan.show)
classPlanRouters.get("/planos-usuario/:userId", classPlan.list)
classPlanRouters.put("/:id", classPlan.updateById)
classPlanRouters.delete("/:id", classPlan.delete)

export default classPlanRouters
12 changes: 12 additions & 0 deletions backend/src/routes/drillElementRouters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Router } from "express"
import drillElementController from "@/controllers/drillElementController"

const drillElementRouters = Router()
const drillElement = new drillElementController()

drillElementRouters.post("/", drillElement.create)
drillElementRouters.get("/:drillId", drillElement.getManyByDrillId)
drillElementRouters.put("/:id", drillElement.updateById)
drillElementRouters.delete("/:id", drillElement.deleteById)

export default drillElementRouters
1 change: 1 addition & 0 deletions backend/src/routes/drillRouters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ drillRouters.post("/", drill.create)
drillRouters.get("/:classPlanId", drill.getManyByClassPlanId)
drillRouters.get("/drill/:id", drill.show)
drillRouters.put("/:id", drill.updateById)
drillRouters.put("/image/:id", drill.updateImage)
drillRouters.delete("/:id", drill.deleteById)

export default drillRouters
2 changes: 2 additions & 0 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import homeRoutes from "./homeRouters"
import userRoutes from "./userRouters"
import classPlanRouters from "./classPlanRouters"
import drillRouters from "./drillRouters"
import drillElementRouters from "./drillElementRouters"

const router = Router()

router.use("/", homeRoutes)
router.use("/user", userRoutes)
router.use("/classPlan", classPlanRouters)
router.use("/drill", drillRouters)
router.use("/drillElement", drillElementRouters)

export { router }
1 change: 1 addition & 0 deletions backend/src/zodSchemas/drill.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const drillSchema = z.object({
.string()
.max(500, "Observações deve ter no máximo 500 caracteres"),
classPlanId: z.string().uuid("Id do plano de aula inválido"),
image: z.string(),
})

export { drillSchema }
10 changes: 10 additions & 0 deletions backend/src/zodSchemas/drillElement.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from "zod"

const drillElementSchema = z.object({
index: z.number(),
top: z.number(),
left: z.number(),
drillId: z.string().uuid("Id do drill inválida"),
})

export { drillElementSchema }
30 changes: 29 additions & 1 deletion backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,24 @@ [email protected]:
type-is "~1.6.18"
unpipe "1.0.0"

body-parser@^1.20.2:
version "1.20.2"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.2.tgz#6feb0e21c4724d06de7ff38da36dad4f57a747fd"
integrity sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==
dependencies:
bytes "3.1.2"
content-type "~1.0.5"
debug "2.6.9"
depd "2.0.0"
destroy "1.2.0"
http-errors "2.0.0"
iconv-lite "0.4.24"
on-finished "2.4.1"
qs "6.11.0"
raw-body "2.5.2"
type-is "~1.6.18"
unpipe "1.0.0"

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz"
Expand Down Expand Up @@ -1455,7 +1473,7 @@ [email protected]:
dependencies:
safe-buffer "5.2.1"

content-type@~1.0.4:
content-type@~1.0.4, content-type@~1.0.5:
version "1.0.5"
resolved "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz"
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==
Expand Down Expand Up @@ -3439,6 +3457,16 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

[email protected]:
version "2.5.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a"
integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==
dependencies:
bytes "3.1.2"
http-errors "2.0.0"
iconv-lite "0.4.24"
unpipe "1.0.0"

react-is@^18.0.0:
version "18.2.0"
resolved "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz"
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"apexcharts": "^3.41.0",
"axios": "^1.6.2",
"headlessui": "^0.0.0",
"html2canvas": "^1.4.1",
"jsvectormap": "^1.5.3",
"match-sorter": "^6.3.1",
"react": "^18.2.0",
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/DrillElement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import useDragger from "./useDragger";


const DrillElement: React.FC<{id : string, deleteItem : (idDeleted: string) => void, image: any, elementWidth: number, top: number, left: number}> = ({id, deleteItem, image, elementWidth, top, left}) => {
useDragger(id, deleteItem);
return(
<img id={id} style={{width: `${elementWidth}px`, boxSizing: "content-box", position:"absolute", cursor: "pointer", top: `${top}px`, left: `${left}px`}} alt="Drill Element" src={image}></img>
);
}

export default DrillElement;
Loading

0 comments on commit 7fdd094

Please sign in to comment.