Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions devU-api/src/entities/assignment/assignment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ async function processFiles(req: Request) {
} else {
console.warn(`Files where not in array format ${req.files}`)
}
} else {
console.warn(`No files where processed`)
}

return { fileHashes, fileNames }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response, NextFunction } from 'express'
import { NextFunction, Request, Response } from 'express'

import AssignmentProblemService from './assignmentProblem.service'

Expand Down Expand Up @@ -33,15 +33,21 @@ export async function detail(req: Request, res: Response, next: NextFunction) {
}
}

export async function post(req: Request, res: Response, next: NextFunction) {
export async function post(req: Request, res: Response, _: NextFunction) {
try {
const assignmentProblem = await AssignmentProblemService.create(req.body)
req.body.assignmentId = parseInt(req.params.assignmentId)
const assignmentProblem = await AssignmentProblemService.create(
req.body.assignmentId,
req.body.problemName,
req.body.maxScore,
req.body.metadata,
)
const response = serialize(assignmentProblem)

res.status(201).json(response)
} catch (err) {
if (err instanceof Error) {
res.status(400).json(new GenericResponse(err.message))
res.status(400).json(new GenericResponse(err.message))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class AssignmentProblemModel {
* type: integer
* problemName:
* type: string
* metadata:
* type: string
* description: A json string containing additional problem metadata
* maxScore:
* type: integer
*/
Expand All @@ -43,6 +46,9 @@ export default class AssignmentProblemModel {
@Column({ name: 'problem_name', length: 128 })
problemName: string

@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
metadata: any // use any since this can be any arbitrary structure

@Column({ name: 'max_score' })
maxScore: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ const Router = express.Router({ mergeParams: true })
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* id:
* type: integer
* assignmentId:
* type: integer
* problemName:
* type: string
* metadata:
* type: string
* description: A json string containing additional problem metadata
* maxScore:
* type: integer
* parameters:
* - name: assignmentId
* description: Enter Assignment Id
Expand All @@ -43,6 +61,22 @@ Router.get('/', isAuthorized('enrolled'), AssignmentProblemController.get)
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: integer
* assignmentId:
* type: integer
* problemName:
* type: string
* metadata:
* type: string
* description: A json string containing additional problem metadata
* maxScore:
* type: integer
* parameters:
* - name: id
* description: Enter AssignmentProblem Id
Expand All @@ -63,8 +97,33 @@ Router.get('/:id', isAuthorized('assignmentEditAll'), asInt(), AssignmentProblem
* tags:
* - AssignmentProblems
* responses:
* '200':
* description: OK
* '201':
* description: Created
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: integer
* assignmentId:
* type: integer
* problemName:
* type: string
* metadata:
* type: string
* description: A json string containing additional problem metadata
* maxScore:
* type: integer
* '400':
* description: Bad Request
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* requestBody:
* content:
* application/x-www-form-urlencoded:
Expand All @@ -75,14 +134,37 @@ Router.post('/', isAuthorized('assignmentEditAll'), validator, AssignmentProblem

/**
* @swagger
* /course/:courseId/assignment/:assignmentId/assignment-problems:
* /course/:courseId/assignment/:assignmentId/assignment-problems/{id}:
* put:
* summary: Update an assignment problem
* tags:
* - AssignmentProblems
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* '404':
* description: Not Found
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* parameters:
* - name: id
* description: Enter AssignmentProblem Id
* in: path
* required: true
* schema:
* type: integer
* requestBody:
* content:
* application/x-www-form-urlencoded:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function serialize(assignmentProblem: AssignmentProblemModel): Assignment
assignmentId: assignmentProblem.assignmentId,
problemName: assignmentProblem.problemName,
maxScore: assignmentProblem.maxScore,
metadata: assignmentProblem.metadata,
createdAt: assignmentProblem.createdAt.toISOString(),
updatedAt: assignmentProblem.updatedAt.toISOString(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { AssignmentProblem } from 'devu-shared-modules'

const connect = () => dataSource.getRepository(AssignmentProblemModel)

export async function create(assignmentProblem: AssignmentProblem) {
return await connect().save(assignmentProblem)
}

export async function update(assignmentProblem: AssignmentProblem) {
const { id, assignmentId, problemName, maxScore } = assignmentProblem
if (!id) throw new Error('Missing Id')
Expand All @@ -30,10 +26,26 @@ export async function list(assignmentId: number) {
return await connect().findBy({ assignmentId: assignmentId, deletedAt: IsNull() })
}

export async function create(
assignmentId: number,
problemName: string,
maxScore: number,
metadata?: any,
) {
const assignmentProblem = <AssignmentProblemModel>{
assignmentId: assignmentId,
problemName: problemName,
maxScore: maxScore,
metadata: metadata,
}

return await connect().save(assignmentProblem)
}

export default {
create,
retrieve,
update,
_delete,
list,
create,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import validate from '../../middleware/validator/generic.validator'
const assignmentId = check('assignmentId').isNumeric()
const problemName = check('problemName').isString().trim().isLength({ max: 128 })
const maxScore = check('maxScore').isNumeric()
const metadata = check('metadata')
.optional({ nullable: true })
.isObject()
.default({})

const validator = [assignmentId, problemName, maxScore, validate]
const validator = [assignmentId, problemName, maxScore, metadata, validate]

export default validator
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export async function detail(req: Request, res: Response, next: NextFunction) {

export async function post(req: Request, res: Response, next: NextFunction) {
try {
const nonContainer = await NonContainerAutoGraderService.create(req.body)
req.body.assignmentId = parseInt(req.params.assignmentId)
const nonContainer = await NonContainerAutoGraderService.create(
req.body.assignmentId,
req.body.question,
req.body.score,
req.body.isRegex,
req.body.correctString
)
const response = serialize(nonContainer)

res.status(201).json(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export default class NonContainerAutoGraderModel {
* type: integer
* question:
* type: string
* metadata:
* type: any
* description: this contains a valid json string tha contains info about any arbitrary question type (MCQ, Fill in the blanks etc.)
* score:
* type: number
* correctString:
Expand All @@ -56,9 +53,6 @@ export default class NonContainerAutoGraderModel {
@Column({ name: 'question', length: 128 })
question: string

@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
metadata: any // use any since this can be any arbitrary structure

@Column({ name: 'score' })
score: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export function serialize(nonContainerAutoGrader: NonContainerAutoGraderModel):
assignmentId: nonContainerAutoGrader.assignmentId,
question: nonContainerAutoGrader.question,
score: nonContainerAutoGrader.score,
metadata: JSON.stringify(nonContainerAutoGrader.metadata ?? ''),
correctString: nonContainerAutoGrader.correctString,
isRegex: nonContainerAutoGrader.isRegex,
correctString: nonContainerAutoGrader.correctString,
createdAt: nonContainerAutoGrader.createdAt.toISOString(),
updatedAt: nonContainerAutoGrader.updatedAt.toISOString(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ import { NonContainerAutoGrader } from 'devu-shared-modules'

const connect = () => dataSource.getRepository(NonContainerAutoGraderModel)

export async function create(nonContainerQuestion: NonContainerAutoGrader) {
return await connect().save(nonContainerQuestion)
export async function create(
assignmentId: number,
question: string,
score: number,
isRegex: boolean,
correctString: string,
) {
const nonContainerAutoGrader = <NonContainerAutoGraderModel>{
assignmentId: assignmentId,
question: question,
score: score,
isRegex: isRegex,
correctString: correctString,
}

return await connect().save(nonContainerAutoGrader)
}

export async function update(nonContainerQuestion: NonContainerAutoGrader) {
Expand Down
10 changes: 5 additions & 5 deletions devU-api/src/fileUpload/fileUpload.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export default class FileModel {
@DeleteDateColumn({ name: 'deleted_at' })
deletedAt?: Date

@Column({ name: 'etag' })
@Column({ name: 'etag', default: "" })
etag: string

@Column({ name: 'name' })
@Column({ name: 'name' , default: ""})
name: string

@Column({ name: 'type' })
@Column({ name: 'type' , default: ""})
type: string

@Column({ name: 'filename', length: 128 })
@Column({ name: 'filename', length: 128 , default: ""})
filename: string

@Column({ name: 'bucket', length: 64 })
@Column({ name: 'bucket', length: 64 , default: ""})
fieldName: string

@Column({ name: 'course_id' })
Expand Down
6 changes: 3 additions & 3 deletions devU-api/src/migration/1743395416522-updateCag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export class UpdateCag1743395416522 implements MigrationInterface {
await queryRunner.query(`ALTER TABLE "container_auto_grader" DROP COLUMN "makefile_filename"`);
await queryRunner.query(`ALTER TABLE "container_auto_grader" DROP COLUMN "autograding_image"`);
await queryRunner.query(`ALTER TABLE "container_auto_grader" DROP COLUMN "grader_filename"`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "etag" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "name" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "type" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "etag" character varying NOT NULL DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "name" character varying NOT NULL DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ADD "type" character varying NOT NULL DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "container_auto_grader" ADD "dockerfile_id" character varying(512) NOT NULL`);
await queryRunner.query(`ALTER TABLE "container_auto_grader" ADD "job_file_ids" jsonb NOT NULL DEFAULT '[]'`);
await queryRunner.query(`ALTER TABLE "container_auto_grader" ADD "timeout_in_seconds" integer NOT NULL`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MoveMetadataToAssignmentProblem1743961277791 implements MigrationInterface {
name = 'MoveMetadataToAssignmentProblem1743961277791'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "nonContainerAutoGrader" DROP COLUMN "metadata"`);
await queryRunner.query(`ALTER TABLE "assignment_problems" ADD "metadata" jsonb DEFAULT '{}'`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "etag" SET DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "name" SET DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "type" SET DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "filename" SET DEFAULT ''`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "bucket" SET DEFAULT ''`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "bucket" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "filename" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "type" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "name" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "FilesAuth" ALTER COLUMN "etag" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "assignment_problems" DROP COLUMN "metadata"`);
await queryRunner.query(`ALTER TABLE "nonContainerAutoGrader" ADD "metadata" jsonb DEFAULT '{}'`);
}

}
Loading