From 9da51e6065b293ee8d490b84fee853fbf7bb4fe0 Mon Sep 17 00:00:00 2001 From: JungangHighschool Date: Fri, 18 Aug 2023 22:04:25 +0900 Subject: [PATCH] hot-fix : creating user repo --- docker-compose.yml | 2 + .../migrations/20230727042812_/migration.sql | 8 --- .../migration.sql | 15 ----- .../migration.sql | 17 ------ .../migration.sql | 12 ---- .../migrations/20230802044433_/migration.sql | 11 ---- .../migrations/20230802044621_/migration.sql | 8 --- .../migrations/20230806062344_/migration.sql | 11 ---- .../migration.sql | 14 ----- .../migration.sql | 2 - .../migration.sql | 8 --- .../migrations/20230817124452_/migration.sql | 2 - .../migrations/20230818063054_/migration.sql | 57 ------------------- .../migration.sql | 31 +++++++--- src/problem/problem.service.ts | 2 + src/repos/repos.controller.ts | 10 +++- src/repos/repos.service.ts | 9 ++- 17 files changed, 43 insertions(+), 176 deletions(-) delete mode 100644 prisma/migrations/20230727042812_/migration.sql delete mode 100644 prisma/migrations/20230730083948_modify_testcase_table/migration.sql delete mode 100644 prisma/migrations/20230730084056_modify_hiddencase_table/migration.sql delete mode 100644 prisma/migrations/20230730130631_add_url_columns_on_testcase_and_hiddencase_table/migration.sql delete mode 100644 prisma/migrations/20230802044433_/migration.sql delete mode 100644 prisma/migrations/20230802044621_/migration.sql delete mode 100644 prisma/migrations/20230806062344_/migration.sql delete mode 100644 prisma/migrations/20230811131713_add_user_hidden_case_model/migration.sql delete mode 100644 prisma/migrations/20230811131938_add_is_correct_field_on_user_hidden_case/migration.sql delete mode 100644 prisma/migrations/20230812090919_add_output_field_on_hidden_case/migration.sql delete mode 100644 prisma/migrations/20230817124452_/migration.sql delete mode 100644 prisma/migrations/20230818063054_/migration.sql rename prisma/migrations/{20230717115256_init => 20230818130322_}/migration.sql (71%) diff --git a/docker-compose.yml b/docker-compose.yml index 3500ed1..8498246 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,8 @@ services: image: mcr.microsoft.com/vscode/devcontainers/typescript-node:18-bullseye ports: - 4000:4000 + expose: + - 4000 volumes: - .:/workspace:cached stdin_open: true diff --git a/prisma/migrations/20230727042812_/migration.sql b/prisma/migrations/20230727042812_/migration.sql deleted file mode 100644 index 60eb02d..0000000 --- a/prisma/migrations/20230727042812_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[url]` on the table `Repo` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateIndex -CREATE UNIQUE INDEX "Repo_url_key" ON "Repo"("url"); diff --git a/prisma/migrations/20230730083948_modify_testcase_table/migration.sql b/prisma/migrations/20230730083948_modify_testcase_table/migration.sql deleted file mode 100644 index 05cb2d0..0000000 --- a/prisma/migrations/20230730083948_modify_testcase_table/migration.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `input` on the `TestCase` table. All the data in the column will be lost. - - You are about to drop the column `output` on the `TestCase` table. All the data in the column will be lost. - - Added the required column `repoId` to the `TestCase` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "TestCase" DROP COLUMN "input", -DROP COLUMN "output", -ADD COLUMN "repoId" INTEGER NOT NULL; - --- AddForeignKey -ALTER TABLE "TestCase" ADD CONSTRAINT "TestCase_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20230730084056_modify_hiddencase_table/migration.sql b/prisma/migrations/20230730084056_modify_hiddencase_table/migration.sql deleted file mode 100644 index a70f0e8..0000000 --- a/prisma/migrations/20230730084056_modify_hiddencase_table/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `input` on the `HiddenCase` table. All the data in the column will be lost. - - You are about to drop the column `output` on the `HiddenCase` table. All the data in the column will be lost. - - Added the required column `bias` to the `HiddenCase` table without a default value. This is not possible if the table is not empty. - - Added the required column `repoId` to the `HiddenCase` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "HiddenCase" DROP COLUMN "input", -DROP COLUMN "output", -ADD COLUMN "bias" TEXT NOT NULL, -ADD COLUMN "repoId" INTEGER NOT NULL; - --- AddForeignKey -ALTER TABLE "HiddenCase" ADD CONSTRAINT "HiddenCase_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20230730130631_add_url_columns_on_testcase_and_hiddencase_table/migration.sql b/prisma/migrations/20230730130631_add_url_columns_on_testcase_and_hiddencase_table/migration.sql deleted file mode 100644 index 18f8943..0000000 --- a/prisma/migrations/20230730130631_add_url_columns_on_testcase_and_hiddencase_table/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - Added the required column `url` to the `HiddenCase` table without a default value. This is not possible if the table is not empty. - - Added the required column `url` to the `TestCase` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "HiddenCase" ADD COLUMN "url" VARCHAR(255) NOT NULL; - --- AlterTable -ALTER TABLE "TestCase" ADD COLUMN "url" VARCHAR(255) NOT NULL; diff --git a/prisma/migrations/20230802044433_/migration.sql b/prisma/migrations/20230802044433_/migration.sql deleted file mode 100644 index 8265c48..0000000 --- a/prisma/migrations/20230802044433_/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `url` on the `Repo` table. All the data in the column will be lost. - -*/ --- DropIndex -DROP INDEX "Repo_url_key"; - --- AlterTable -ALTER TABLE "Repo" DROP COLUMN "url"; diff --git a/prisma/migrations/20230802044621_/migration.sql b/prisma/migrations/20230802044621_/migration.sql deleted file mode 100644 index 066b42b..0000000 --- a/prisma/migrations/20230802044621_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[name]` on the table `Repo` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateIndex -CREATE UNIQUE INDEX "Repo_name_key" ON "Repo"("name"); diff --git a/prisma/migrations/20230806062344_/migration.sql b/prisma/migrations/20230806062344_/migration.sql deleted file mode 100644 index 7866f73..0000000 --- a/prisma/migrations/20230806062344_/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[userId,repoId]` on the table `UserRepo` will be added. If there are existing duplicate values, this will fail. - -*/ --- AlterTable -ALTER TABLE "User" ADD COLUMN "sshKey" TEXT; - --- CreateIndex -CREATE UNIQUE INDEX "UserRepo_userId_repoId_key" ON "UserRepo"("userId", "repoId"); diff --git a/prisma/migrations/20230811131713_add_user_hidden_case_model/migration.sql b/prisma/migrations/20230811131713_add_user_hidden_case_model/migration.sql deleted file mode 100644 index ba126df..0000000 --- a/prisma/migrations/20230811131713_add_user_hidden_case_model/migration.sql +++ /dev/null @@ -1,14 +0,0 @@ --- CreateTable -CREATE TABLE "UserHiddenCase" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "hiddenCaseId" INTEGER NOT NULL, - - CONSTRAINT "UserHiddenCase_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "UserHiddenCase" ADD CONSTRAINT "UserHiddenCase_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "UserHiddenCase" ADD CONSTRAINT "UserHiddenCase_hiddenCaseId_fkey" FOREIGN KEY ("hiddenCaseId") REFERENCES "HiddenCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20230811131938_add_is_correct_field_on_user_hidden_case/migration.sql b/prisma/migrations/20230811131938_add_is_correct_field_on_user_hidden_case/migration.sql deleted file mode 100644 index a33ad16..0000000 --- a/prisma/migrations/20230811131938_add_is_correct_field_on_user_hidden_case/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "UserHiddenCase" ADD COLUMN "isCorrect" BOOLEAN; diff --git a/prisma/migrations/20230812090919_add_output_field_on_hidden_case/migration.sql b/prisma/migrations/20230812090919_add_output_field_on_hidden_case/migration.sql deleted file mode 100644 index aeafb1c..0000000 --- a/prisma/migrations/20230812090919_add_output_field_on_hidden_case/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Added the required column `output` to the `HiddenCase` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "HiddenCase" ADD COLUMN "output" TEXT NOT NULL; diff --git a/prisma/migrations/20230817124452_/migration.sql b/prisma/migrations/20230817124452_/migration.sql deleted file mode 100644 index e556089..0000000 --- a/prisma/migrations/20230817124452_/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Problem" ADD COLUMN "uuid" VARCHAR(255) NOT NULL DEFAULT 'null'; diff --git a/prisma/migrations/20230818063054_/migration.sql b/prisma/migrations/20230818063054_/migration.sql deleted file mode 100644 index 1e80859..0000000 --- a/prisma/migrations/20230818063054_/migration.sql +++ /dev/null @@ -1,57 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `url` on the `TestCase` table. All the data in the column will be lost. - - You are about to drop the column `sshKey` on the `User` table. All the data in the column will be lost. - - You are about to drop the `HiddenCase` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `UserHiddenCase` table. If the table is not empty, all the data it contains will be lost. - - Added the required column `input` to the `TestCase` table without a default value. This is not possible if the table is not empty. - - Added the required column `isHidden` to the `TestCase` table without a default value. This is not possible if the table is not empty. - - Added the required column `output` to the `TestCase` table without a default value. This is not possible if the table is not empty. - -*/ --- CreateEnum -CREATE TYPE "TestcaseType" AS ENUM ('OPENED', 'HIDDEN'); - --- DropForeignKey -ALTER TABLE "HiddenCase" DROP CONSTRAINT "HiddenCase_problemId_fkey"; - --- DropForeignKey -ALTER TABLE "HiddenCase" DROP CONSTRAINT "HiddenCase_repoId_fkey"; - --- DropForeignKey -ALTER TABLE "UserHiddenCase" DROP CONSTRAINT "UserHiddenCase_hiddenCaseId_fkey"; - --- DropForeignKey -ALTER TABLE "UserHiddenCase" DROP CONSTRAINT "UserHiddenCase_userId_fkey"; - --- AlterTable -ALTER TABLE "TestCase" DROP COLUMN "url", -ADD COLUMN "input" TEXT NOT NULL, -ADD COLUMN "isHidden" "TestcaseType" NOT NULL, -ADD COLUMN "output" TEXT NOT NULL; - --- AlterTable -ALTER TABLE "User" DROP COLUMN "sshKey"; - --- DropTable -DROP TABLE "HiddenCase"; - --- DropTable -DROP TABLE "UserHiddenCase"; - --- CreateTable -CREATE TABLE "UserTestCase" ( - "id" SERIAL NOT NULL, - "isCorrect" BOOLEAN, - "userId" INTEGER NOT NULL, - "testCaseId" INTEGER NOT NULL, - - CONSTRAINT "UserTestCase_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_testCaseId_fkey" FOREIGN KEY ("testCaseId") REFERENCES "TestCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20230717115256_init/migration.sql b/prisma/migrations/20230818130322_/migration.sql similarity index 71% rename from prisma/migrations/20230717115256_init/migration.sql rename to prisma/migrations/20230818130322_/migration.sql index ab4eaf5..29d489a 100644 --- a/prisma/migrations/20230717115256_init/migration.sql +++ b/prisma/migrations/20230818130322_/migration.sql @@ -1,6 +1,9 @@ -- CreateEnum CREATE TYPE "Role" AS ENUM ('Tutor', 'Student'); +-- CreateEnum +CREATE TYPE "TestcaseType" AS ENUM ('OPENED', 'HIDDEN'); + -- CreateTable CREATE TABLE "User" ( "id" SERIAL NOT NULL, @@ -17,7 +20,6 @@ CREATE TABLE "User" ( CREATE TABLE "Repo" ( "id" SERIAL NOT NULL, "name" VARCHAR(255) NOT NULL, - "url" VARCHAR(255) NOT NULL, CONSTRAINT "Repo_pkey" PRIMARY KEY ("id") ); @@ -47,6 +49,7 @@ CREATE TABLE "Problem" ( "id" SERIAL NOT NULL, "title" VARCHAR(255) NOT NULL, "text" TEXT NOT NULL, + "uuid" VARCHAR(255) NOT NULL DEFAULT 'null', "repoId" INTEGER NOT NULL, CONSTRAINT "Problem_pkey" PRIMARY KEY ("id") @@ -57,19 +60,21 @@ CREATE TABLE "TestCase" ( "id" SERIAL NOT NULL, "input" TEXT NOT NULL, "output" TEXT NOT NULL, + "isHidden" "TestcaseType" NOT NULL, + "repoId" INTEGER NOT NULL, "problemId" INTEGER NOT NULL, CONSTRAINT "TestCase_pkey" PRIMARY KEY ("id") ); -- CreateTable -CREATE TABLE "HiddenCase" ( +CREATE TABLE "UserTestCase" ( "id" SERIAL NOT NULL, - "input" TEXT NOT NULL, - "output" TEXT NOT NULL, - "problemId" INTEGER NOT NULL, + "isCorrect" BOOLEAN, + "userId" INTEGER NOT NULL, + "testCaseId" INTEGER NOT NULL, - CONSTRAINT "HiddenCase_pkey" PRIMARY KEY ("id") + CONSTRAINT "UserTestCase_pkey" PRIMARY KEY ("id") ); -- CreateIndex @@ -78,6 +83,12 @@ CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); -- CreateIndex CREATE UNIQUE INDEX "User_nickname_key" ON "User"("nickname"); +-- CreateIndex +CREATE UNIQUE INDEX "Repo_name_key" ON "Repo"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "UserRepo_userId_repoId_key" ON "UserRepo"("userId", "repoId"); + -- AddForeignKey ALTER TABLE "UserRepo" ADD CONSTRAINT "UserRepo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; @@ -93,8 +104,14 @@ ALTER TABLE "Score" ADD CONSTRAINT "Score_problemId_fkey" FOREIGN KEY ("problemI -- AddForeignKey ALTER TABLE "Problem" ADD CONSTRAINT "Problem_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE; +-- AddForeignKey +ALTER TABLE "TestCase" ADD CONSTRAINT "TestCase_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE "TestCase" ADD CONSTRAINT "TestCase_problemId_fkey" FOREIGN KEY ("problemId") REFERENCES "Problem"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "HiddenCase" ADD CONSTRAINT "HiddenCase_problemId_fkey" FOREIGN KEY ("problemId") REFERENCES "Problem"("id") ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_testCaseId_fkey" FOREIGN KEY ("testCaseId") REFERENCES "TestCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/src/problem/problem.service.ts b/src/problem/problem.service.ts index 92bd037..0cd1306 100644 --- a/src/problem/problem.service.ts +++ b/src/problem/problem.service.ts @@ -63,6 +63,8 @@ export class ProblemService { } async isMemberOfRepo(userId: number, repoId: number): Promise { + console.log(userId, repoId) + const userRepo = await this.prisma.userRepo.findFirst({ where: { userId, diff --git a/src/repos/repos.controller.ts b/src/repos/repos.controller.ts index e93b7f6..ca20c6a 100644 --- a/src/repos/repos.controller.ts +++ b/src/repos/repos.controller.ts @@ -36,8 +36,14 @@ export class ReposController { @Roles(Role.Tutor) @Post() - async createRepo(@Body() createRepoDto: CreateRepoDto) { - const newRepo = await this.reposService.createNewRepo(createRepoDto) + async createRepo( + @Body() createRepoDto: CreateRepoDto, + @Req() req: AuthenticatedRequest + ) { + const newRepo = await this.reposService.createNewRepo( + createRepoDto, + req.user.userId + ) return new CommonResponseDto({ repoId: newRepo.id }) } diff --git a/src/repos/repos.service.ts b/src/repos/repos.service.ts index 60b719d..001bf24 100644 --- a/src/repos/repos.service.ts +++ b/src/repos/repos.service.ts @@ -33,7 +33,7 @@ export class ReposService { }) } - async createNewRepo(createRepoDto: CreateRepoDto) { + async createNewRepo(createRepoDto: CreateRepoDto, userId: number) { const repoName = createRepoDto.repoName.toLowerCase() const repoExist = await this.prismaService.repo.findFirst({ where: { @@ -49,7 +49,12 @@ export class ReposService { await this.minio.makeBucket(repoName) return await tx.repo.create({ data: { - name: repoName + name: repoName, + UserRepo: { + create: { + userId: userId + } + } } }) })