Skip to content

Commit

Permalink
Merge pull request #84 from PhungThanhTu/feature/support-programming-…
Browse files Browse the repository at this point in the history
…lang

Feature/support programming lang
  • Loading branch information
PhungThanhTu authored Jul 23, 2023
2 parents e168fb0 + a7e7d8e commit 159ed3b
Show file tree
Hide file tree
Showing 30 changed files with 788 additions and 95 deletions.
54 changes: 1 addition & 53 deletions database/setup/00_createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,4 @@ create table Course
title nvarchar(max),
courseSubject nvarchar(max),
courseTheme nvarchar(max)
)
-- create table CourseExercise
-- (
-- courseId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Course](id),
-- exerciseId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Exercise](id),
-- title nvarchar(max),
-- document nvarchar(max)
-- )

-- create table Submission
-- (
-- id UNIQUEIDENTIFIER PRIMARY KEY,
-- exerciseId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Exercise](id) NOT NULL,
-- score float,
-- averageTime float,
-- averageMemory float,
-- timeCreated smalldatetime
-- )
-- create table SubmissionSourceCode
-- (
-- submissionId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Submission](id) NOT NULL,
-- programmingLanguageId int FOREIGN KEY REFERENCES [dbo].[ProgrammingLanguage](id) NOT NULL,
-- sourceCode nvarchar(max)
-- )
-- create table RunStatus (
-- id int primary key,
-- statusDescription nvarchar(50)
-- )
-- insert into [dbo].[RunStatus]
-- (id,statusDescription)
-- VALUES
-- (0,'Pending'),
-- (1,'Accepted'),
-- (2,'Wrong'),
-- (3,'Compliation Error'),
-- (4,'Runtime Error'),
-- (5,'Memory Limit Exceeded'),
-- (6,'Time Limit Exceeded'),
-- (7,'Others')

-- create table SubmissionTestResult
-- (
-- submissionId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Submission](id) NOT NULL,
-- testId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[MetaTestCase](id) NOT NULL,
-- programmingLanguageId int FOREIGN KEY REFERENCES [dbo].[ProgrammingLanguage](id) NOT NULL,
-- runTime float,
-- memoryUsage float,
-- runStatus int FOREIGN KEY REFERENCES [dbo].[RunStatus](id),
-- exitCode int,
-- actualStdout nvarchar(max),
-- stdErr nvarchar(max),
-- CONSTRAINT PK_SubmissionTestResult PRIMARY KEY(submissionId,testId,programmingLanguageId)
-- )
)
35 changes: 0 additions & 35 deletions database/setup/113_AddJavaScriptLanguage.sql

This file was deleted.

9 changes: 9 additions & 0 deletions database/setup/123_Table_UserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create table UserTestcase
(
Id int,
UserId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[PlpUser](id),
ExerciseId UNIQUEIDENTIFIER FOREIGN KEY REFERENCES [dbo].[Exercise](id) NOT NULL,
Input nvarchar(max),
ExpectedOutput nvarchar(max),
TestOrder int
)
5 changes: 5 additions & 0 deletions database/setup/124_GetFirstExerciseByDocumentId.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE PROCEDURE GetFirstExerciseByDocumentId
@DocumentId UNIQUEIDENTIFIER
AS
select * from [dbo].[DocumentExercise]
where DocumentId = @DocumentId
26 changes: 26 additions & 0 deletions database/setup/125_CreateUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
create procedure CreateUserTestcase
@Id INT,
@UserId UNIQUEIDENTIFIER,
@ExerciseId UNIQUEIDENTIFIER,
@Input nvarchar(max),
@ExpectedOutput nvarchar(max),
@TestOrder INT
AS
INSERT INTO [dbo].[UserTestcase]
(
Id,
UserId,
ExerciseId,
[Input],
ExpectedOutput,
TestOrder
)
VALUES
(
@Id,
@UserId,
@ExerciseId,
@Input,
@ExpectedOutput,
@TestOrder
)
15 changes: 15 additions & 0 deletions database/setup/126_GetAllUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE PROCEDURE GetAllUserTestcase
@UserId UNIQUEIDENTIFIER,
@ExerciseId UNIQUEIDENTIFIER
as
select
Id,
UserId,
ExerciseId,
[Input],
ExpectedOutput,
TestOrder
from [dbo].[UserTestcase]
where UserId = @UserId
and ExerciseId = @ExerciseId
ORDER BY TestOrder ASC
7 changes: 7 additions & 0 deletions database/setup/127_GetNewOrderUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create procedure GetNewOrderUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER
AS
select COALESCE(Max(TestOrder), 0) as TestOrder from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
8 changes: 8 additions & 0 deletions database/setup/128_GetMaxIdUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
create procedure GetMaxIdUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER
AS
select COALESCE(Max(Id), 0) as Id from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId

24 changes: 24 additions & 0 deletions database/setup/129_SwapOrderUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
create procedure SwapOrderUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@TestOrder1 INT,
@TestOrder2 INT
AS
declare @Id1 INT
declare @Id2 INT
select @Id1 = Id from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
and TestOrder = @TestOrder1
select @Id2 = Id from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
and TestOrder = @TestOrder2
update [dbo].[UserTestcase]
SET
TestOrder = @TestOrder1
WHERE Id = @Id2
update [dbo].[UserTestcase]
SET
TestOrder = @TestOrder2
where Id = @Id1
17 changes: 17 additions & 0 deletions database/setup/130_UpdateUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create procedure UpdateUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@Id INT,
@Input nvarchar(max) = NULL,
@ExpectedOutput nvarchar(max) = NULL,
@TestOrder INT
AS

update [dbo].[UserTestcase]
SET
[Input] = COALESCE(@Input, [Input]),
ExpectedOutput = COALESCE(@ExpectedOutput, ExpectedOutput),
TestOrder = COALESCE(@TestOrder, TestOrder)
WHERE ExerciseId = @ExerciseId
AND UserId = @UserId
AND Id = @Id
19 changes: 19 additions & 0 deletions database/setup/131_DeleteUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create procedure DeleteUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@Id INT
as
declare @CurrOrder INT
select @CurrOrder = TestOrder from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
and Id = @Id
delete from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
and Id = @Id
update [dbo].[UserTestcase]
set TestOrder = TestOrder - 1
where ExerciseId = @ExerciseId
and UserId = @UserId
and TestOrder > @CurrOrder
10 changes: 10 additions & 0 deletions database/setup/132_GetUserTestcase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create procedure GetUserTestcase
@ExerciseId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@Id INT
as
select TestOrder, Id, [Input], ExpectedOutput as [Output]
from [dbo].[UserTestcase]
where ExerciseId = @ExerciseId
and UserId = @UserId
and Id = @Id
9 changes: 9 additions & 0 deletions database/setup/133_AlterProc_DeleteSubmissionById.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
alter PROCEDURE DeleteSubmissionById
@SubmissionId UNIQUEIDENTIFIER
AS
DELETE FROM [dbo].[TestResult]
where SubmissionId = @SubmissionId
DELETE FROM [dbo].[SubmissionUser]
where SubmissionId = @SubmissionId
DELETE FROM [dbo].[Submission]
where Id = @SubmissionId
58 changes: 58 additions & 0 deletions database/setup/134_LanguageSupport.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
insert into [dbo].[ProgrammingLanguage]
(Id,LanguageName, DisplayName,FileExtension, NeedCompile, CompileCommand, RunCommand)
VALUES
(3,
'lua',
'Lua 5.4.4',
'lua',
'0',
'',
'/usr/local/bin/lua ./$FILENAME.$EXTENSION')

insert into [dbo].[ProgrammingLanguage]
(Id,LanguageName, DisplayName,FileExtension, NeedCompile, CompileCommand, RunCommand)
VALUES
(4,
'python',
'Python 3.10.11',
'py',
'0',
'',
'/usr/local/bin/python3.10 ./$FILENAME.$EXTENSION')

-- insert into [dbo].[ProgrammingLanguage]
-- (Id,LanguageName, DisplayName,FileExtension, NeedCompile, CompileCommand, RunCommand)
-- VALUES
-- (5,
-- 'rust',
-- 'Rust 1.71.0',
-- 'rs',
-- '1',
-- '/usr/local/bin/rustc linker=/usr/bin/cc $FILENAME.$EXTENSION',
-- './$FILENAME')

-- update [dbo].[ProgrammingLanguage]
-- set CompileCommand = '/usr/local/bin/rustc -C linker=/usr/bin/cc $FILENAME.$EXTENSION'
-- where Id = 5

insert into [dbo].[ProgrammingLanguage]
(Id,LanguageName, DisplayName,FileExtension, NeedCompile, CompileCommand, RunCommand)
values
(6,
'ruby',
'ruby 3.2.2',
'rb',
'0',
'',
'/usr/local/bin/ruby ./$FILENAME.$EXTENSION')

insert into [dbo].[ProgrammingLanguage]
(Id,LanguageName, DisplayName,FileExtension, NeedCompile, CompileCommand, RunCommand)
values
(7,
'javascript',
'node 16',
'js',
'0',
'',
'/usr/bin/node ./$FILENAME.$EXTENSION')
Loading

0 comments on commit 159ed3b

Please sign in to comment.