Skip to content

Commit

Permalink
return the template repository URL as a JSON object (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
reimer-atb authored Mar 1, 2023
1 parent cbef80f commit a0c1de0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ Example POST request: https://api.dev.smartclide.eu/architectural-patterns/appli

### Response

Content-Type: `text/plain`
The template repository URL on GitHub, e.g., `https://github.com/che-samples/web-java-spring-boot`

A repository URL on GitHub, e.g., `https://github.com/che-samples/web-java-spring-boot`
Content-Type: `application/json`

```json
{
"templateRepositoryUrl": "https://github.com/che-samples/web-java-spring-boot"
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

import java.util.Map;

@RestController
public class PatternApplicationController {
Expand All @@ -21,15 +23,15 @@ public PatternApplicationController(final ArchitecturalPatternsJsonHandler jsonH
this.projectJsonHandler = jsonHandler;
}

@PostMapping(value = "/application")
public String applyPattern(@RequestParam("framework") String framework,
@RequestParam("pattern") String pattern) {
@PostMapping(value = "/application", produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> applyPattern(@RequestParam("framework") String framework,
@RequestParam("pattern") String pattern) {
try {
String repoUrl = getProjectURL(framework, pattern);
if (repoUrl == null) {
throw new NullPointerException("Repository URL is not found.");
}
return repoUrl;
return Map.of("templateRepositoryUrl", repoUrl);
} catch (Exception e) {
logger.error("Exception during pattern application.", e);
throw new ResponseStatusException(
Expand Down

0 comments on commit a0c1de0

Please sign in to comment.