Skip to content

Commit 2700bca

Browse files
committed
re-added metadata on assignment-problem
1 parent 0a23a30 commit 2700bca

18 files changed

+189
-38
lines changed

devU-api/src/entities/assignment/assignment.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ async function processFiles(req: Request) {
114114
} else {
115115
console.warn(`Files where not in array format ${req.files}`)
116116
}
117-
} else {
118-
console.warn(`No files where processed`)
119117
}
120118

121119
return { fileHashes, fileNames }

devU-api/src/entities/assignmentProblem/assignmentProblem.controller.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Request, Response, NextFunction } from 'express'
1+
import { NextFunction, Request, Response } from 'express'
22

33
import AssignmentProblemService from './assignmentProblem.service'
44

@@ -33,15 +33,21 @@ export async function detail(req: Request, res: Response, next: NextFunction) {
3333
}
3434
}
3535

36-
export async function post(req: Request, res: Response, next: NextFunction) {
36+
export async function post(req: Request, res: Response, _: NextFunction) {
3737
try {
38-
const assignmentProblem = await AssignmentProblemService.create(req.body)
38+
req.body.assignmentId = parseInt(req.params.assignmentId)
39+
const assignmentProblem = await AssignmentProblemService.create(
40+
req.body.assignmentId,
41+
req.body.problemName,
42+
req.body.maxScore,
43+
req.body.metadata,
44+
)
3945
const response = serialize(assignmentProblem)
4046

4147
res.status(201).json(response)
4248
} catch (err) {
4349
if (err instanceof Error) {
44-
res.status(400).json(new GenericResponse(err.message))
50+
res.status(400).json(new GenericResponse(err.message))
4551
}
4652
}
4753
}

devU-api/src/entities/assignmentProblem/assignmentProblem.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export default class AssignmentProblemModel {
2828
* type: integer
2929
* problemName:
3030
* type: string
31+
* metadata:
32+
* type: string
33+
* description: A json string containing additional problem metadata
3134
* maxScore:
3235
* type: integer
3336
*/
@@ -43,6 +46,9 @@ export default class AssignmentProblemModel {
4346
@Column({ name: 'problem_name', length: 128 })
4447
problemName: string
4548

49+
@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
50+
metadata: any // use any since this can be any arbitrary structure
51+
4652
@Column({ name: 'max_score' })
4753
maxScore: number
4854

devU-api/src/entities/assignmentProblem/assignmentProblem.router.ts

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ const Router = express.Router({ mergeParams: true })
2121
* responses:
2222
* '200':
2323
* description: OK
24+
* content:
25+
* application/json:
26+
* schema:
27+
* type: array
28+
* items:
29+
* type: object
30+
* properties:
31+
* id:
32+
* type: integer
33+
* assignmentId:
34+
* type: integer
35+
* problemName:
36+
* type: string
37+
* metadata:
38+
* type: string
39+
* description: A json string containing additional problem metadata
40+
* maxScore:
41+
* type: integer
2442
* parameters:
2543
* - name: assignmentId
2644
* description: Enter Assignment Id
@@ -43,6 +61,22 @@ Router.get('/', isAuthorized('enrolled'), AssignmentProblemController.get)
4361
* responses:
4462
* '200':
4563
* description: OK
64+
* content:
65+
* application/json:
66+
* schema:
67+
* type: object
68+
* properties:
69+
* id:
70+
* type: integer
71+
* assignmentId:
72+
* type: integer
73+
* problemName:
74+
* type: string
75+
* metadata:
76+
* type: string
77+
* description: A json string containing additional problem metadata
78+
* maxScore:
79+
* type: integer
4680
* parameters:
4781
* - name: id
4882
* description: Enter AssignmentProblem Id
@@ -63,8 +97,33 @@ Router.get('/:id', isAuthorized('assignmentEditAll'), asInt(), AssignmentProblem
6397
* tags:
6498
* - AssignmentProblems
6599
* responses:
66-
* '200':
67-
* description: OK
100+
* '201':
101+
* description: Created
102+
* content:
103+
* application/json:
104+
* schema:
105+
* type: object
106+
* properties:
107+
* id:
108+
* type: integer
109+
* assignmentId:
110+
* type: integer
111+
* problemName:
112+
* type: string
113+
* metadata:
114+
* type: string
115+
* description: A json string containing additional problem metadata
116+
* maxScore:
117+
* type: integer
118+
* '400':
119+
* description: Bad Request
120+
* content:
121+
* application/json:
122+
* schema:
123+
* type: object
124+
* properties:
125+
* message:
126+
* type: string
68127
* requestBody:
69128
* content:
70129
* application/x-www-form-urlencoded:
@@ -75,14 +134,37 @@ Router.post('/', isAuthorized('assignmentEditAll'), validator, AssignmentProblem
75134

76135
/**
77136
* @swagger
78-
* /course/:courseId/assignment/:assignmentId/assignment-problems:
137+
* /course/:courseId/assignment/:assignmentId/assignment-problems/{id}:
79138
* put:
80139
* summary: Update an assignment problem
81140
* tags:
82141
* - AssignmentProblems
83142
* responses:
84143
* '200':
85144
* description: OK
145+
* content:
146+
* application/json:
147+
* schema:
148+
* type: object
149+
* properties:
150+
* message:
151+
* type: string
152+
* '404':
153+
* description: Not Found
154+
* content:
155+
* application/json:
156+
* schema:
157+
* type: object
158+
* properties:
159+
* message:
160+
* type: string
161+
* parameters:
162+
* - name: id
163+
* description: Enter AssignmentProblem Id
164+
* in: path
165+
* required: true
166+
* schema:
167+
* type: integer
86168
* requestBody:
87169
* content:
88170
* application/x-www-form-urlencoded:

devU-api/src/entities/assignmentProblem/assignmentProblem.serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function serialize(assignmentProblem: AssignmentProblemModel): Assignment
88
assignmentId: assignmentProblem.assignmentId,
99
problemName: assignmentProblem.problemName,
1010
maxScore: assignmentProblem.maxScore,
11+
metadata: assignmentProblem.metadata,
1112
createdAt: assignmentProblem.createdAt.toISOString(),
1213
updatedAt: assignmentProblem.updatedAt.toISOString(),
1314
}

devU-api/src/entities/assignmentProblem/assignmentProblem.service.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import { AssignmentProblem } from 'devu-shared-modules'
77

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

10-
export async function create(assignmentProblem: AssignmentProblem) {
11-
return await connect().save(assignmentProblem)
12-
}
13-
1410
export async function update(assignmentProblem: AssignmentProblem) {
1511
const { id, assignmentId, problemName, maxScore } = assignmentProblem
1612
if (!id) throw new Error('Missing Id')
@@ -30,10 +26,26 @@ export async function list(assignmentId: number) {
3026
return await connect().findBy({ assignmentId: assignmentId, deletedAt: IsNull() })
3127
}
3228

29+
export async function create(
30+
assignmentId: number,
31+
problemName: string,
32+
maxScore: number,
33+
metadata?: any,
34+
) {
35+
const assignmentProblem = <AssignmentProblemModel>{
36+
assignmentId: assignmentId,
37+
problemName: problemName,
38+
maxScore: maxScore,
39+
metadata: metadata,
40+
}
41+
42+
return await connect().save(assignmentProblem)
43+
}
44+
3345
export default {
34-
create,
3546
retrieve,
3647
update,
3748
_delete,
3849
list,
50+
create,
3951
}

devU-api/src/entities/assignmentProblem/assignmentProblem.validator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import validate from '../../middleware/validator/generic.validator'
55
const assignmentId = check('assignmentId').isNumeric()
66
const problemName = check('problemName').isString().trim().isLength({ max: 128 })
77
const maxScore = check('maxScore').isNumeric()
8+
const metadata = check('metadata')
9+
.optional({ nullable: true })
10+
.isObject()
11+
.default({})
812

9-
const validator = [assignmentId, problemName, maxScore, validate]
13+
const validator = [assignmentId, problemName, maxScore, metadata, validate]
1014

1115
export default validator

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ export async function detail(req: Request, res: Response, next: NextFunction) {
4242

4343
export async function post(req: Request, res: Response, next: NextFunction) {
4444
try {
45-
const nonContainer = await NonContainerAutoGraderService.create(req.body)
45+
req.body.assignmentId = parseInt(req.params.assignmentId)
46+
const nonContainer = await NonContainerAutoGraderService.create(
47+
req.body.assignmentId,
48+
req.body.question,
49+
req.body.score,
50+
req.body.isRegex,
51+
req.body.correctString
52+
)
4653
const response = serialize(nonContainer)
4754

4855
res.status(201).json(response)

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.model.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export default class NonContainerAutoGraderModel {
2727
* type: integer
2828
* question:
2929
* type: string
30-
* metadata:
31-
* type: any
32-
* description: this contains a valid json string tha contains info about any arbitrary question type (MCQ, Fill in the blanks etc.)
3330
* score:
3431
* type: number
3532
* correctString:
@@ -56,9 +53,6 @@ export default class NonContainerAutoGraderModel {
5653
@Column({ name: 'question', length: 128 })
5754
question: string
5855

59-
@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
60-
metadata: any // use any since this can be any arbitrary structure
61-
6256
@Column({ name: 'score' })
6357
score: number
6458

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.serializer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export function serialize(nonContainerAutoGrader: NonContainerAutoGraderModel):
88
assignmentId: nonContainerAutoGrader.assignmentId,
99
question: nonContainerAutoGrader.question,
1010
score: nonContainerAutoGrader.score,
11-
metadata: JSON.stringify(nonContainerAutoGrader.metadata ?? ''),
12-
correctString: nonContainerAutoGrader.correctString,
1311
isRegex: nonContainerAutoGrader.isRegex,
12+
correctString: nonContainerAutoGrader.correctString,
1413
createdAt: nonContainerAutoGrader.createdAt.toISOString(),
1514
updatedAt: nonContainerAutoGrader.updatedAt.toISOString(),
1615
}

0 commit comments

Comments
 (0)