-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from mdsreq-fga-unb/55_adicionar__final
USs 55 e 56 com correção de alguns problemas
- Loading branch information
Showing
45 changed files
with
2,335 additions
and
1,525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/prisma/migrations/20231209123252_drill_elements/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
8 changes: 8 additions & 0 deletions
8
backend/prisma/migrations/20231210001754_adiciona_imagem_no_drill/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
2 changes: 2 additions & 0 deletions
2
backend/prisma/migrations/20231210004612_adiciona_valor_defaut/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "ClassPlan" ALTER COLUMN "userId" SET DEFAULT ''; |
5 changes: 5 additions & 0 deletions
5
backend/prisma/migrations/20231210050628_adiciona_valor_defalt/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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== | ||
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.