Skip to content

Commit 2004b5e

Browse files
CCM-11226 Skeleton for PATCH /letter/{id} (#98)
1 parent a4779df commit 2004b5e

File tree

11 files changed

+395
-11
lines changed

11 files changed

+395
-11
lines changed

docs/Gemfile.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ GEM
2727
erb (4.0.4)
2828
cgi (>= 0.3.3)
2929
eventmachine (1.2.7)
30+
ffi (1.17.2-aarch64-linux-gnu)
3031
ffi (1.17.2-arm64-darwin)
3132
ffi (1.17.2-x86_64-linux-gnu)
3233
forwardable-extended (2.6.0)
3334
gemoji (4.1.0)
35+
google-protobuf (4.31.1-aarch64-linux-gnu)
36+
bigdecimal
37+
rake (>= 13)
3438
google-protobuf (4.31.1-arm64-darwin)
3539
bigdecimal
3640
rake (>= 13)
@@ -101,8 +105,9 @@ GEM
101105
jekyll-seo-tag (~> 2.1)
102106
minitest (5.24.1)
103107
mutex_m (0.2.0)
104-
nokogiri (1.18.9-arm64-darwin)
108+
nokogiri (1.18.4-aarch64-linux-gnu)
105109
racc (~> 1.4)
110+
nokogiri (1.18.9-arm64-darwin)
106111
nokogiri (1.18.9-x86_64-linux-gnu)
107112
racc (~> 1.4)
108113
pathutil (0.16.2)
@@ -116,6 +121,8 @@ GEM
116121
rexml (3.4.1)
117122
rouge (4.5.2)
118123
safe_yaml (1.0.5)
124+
sass-embedded (1.83.0-aarch64-linux-gnu)
125+
google-protobuf (~> 4.28)
119126
sass-embedded (1.83.0-arm64-darwin)
120127
google-protobuf (~> 4.28)
121128
sass-embedded (1.83.0-x86_64-linux-gnu)
@@ -128,6 +135,7 @@ GEM
128135
webrick (1.8.2)
129136

130137
PLATFORMS
138+
aarch64-linux
131139
arm64-darwin-23
132140
x86_64-linux
133141

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ No requirements.
3030
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3131
| <a name="module_hello_world"></a> [hello\_world](#module\_hello\_world) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3232
| <a name="module_kms"></a> [kms](#module\_kms) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v2.0.10 |
33+
| <a name="module_patch_letters"></a> [patch\_letters](#module\_patch\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3334
## Outputs
3435

3536
| Name | Description |

infrastructure/terraform/components/api/iam_role_api_gateway_execution_role.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
5151
module.authorizer_lambda.function_arn,
5252
module.hello_world.function_arn,
5353
module.get_letters.function_arn,
54+
module.patch_letters.function_arn
5455
]
5556
}
5657
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ locals {
1010
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
1111
HELLO_WORLD_LAMBDA_ARN = module.hello_world.function_arn
1212
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13+
PATCH_LETTERS_LAMBDA_ARN = module.patch_letters.function_arn
1314
})
1415

1516
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module "patch_letters" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.10"
3+
4+
function_name = "patch_letters"
5+
description = "Update the status of a letter"
6+
7+
aws_account_id = var.aws_account_id
8+
component = var.component
9+
environment = var.environment
10+
project = var.project
11+
region = var.region
12+
13+
group = var.group
14+
15+
log_retention_in_days = var.log_retention_in_days
16+
kms_key_arn = module.kms.key_arn
17+
18+
iam_policy_document = {
19+
body = data.aws_iam_policy_document.patch_letters_lambda.json
20+
}
21+
22+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
23+
function_code_base_path = local.aws_lambda_functions_dir_path
24+
function_code_dir = "api-handler/dist"
25+
function_include_common = true
26+
handler_function_name = "patchLetters"
27+
runtime = "nodejs22.x"
28+
memory = 128
29+
timeout = 5
30+
log_level = var.log_level
31+
32+
force_lambda_code_deploy = var.force_lambda_code_deploy
33+
enable_lambda_insights = false
34+
35+
send_to_firehose = true
36+
log_destination_arn = local.destination_arn
37+
log_subscription_role_arn = local.acct.log_subscription_role_arn
38+
39+
lambda_env_vars = {
40+
}
41+
}
42+
43+
data "aws_iam_policy_document" "patch_letters_lambda" {
44+
statement {
45+
sid = "KMSPermissions"
46+
effect = "Allow"
47+
48+
actions = [
49+
"kms:Decrypt",
50+
"kms:GenerateDataKey",
51+
]
52+
53+
resources = [
54+
module.kms.key_arn, ## Requires shared kms module
55+
]
56+
}
57+
}

infrastructure/terraform/components/api/resources/spec.tmpl.json

Lines changed: 158 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
},
2424
"openapi": "3.0.1",
2525
"paths": {
26-
"/": {
26+
"/letters": {
2727
"get": {
28-
"description": "Returns 200 OK if the API is up.",
28+
"description": "Returns 200 OK with paginated letter ids.",
2929
"responses": {
3030
"200": {
3131
"description": "OK"
@@ -36,7 +36,7 @@
3636
"LambdaAuthorizer": []
3737
}
3838
],
39-
"summary": "Health check",
39+
"summary": "Get letters",
4040
"x-amazon-apigateway-integration": {
4141
"contentHandling": "CONVERT_TO_TEXT",
4242
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
@@ -49,24 +49,172 @@
4949
},
5050
"timeoutInMillis": 29000,
5151
"type": "AWS_PROXY",
52-
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${HELLO_WORLD_LAMBDA_ARN}/invocations"
52+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_LETTERS_LAMBDA_ARN}/invocations"
5353
}
5454
}
5555
},
56-
"/letters": {
57-
"get": {
58-
"description": "Returns 200 OK with paginated letter ids.",
56+
"/letters/{id}": {
57+
"parameters": [
58+
{
59+
"description": "Unique identifier of this resource",
60+
"in": "path",
61+
"name": "id",
62+
"required": true,
63+
"schema": {
64+
"type": "string"
65+
}
66+
}
67+
],
68+
"patch": {
69+
"description": "Update the status of a letter by providing the new status in the request body.",
70+
"requestBody": {
71+
"content": {
72+
"application/vnd.api+json": {
73+
"schema": {
74+
"properties": {
75+
"data": {
76+
"properties": {
77+
"attributes": {
78+
"properties": {
79+
"reasonCode": {
80+
"description": "Reason code for the given status",
81+
"type": "number"
82+
},
83+
"reasonText": {
84+
"description": "Reason text for the given status",
85+
"type": "string"
86+
},
87+
"requestedProductionStatus": {
88+
"description": "The requested production status for this letter.\nMay only be set by NHS Notify.",
89+
"enum": [
90+
"ACTIVE",
91+
"HOLD",
92+
"CANCEL"
93+
],
94+
"title": "ProductionStatus",
95+
"type": "string"
96+
},
97+
"status": {
98+
"default": "PENDING",
99+
"description": "The supplier status of an individual letter",
100+
"enum": [
101+
"PENDING",
102+
"ACCEPTED",
103+
"REJECTED",
104+
"PRINTED",
105+
"ENCLOSED",
106+
"CANCELLED",
107+
"DISPATCHED",
108+
"FAILED",
109+
"RETURNED",
110+
"DESTROYED",
111+
"FORWARDED"
112+
],
113+
"type": "string"
114+
}
115+
},
116+
"type": "object"
117+
},
118+
"id": {
119+
"type": "string"
120+
},
121+
"type": {
122+
"const": "Letter",
123+
"type": "string"
124+
}
125+
},
126+
"type": "object"
127+
}
128+
},
129+
"type": "object"
130+
}
131+
}
132+
},
133+
"required": true
134+
},
59135
"responses": {
60136
"200": {
61-
"description": "OK"
137+
"content": {
138+
"application/vnd.api+json": {
139+
"schema": {
140+
"properties": {
141+
"data": {
142+
"properties": {
143+
"attributes": {
144+
"properties": {
145+
"reasonCode": {
146+
"description": "Reason code for the given status",
147+
"type": "number"
148+
},
149+
"reasonText": {
150+
"description": "Reason text for the given status",
151+
"type": "string"
152+
},
153+
"requestedProductionStatus": {
154+
"description": "A requested status for the production of a letter",
155+
"enum": [
156+
"ACTIVE",
157+
"HOLD",
158+
"CANCEL"
159+
],
160+
"title": "ProductionStatus",
161+
"type": "string"
162+
},
163+
"status": {
164+
"default": "PENDING",
165+
"description": "The supplier status of an individual letter",
166+
"enum": [
167+
"PENDING",
168+
"ACCEPTED",
169+
"REJECTED",
170+
"PRINTED",
171+
"ENCLOSED",
172+
"CANCELLED",
173+
"DISPATCHED",
174+
"FAILED",
175+
"RETURNED",
176+
"DESTROYED",
177+
"FORWARDED"
178+
],
179+
"type": "string"
180+
}
181+
},
182+
"required": [
183+
"status",
184+
"requestedProductionStatus"
185+
],
186+
"type": "object"
187+
},
188+
"id": {
189+
"type": "string"
190+
},
191+
"type": {
192+
"const": "Letter",
193+
"type": "string"
194+
}
195+
},
196+
"type": "object"
197+
}
198+
},
199+
"type": "object"
200+
}
201+
}
202+
},
203+
"description": "Letter resource updated successfully"
204+
},
205+
"400": {
206+
"description": "Bad request"
207+
},
208+
"404": {
209+
"description": "Resource not found"
62210
}
63211
},
64212
"security": [
65213
{
66214
"LambdaAuthorizer": []
67215
}
68216
],
69-
"summary": "Get letters",
217+
"summary": "Update the status of a letter",
70218
"x-amazon-apigateway-integration": {
71219
"contentHandling": "CONVERT_TO_TEXT",
72220
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
@@ -79,7 +227,7 @@
79227
},
80228
"timeoutInMillis": 29000,
81229
"type": "AWS_PROXY",
82-
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_LETTERS_LAMBDA_ARN}/invocations"
230+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${PATCH_LETTERS_LAMBDA_ARN}/invocations"
83231
}
84232
}
85233
}

0 commit comments

Comments
 (0)