Skip to content

Commit

Permalink
added in spec endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
whkelvin committed Dec 28, 2024
1 parent ba45159 commit e891e30
Show file tree
Hide file tree
Showing 20 changed files with 922 additions and 104 deletions.
27 changes: 27 additions & 0 deletions prisma/migrations/20241226210647_added_spec_snapshot/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- CreateTable
CREATE TABLE "Specification" (
"id" SERIAL NOT NULL,
"uuid" TEXT NOT NULL,
"name" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "SpecificationSnapshot" (
"id" SERIAL NOT NULL,
"uuid" TEXT NOT NULL,
"specId" INTEGER NOT NULL,
"prevSnapshotId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"versionNum" INTEGER NOT NULL,
"content" TEXT NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "SpecificationSnapshot_prevSnapshotId_key" ON "SpecificationSnapshot"("prevSnapshotId");

-- AddForeignKey
ALTER TABLE "SpecificationSnapshot" ADD CONSTRAINT "SpecificationSnapshot_specId_fkey" FOREIGN KEY ("specId") REFERENCES "Specification"("id") ON DELETE CASCADE ON UPDATE CASCADE;
26 changes: 26 additions & 0 deletions prisma/migrations/20241226211957_created_spec_owner/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Warnings:
- Added the required column `userId` to the `SpecificationSnapshot` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "SpecificationSnapshot" ADD COLUMN "userId" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "BridgeUserAndSpecfication" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"specId" INTEGER NOT NULL,

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

-- AddForeignKey
ALTER TABLE "BridgeUserAndSpecfication" ADD CONSTRAINT "BridgeUserAndSpecfication_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BridgeUserAndSpecfication" ADD CONSTRAINT "BridgeUserAndSpecfication_specId_fkey" FOREIGN KEY ("specId") REFERENCES "Specification"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SpecificationSnapshot" ADD CONSTRAINT "SpecificationSnapshot_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This is an empty migration.
16 changes: 16 additions & 0 deletions prisma/migrations/20241226213753_updated_field_name/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:
- You are about to drop the column `userId` on the `SpecificationSnapshot` table. All the data in the column will be lost.
- Added the required column `creatorId` to the `SpecificationSnapshot` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "SpecificationSnapshot" DROP CONSTRAINT "SpecificationSnapshot_userId_fkey";

-- AlterTable
ALTER TABLE "SpecificationSnapshot" DROP COLUMN "userId",
ADD COLUMN "creatorId" INTEGER NOT NULL;

-- AddForeignKey
ALTER TABLE "SpecificationSnapshot" ADD CONSTRAINT "SpecificationSnapshot_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
45 changes: 38 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,49 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
uuid String
email String @unique
sessions Session[]
username String
google_id String?
id Int @id @default(autoincrement())
uuid String
email String @unique
sessions Session[]
username String
google_id String?
bridgeUserAndSpecification BridgeUserAndSpecfication[]
SpecificationSnapshot SpecificationSnapshot[]
}

model Session {
id String @id
uuid String
uuid String
userId Int
expiresAt DateTime
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
}

model BridgeUserAndSpecfication {
id Int @id @default(autoincrement())
userId Int
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
specId Int
spec Specification @relation(references: [id], fields: [specId], onDelete: Cascade)
}

model Specification {
id Int @id @default(autoincrement())
uuid String
name String
specSnapshots SpecificationSnapshot[]
bridgeUserAndSpecification BridgeUserAndSpecfication[]
}

model SpecificationSnapshot {
id Int @id @default(autoincrement())
uuid String
specId Int
spec Specification @relation(references: [id], fields: [specId], onDelete: Cascade)
prevSnapshotId String @unique
createdAt DateTime @default(now())
versionNum Int
content String
creatorId Int
createdBy User @relation(references: [id], fields: [creatorId], onDelete: Cascade)
}
8 changes: 8 additions & 0 deletions spec/client/createSpec.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST localhost:5173/api/spec/createSpec
Cookie: sessionToken=wm6yy37jowyacj73eqvdelxliyrkxc3z;HttpOnly=true;SameSite=Lax;Expires=2025-01-21T18:28:11.755Z;Path=/;

{
"name": "firstSpec",
"creatorUserId": "83edaa20-9f3c-49ae-b078-c10d496c27f3"
}

6 changes: 6 additions & 0 deletions spec/client/getLatestSpec.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POST localhost:5173/api/spec/getLatestSpecById
Cookie: sessionToken=wm6yy37jowyacj73eqvdelxliyrkxc3z;HttpOnly=true;SameSite=Lax;Expires=2025-01-21T18:28:11.755Z;Path=/;

{
"id": "97ce9b27-016f-4929-9cf9-aae2cded9d99"
}
6 changes: 6 additions & 0 deletions spec/client/getSpecs.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POST localhost:5173/api/spec/getSpecs
Cookie: sessionToken=wm6yy37jowyacj73eqvdelxliyrkxc3z;HttpOnly=true;SameSite=Lax;Expires=2025-01-21T18:28:11.755Z;Path=/;

{
"userId": "83edaa20-9f3c-49ae-b078-c10d496c27f3"
}
10 changes: 10 additions & 0 deletions spec/client/updateSpec.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POST localhost:5173/api/spec/updateSpec
Cookie: sessionToken=wm6yy37jowyacj73eqvdelxliyrkxc3z;HttpOnly=true;SameSite=Lax;Expires=2025-01-21T18:28:11.755Z;Path=/;

{
"specId": "97ce9b27-016f-4929-9cf9-aae2cded9d99",
"content": "hello world",
"prevSpecSnapshotId": "54fce999-8e6a-482f-b7d8-b4837b1fe66c",
"updatorUserId": "83edaa20-9f3c-49ae-b078-c10d496c27f3"
}

Loading

0 comments on commit e891e30

Please sign in to comment.