Skip to content

Commit 88263f6

Browse files
committed
feat(justifications): implement get
1 parent fc470c1 commit 88263f6

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

serverless.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ custom:
8686
contentType: application/json,
8787
schema: '${file(src/doges-on-trial/models/doge-images.json):post.response}',
8888
}
89+
- {
90+
name: GetJustificationsRequest,
91+
description: 'The request for getJustifications.',
92+
contentType: application/json,
93+
schema: '${file(src/court/models/justifications.json):get.request}',
94+
}
95+
- {
96+
name: GetJustificationsResponse,
97+
description: 'The response for getJustifications.',
98+
contentType: application/json,
99+
schema: '${file(src/court/models/justifications.json):get.response}',
100+
}
89101
- {
90102
name: PutJustificationsRequest,
91103
description: 'The request for putJustifications.',
@@ -230,6 +242,32 @@ functions:
230242
responseModels: { application/json: ErrorResponse },
231243
},
232244
]
245+
getJustifications:
246+
handler: src/court/justifications.get
247+
events:
248+
- { http: { path: justifications, method: post, cors: true } }
249+
iamRoleStatementsName: 'getJustifications-${self:provider.stage}-lambda-role'
250+
iamRoleStatements:
251+
- {
252+
Effect: Allow,
253+
Action: ['dynamodb:Query'],
254+
Resource: 'arn:aws:dynamodb:us-east-2:547511976516:table/justifications',
255+
}
256+
documentation:
257+
summary: 'Get justifications for a dispute round.'
258+
description: 'Get justifications for a dispute round.'
259+
requestModels: { application/json: GetJustificationsRequest }
260+
methodResponses:
261+
[
262+
{
263+
statusCode: '200',
264+
responseModels: { application/json: GetJustificationsResponse },
265+
},
266+
{
267+
statusCode: '400',
268+
responseModels: { application/json: ErrorResponse },
269+
},
270+
]
233271
putJustifications:
234272
handler: src/court/justifications.put
235273
events:

src/court/justifications.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ const _web3 = require('../utils/web3')
22
const KlerosLiquid = require('../assets/contracts/KlerosLiquid.json')
33
const dynamoDB = require('../utils/dynamo-db')
44

5+
module.exports.get = async (event, _context, callback) => {
6+
// Fetch justifications and return them
7+
const payload = JSON.parse(event.body).payload
8+
callback(null, {
9+
statusCode: 200,
10+
headers: { 'Access-Control-Allow-Origin': '*' },
11+
body: JSON.stringify({
12+
payload: {
13+
justifications: await dynamoDB.query({
14+
ExpressionAttributeValues: {
15+
':disputeIDAndAppeal': {
16+
S: `${payload.disputeID}-${payload.appeal}`
17+
}
18+
},
19+
KeyConditionExpression: 'disputeIDAndAppeal = :disputeIDAndAppeal',
20+
TableName: 'justifications'
21+
})
22+
}
23+
})
24+
})
25+
}
26+
527
module.exports.put = async (event, _context, callback) => {
628
// Initialize web3 and contracts
729
const web3 = await _web3()

src/court/models/justifications.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
{
2+
"get": {
3+
"request": {
4+
"type": "object",
5+
"properties": {
6+
"payload": {
7+
"type": "object",
8+
"properties": {
9+
"disputeID": {
10+
"type": "number",
11+
"description": "The ID of the dispute the votes are cast for."
12+
},
13+
"appeal": {
14+
"type": "number",
15+
"description": "The appeal of the dispute the votes are cast for."
16+
}
17+
}
18+
}
19+
}
20+
},
21+
"response": {
22+
"type": "object",
23+
"properties": {
24+
"payload": {
25+
"type": "object",
26+
"properties": {
27+
"justifications": {
28+
"type": "object",
29+
"description": "The justifications query response."
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
236
"put": {
337
"request": {
438
"type": "object",

src/utils/dynamo-db.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ const dynamoDB = new DynamoDB({ apiVersion: '2012-08-10', region: 'us-east-2' })
66
dynamoDB.getItem = promisify(dynamoDB.getItem)
77
dynamoDB.putItem = promisify(dynamoDB.putItem)
88
dynamoDB.updateItem = promisify(dynamoDB.updateItem)
9+
dynamoDB.query = promisify(dynamoDB.query)
910

1011
module.exports = dynamoDB

0 commit comments

Comments
 (0)