Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1165] Fix template endpoint content field #1166

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ alias(

fix_prettier(
name = "fix_prettier",
ignore = ":.prettierignore",
ignore = "//:.prettierignore",
)

multirun(
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# Airy Bazel tools
git_repository(
name = "com_github_airyhq_bazel_tools",
commit = "67692d45534663c18ad5d1061f367fab23a98415",
commit = "df21f28f7b7717c11c4e5a22e47955cedacea122",
remote = "https://github.com/airyhq/bazel-tools.git",
shallow_since = "1614184856 +0100",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
@RestController
public class TemplatesController {
private final Stores stores;
private final ObjectMapper objectMapper;
private final ObjectMapper objectMapper = new ObjectMapper();

public TemplatesController(Stores stores, ObjectMapper objectMapper) {
public TemplatesController(Stores stores) {
this.stores = stores;
this.objectMapper = objectMapper;
}

@PostMapping("/templates.create")
ResponseEntity<?> createTemplate(@RequestBody @Valid CreateTemplateRequestPayload payload) throws JsonProcessingException {
final Template template = Template.newBuilder()
.setId(UUID.randomUUID().toString())
.setName(payload.getName())
.setContent(payload.getContent())
.setContent(objectMapper.writeValueAsString(payload.getContent()))
.setVariables(objectMapper.writeValueAsString(payload.getVariables()))
.build();

Expand Down Expand Up @@ -100,7 +99,7 @@ ResponseEntity<?> updateTemplate(@RequestBody @Valid UpdateTemplateRequestPayloa
}

if (payload.getContent() != null) {
template.setContent(payload.getContent());
template.setContent(objectMapper.writeValueAsString(payload.getContent()));
}

if (payload.getVariables() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CreateTemplateRequestPayload {
@NotNull
private String name;
@NotNull
private String content;
private JsonNode content;
@Valid
@NotNull
private JsonNode variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class UpdateTemplateRequestPayload {
@NotNull
private UUID id;
private String name;
private String content;
private JsonNode content;
private JsonNode variables;
}
80 changes: 50 additions & 30 deletions docs/docs/api/endpoints/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ for more information.

**Sample request**

```json
```json5
{
"name": "my template name",
"content": "{\"blueprint\":\"text\",\"payload\":\"[[salutation]]!\"}",
"variables": {
"en": {
"salutation": "%s"
name: "my template name",
content: {
message: {
text: "[[salutation]]!"
}
},
// source specific message content
variables: {
en: {
salutation: "%s"
}
}
}
Expand All @@ -28,11 +33,11 @@ for more information.

```json5
{
"id": "TEMPLATE-UUID"
id: "TEMPLATE-UUID"
}
```

## List
## Listw

`POST /templates.list`

Expand All @@ -46,22 +51,27 @@ Find templates whose name contains "NASA":

```json5
{
"name": "NASA" //optional
name: "NASA" // optional
}
```

**Sample response**

```json5
{
"data": [
data: [
{
"id": "TEMPLATE-UUID",
"name": "Template for NASA",
"content": '{"blueprint":"text","payload":"[[salutation]]!"}',
"variables": {
"en": {
"salutation": "%s"
id: "TEMPLATE-UUID",
name: "Template for NASA",
content: {
message: {
text: "[[salutation]]!"
}
},
// source specific message content
variables: {
en: {
salutation: "%s"
}
}
}
Expand All @@ -75,20 +85,25 @@ Find templates whose name contains "NASA":

```json5
{
"id": "TEMPLATE-UUID"
id: "TEMPLATE-UUID"
}
```

**Sample response**

```json5
{
"id": "TEMPLATE-UUID",
"name": "{String}",
"content": "{String}",
"variables": {
"en": {
"salutation": "%s"
id: "TEMPLATE-UUID",
name: "{String}",
content: {
message: {
text: "[[salutation]]!"
}
},
// source specific message content
variables: {
en: {
salutation: "%s"
}
}
}
Expand All @@ -100,12 +115,17 @@ Find templates whose name contains "NASA":

```json5
{
"id": "template id",
"name": "my template name",
"content": '{"blueprint":"text","payload":"[[salutation]]!"}',
"variables": {
"en": {
"salutation": "%s"
id: "template id",
name: "my template name",
content: {
message: {
text: "[[salutation]]!"
}
},
// source specific message content
variables: {
en: {
salutation: "%s"
}
}
}
Expand All @@ -121,7 +141,7 @@ This endpoint returns _200_ if successful.

```json5
{
"id": "TEMPLATE-UUID"
id: "TEMPLATE-UUID"
}
```

Expand Down