diff --git a/.vscode/cspell-templates.txt b/.vscode/cspell-templates.txt index 6d280d7c2af..e40f3e9caa1 100644 --- a/.vscode/cspell-templates.txt +++ b/.vscode/cspell-templates.txt @@ -20,6 +20,7 @@ eastus envconfig ezfunc fasterxml +hubspot immer inprogress INPROGRESS diff --git a/templates/todo/api/common/openapi.yaml b/templates/todo/api/common/openapi.yaml index b5d1f18cced..0aca8700c0f 100644 --- a/templates/todo/api/common/openapi.yaml +++ b/templates/todo/api/common/openapi.yaml @@ -62,7 +62,7 @@ components: in: path required: true name: itemId - description: The Todo list unique identifier + description: The Todo item unique identifier schema: type: string state: @@ -79,6 +79,7 @@ components: description: The max number of items to returns in a result schema: type: number + default: 20 skip: in: query required: false @@ -86,6 +87,7 @@ components: description: The number of items to skip within the results schema: type: number + default: 0 requestBodies: TodoList: @@ -179,6 +181,8 @@ paths: responses: 200: $ref: "#/components/responses/TodoList" + 404: + description: Todo list not found 400: description: Todo list is invalid delete: @@ -288,6 +292,7 @@ paths: tags: - Items requestBody: + description: unique identifiers of the Todo items to update content: application/json: schema: diff --git a/templates/todo/api/java/.openapi-generator/FILES b/templates/todo/api/java/.openapi-generator/FILES index 726c90a1f19..1596b4b1b10 100644 --- a/templates/todo/api/java/.openapi-generator/FILES +++ b/templates/todo/api/java/.openapi-generator/FILES @@ -1,4 +1,5 @@ src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java +src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java diff --git a/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 b/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 index 4bf5f74fc3c..59b3d7fcc12 100644 --- a/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 +++ b/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 @@ -1 +1 @@ -1e0347e24b739d303f3af0493d1e730e4ac47a27fdac1e8a151defcc745496f0 \ No newline at end of file +baa1ff1c1daf16544c5985f4e1240a6d5611af0bb2d5f4bf5b631de8d53a9e70 \ No newline at end of file diff --git a/templates/todo/api/java/package-lock.json b/templates/todo/api/java/package-lock.json new file mode 100644 index 00000000000..d09fa5f415e --- /dev/null +++ b/templates/todo/api/java/package-lock.json @@ -0,0 +1,116 @@ +{ + "name": "java", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier-plugin-java": "^1.6.2" + } + }, + "node_modules/chevrotain": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-6.5.0.tgz", + "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", + "dev": true, + "dependencies": { + "regexp-to-ast": "0.4.0" + } + }, + "node_modules/java-parser": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/java-parser/-/java-parser-2.0.2.tgz", + "integrity": "sha512-fwv1eDYE4OIAN+XS7cD8aB7UdQyAh3Uz36ydWqemvnDKXEdLbxq7qIbvsjpSvS1NHFR+r81N7AjGcpnamjVxJw==", + "dev": true, + "dependencies": { + "chevrotain": "6.5.0", + "lodash": "4.17.21" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, + "node_modules/prettier": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.1.tgz", + "integrity": "sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/prettier-plugin-java": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-java/-/prettier-plugin-java-1.6.2.tgz", + "integrity": "sha512-oVIUOkx50eb9skdRtEIU7MJUsizQ1ZocgXR1w1o8AnieNGpuPI/2pWnpjtbBm9wUG1dHtBGU8cVIr8h+xgzQIg==", + "dev": true, + "dependencies": { + "java-parser": "2.0.2", + "lodash": "4.17.21", + "prettier": "2.3.1" + } + }, + "node_modules/regexp-to-ast": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", + "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", + "dev": true + } + }, + "dependencies": { + "chevrotain": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-6.5.0.tgz", + "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", + "dev": true, + "requires": { + "regexp-to-ast": "0.4.0" + } + }, + "java-parser": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/java-parser/-/java-parser-2.0.2.tgz", + "integrity": "sha512-fwv1eDYE4OIAN+XS7cD8aB7UdQyAh3Uz36ydWqemvnDKXEdLbxq7qIbvsjpSvS1NHFR+r81N7AjGcpnamjVxJw==", + "dev": true, + "requires": { + "chevrotain": "6.5.0", + "lodash": "4.17.21" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, + "prettier": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.1.tgz", + "integrity": "sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==", + "dev": true + }, + "prettier-plugin-java": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-java/-/prettier-plugin-java-1.6.2.tgz", + "integrity": "sha512-oVIUOkx50eb9skdRtEIU7MJUsizQ1ZocgXR1w1o8AnieNGpuPI/2pWnpjtbBm9wUG1dHtBGU8cVIr8h+xgzQIg==", + "dev": true, + "requires": { + "java-parser": "2.0.2", + "lodash": "4.17.21", + "prettier": "2.3.1" + } + }, + "regexp-to-ast": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", + "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", + "dev": true + } + } +} diff --git a/templates/todo/api/java/package.json b/templates/todo/api/java/package.json new file mode 100644 index 00000000000..b1607b07643 --- /dev/null +++ b/templates/todo/api/java/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "prettier-plugin-java": "^1.6.2" + } +} diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index f24a89c9654..b9047ab1ce0 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -18,6 +18,11 @@ ${java.version} ${java.version} 1.6.11 + + write @@ -105,6 +110,27 @@ + + com.hubspot.maven.plugins + prettier-maven-plugin + 0.16 + + 1.5.0 + 125 + 4 + false + true + true + + + + validate + + ${plugin.prettier.goal} + + + + @@ -134,11 +160,24 @@ false true true + true + + com.hubspot.maven.plugins + prettier-maven-plugin + + + compile + + ${plugin.prettier.goal} + + + + diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java index 18f6d0bcfd1..1549d3d3049 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java @@ -1,10 +1,9 @@ package com.microsoft.azure.simpletodo; +import com.microsoft.applicationinsights.attach.ApplicationInsights; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.microsoft.applicationinsights.attach.ApplicationInsights; - @SpringBootApplication public class SimpleTodoApplication { diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java index bcdbd2577c0..cbcc964b124 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java @@ -1,11 +1,11 @@ package com.microsoft.azure.simpletodo.api; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import org.springframework.web.context.request.NativeWebRequest; public class ApiUtil { + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { try { HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java new file mode 100644 index 00000000000..8e006fed20f --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java @@ -0,0 +1,364 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.1). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package com.microsoft.azure.simpletodo.api; + +import com.microsoft.azure.simpletodo.model.TodoItem; +import com.microsoft.azure.simpletodo.model.TodoState; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.math.BigDecimal; +import java.util.List; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "Items", description = "the Items API") +public interface ItemsApi { + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /lists/{listId}/items : Creates a new Todo item within a list + * + * @param listId The Todo list unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 201) + * or Todo list not found (status code 404) + */ + @Operation( + operationId = "createItem", + summary = "Creates a new Todo item within a list", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "201", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/lists/{listId}/items", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity createItem( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return Todo item deleted successfully (status code 204) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "deleteItemById", + summary = "Deletes a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}/items/{itemId}") + default ResponseEntity deleteItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return A Todo item result (status code 200) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "getItemById", + summary = "Gets a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/{itemId}", produces = { "application/json" }) + default ResponseEntity getItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * GET /lists/{listId}/items : Gets Todo items within the specified list + * + * @param listId The Todo list unique identifier (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) + * or Todo list not found (status code 404) + */ + @Operation( + operationId = "getItemsByListId", + summary = "Gets Todo items within the specified list", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "An array of Todo items", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items", produces = { "application/json" }) + default ResponseEntity> getItemsByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state + * + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "getItemsByListIdAndState", + summary = "Gets a list of Todo items of a specific state", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "An array of Todo items", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/lists/{listId}/items/state/{state}", + produces = { "application/json" } + ) + default ResponseEntity> getItemsByListIdAndState( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable( + "state" + ) TodoState state, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 200) + * or Todo item is invalid (status code 400) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "updateItemById", + summary = "Updates a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "400", description = "Todo item is invalid"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/{itemId}", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity updateItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items + * + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param requestBody unique identifiers of the Todo items to update (optional) + * @return Todo items updated (status code 204) + * or Update request is invalid (status code 400) + */ + @Operation( + operationId = "updateItemsStateByListId", + summary = "Changes the state of the specified list items", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "204", description = "Todo items updated"), + @ApiResponse(responseCode = "400", description = "Update request is invalid"), + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/state/{state}", + consumes = { "application/json" } + ) + default ResponseEntity updateItemsStateByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable( + "state" + ) TodoState state, + @Parameter( + name = "request_body", + description = "unique identifiers of the Todo items to update" + ) @Valid @RequestBody(required = false) List requestBody + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java index dcc1795e412..73104e8897b 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java @@ -5,11 +5,7 @@ */ package com.microsoft.azure.simpletodo.api; -import java.math.BigDecimal; -import java.util.List; -import com.microsoft.azure.simpletodo.model.TodoItem; import com.microsoft.azure.simpletodo.model.TodoList; -import com.microsoft.azure.simpletodo.model.TodoState; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -18,6 +14,13 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; +import javax.validation.Valid; +import javax.validation.constraints.*; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -26,65 +29,14 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import javax.validation.Valid; -import javax.validation.constraints.*; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated -@Tag(name = "lists", description = "the lists API") +@Tag(name = "Lists", description = "the Lists API") public interface ListsApi { - default Optional getRequest() { return Optional.empty(); } - /** - * POST /lists/{listId}/items : Creates a new Todo item within a list - * - * @param listId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 201) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "createItem", - summary = "Creates a new Todo item within a list", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.POST, - value = "/lists/{listId}/items", - produces = { "application/json" }, - consumes = { "application/json" } - ) - default ResponseEntity createItem( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * POST /lists : Creates a new Todo list * @@ -97,10 +49,12 @@ default ResponseEntity createItem( summary = "Creates a new Todo list", tags = { "Lists" }, responses = { - @ApiResponse(responseCode = "201", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "400", description = "Invalid request schema") + @ApiResponse( + responseCode = "201", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "400", description = "Invalid request schema"), } ) @RequestMapping( @@ -112,50 +66,19 @@ default ResponseEntity createItem( default ResponseEntity createList( @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @return Todo item deleted successfully (status code 204) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "deleteItemById", - summary = "Deletes a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.DELETE, - value = "/lists/{listId}/items/{itemId}" - ) - default ResponseEntity deleteItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId - ) { + }); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - /** * DELETE /lists/{listId} : Deletes a Todo list by unique identifier * @@ -169,153 +92,18 @@ default ResponseEntity deleteItemById( tags = { "Lists" }, responses = { @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list not found") + @ApiResponse(responseCode = "404", description = "Todo list not found"), } ) - @RequestMapping( - method = RequestMethod.DELETE, - value = "/lists/{listId}" - ) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}") default ResponseEntity deleteListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId ) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - /** - * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @return A Todo item result (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemById", - summary = "Gets a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" } - ) - default ResponseEntity getItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists/{listId}/items : Gets Todo items within the specified list - * - * @param listId The Todo list unique identifier (required) - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) - * @return An array of Todo items (status code 200) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "getItemsByListId", - summary = "Gets Todo items within the specified list", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items", - produces = { "application/json" } - ) - default ResponseEntity> getItemsByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) - * @return An array of Todo items (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemsByListIdAndState", - summary = "Gets a list of Todo items of a specific state", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/state/{state}", - produces = { "application/json" } - ) - default ResponseEntity> getItemsByListIdAndState( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * GET /lists/{listId} : Gets a Todo list by unique identifier * @@ -328,39 +116,38 @@ default ResponseEntity> getItemsByListIdAndState( summary = "Gets a Todo list by unique identifier", tags = { "Lists" }, responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") + @ApiResponse( + responseCode = "200", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), } ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}", - produces = { "application/json" } - ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}", produces = { "application/json" }) default ResponseEntity getListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } } - } - }); + }); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - /** * GET /lists : Gets an array of Todo lists * - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) * @return An array of Todo lists (status code 200) */ @Operation( @@ -368,120 +155,46 @@ default ResponseEntity getListById( summary = "Gets an array of Todo lists", tags = { "Lists" }, responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo lists", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }) + @ApiResponse( + responseCode = "200", + description = "An array of Todo lists", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), } ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists", - produces = { "application/json" } - ) + @RequestMapping(method = RequestMethod.GET, value = "/lists", produces = { "application/json" }) default ResponseEntity> getLists( - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } } - } - }); + }); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - - /** - * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 200) - * or Todo item is invalid (status code 400) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "updateItemById", - summary = "Updates a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "400", description = "Todo item is invalid"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" }, - consumes = { "application/json" } - ) - default ResponseEntity updateItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param requestBody (optional) - * @return Todo items updated (status code 204) - * or Update request is invalid (status code 400) - */ - @Operation( - operationId = "updateItemsStateByListId", - summary = "Changes the state of the specified list items", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "204", description = "Todo items updated"), - @ApiResponse(responseCode = "400", description = "Update request is invalid") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/state/{state}", - consumes = { "application/json" } - ) - default ResponseEntity updateItemsStateByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "request_body", description = "") @Valid @RequestBody(required = false) List requestBody - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * PUT /lists/{listId} : Updates a Todo list by unique identifier * * @param listId The Todo list unique identifier (required) * @param todoList The Todo List (optional) * @return A Todo list result (status code 200) + * or Todo list not found (status code 404) * or Todo list is invalid (status code 400) */ @Operation( @@ -489,10 +202,13 @@ default ResponseEntity updateItemsStateByListId( summary = "Updates a Todo list by unique identifier", tags = { "Lists" }, responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "400", description = "Todo list is invalid") + @ApiResponse( + responseCode = "200", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + @ApiResponse(responseCode = "400", description = "Todo list is invalid"), } ) @RequestMapping( @@ -502,20 +218,21 @@ default ResponseEntity updateItemsStateByListId( consumes = { "application/json" } ) default ResponseEntity updateListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } } - } - }); + }); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java index a47d5eb92fe..2932eb3c1f0 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java @@ -14,10 +14,9 @@ public class MongoDBConfiguration { @Bean public MongoCustomConversions mongoCustomConversions() { - return new MongoCustomConversions(Arrays.asList( - new OffsetDateTimeReadConverter(), - new OffsetDateTimeWriteConverter() - )); + return new MongoCustomConversions( + Arrays.asList(new OffsetDateTimeReadConverter(), new OffsetDateTimeWriteConverter()) + ); } static class OffsetDateTimeWriteConverter implements Converter { diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java index 06754ffab41..49d09b27ea1 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java @@ -1,7 +1,6 @@ package com.microsoft.azure.simpletodo.configuration; import com.fasterxml.jackson.databind.util.StdDateFormat; - import java.text.DateFormat; import java.text.FieldPosition; import java.text.ParsePosition; @@ -10,12 +9,12 @@ import java.util.TimeZone; public class RFC3339DateFormat extends DateFormat { + private static final long serialVersionUID = 1L; + private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); - private final StdDateFormat fmt = new StdDateFormat() - .withTimeZone(TIMEZONE_Z) - .withColonInTimeZone(true); + private final StdDateFormat fmt = new StdDateFormat().withTimeZone(TIMEZONE_Z).withColonInTimeZone(true); public RFC3339DateFormat() { this.calendar = new GregorianCalendar(); diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java new file mode 100644 index 00000000000..4a521df9604 --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +package com.microsoft.azure.simpletodo.configuration; + +import com.microsoft.azure.simpletodo.model.TodoState; +import org.springframework.core.convert.converter.Converter; + +public class StringToTodoStateConverter implements Converter { + + @Override + public TodoState convert(String source) { + return TodoState.fromValue(source); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java index 191fa0b6d82..855a4c38e09 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java @@ -2,22 +2,26 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -public class WebConfiguration { +public class WebConfiguration implements WebMvcConfigurer { + + @Override + public void addFormatters(FormatterRegistry registry) { + // spring can not convert string "todo" to enum `TodoState.TODO` by itself without + // this converter. + registry.addConverter(new StringToTodoStateConverter()); + } @Bean public WebMvcConfigurer webConfigurer() { return new WebMvcConfigurer() { - @Override public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOrigins("*") - .allowedMethods("*") - .allowedHeaders("*"); + registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*"); } }; } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java new file mode 100644 index 00000000000..028cb92f71d --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +package com.microsoft.azure.simpletodo.controller; + +import com.microsoft.azure.simpletodo.api.ItemsApi; +import com.microsoft.azure.simpletodo.model.TodoItem; +import com.microsoft.azure.simpletodo.model.TodoList; +import com.microsoft.azure.simpletodo.model.TodoState; +import com.microsoft.azure.simpletodo.repository.TodoItemRepository; +import com.microsoft.azure.simpletodo.repository.TodoListRepository; +import java.math.BigDecimal; +import java.net.URI; +import java.util.List; +import java.util.Optional; +import java.util.stream.StreamSupport; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +@RestController +public class TodoItemsController implements ItemsApi { + + private final TodoListRepository todoListRepository; + + private final TodoItemRepository todoItemRepository; + + public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { + this.todoListRepository = todoListRepository; + this.todoItemRepository = todoItemRepository; + } + + public ResponseEntity createItem(String listId, TodoItem todoItem) { + final Optional optionalTodoList = todoListRepository.findById(listId); + if (optionalTodoList.isPresent()) { + todoItem.setListId(listId); + final TodoItem savedTodoItem = todoItemRepository.save(todoItem); + final URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoItem.getId()) + .toUri(); + return ResponseEntity.created(location).body(savedTodoItem); + } else { + return ResponseEntity.notFound().build(); + } + } + + public ResponseEntity deleteItemById(String listId, String itemId) { + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) + .map(i -> ResponseEntity.noContent().build()) + .orElse(ResponseEntity.notFound().build()); + } + + public ResponseEntity getItemById(String listId, String itemId) { + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository + .findById(listId) + .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { + // make sure listId and itemId are set into the todoItem, otherwise it will create + // a new todo item. + todoItem.setId(itemId); + todoItem.setListId(listId); + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(t -> todoItemRepository.save(todoItem)) + .map(ResponseEntity::ok) // return the saved item. + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getItemsByListIdAndState( + String listId, + TodoState state, + BigDecimal top, + BigDecimal skip + ) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository + .findById(listId) + .map(l -> + todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), skip.intValue(), top.intValue()) + ) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { + // update all items in list with the given state if `itemIds` is not specified. + final List items = Optional + .ofNullable(itemIds) + .filter(ids -> !CollectionUtils.isEmpty(ids)) + .map(ids -> + StreamSupport + .stream(todoItemRepository.findAllById(ids).spliterator(), false) + .filter(i -> listId.equalsIgnoreCase(i.getListId())) + .toList() + ) + .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); + items.forEach(item -> item.setState(state)); + todoItemRepository.saveAll(items); // save items in batch. + return ResponseEntity.noContent().build(); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java new file mode 100644 index 00000000000..1a5c661721e --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -0,0 +1,62 @@ +package com.microsoft.azure.simpletodo.controller; + +import com.microsoft.azure.simpletodo.api.ListsApi; +import com.microsoft.azure.simpletodo.model.TodoList; +import com.microsoft.azure.simpletodo.repository.TodoListRepository; +import java.math.BigDecimal; +import java.net.URI; +import java.util.List; +import javax.validation.constraints.NotNull; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +@RestController +public class TodoListsController implements ListsApi { + + private final TodoListRepository todoListRepository; + + public TodoListsController(TodoListRepository todoListRepository) { + this.todoListRepository = todoListRepository; + } + + public ResponseEntity createList(TodoList todoList) { + final TodoList savedTodoList = todoListRepository.save(todoList); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoList.getId()) + .toUri(); + return ResponseEntity.created(location).body(savedTodoList); + } + + public ResponseEntity deleteListById(String listId) { + return todoListRepository + .findById(listId) + .map(l -> todoListRepository.deleteTodoListById(l.getId())) + .map(l -> ResponseEntity.noContent().build()) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity getListById(String listId) { + return todoListRepository + .findById(listId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); + } + + public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { + // make sure listId is set into the todoItem, otherwise it will create a new todo + // list. + todoList.setId(listId); + return todoListRepository + .findById(listId) + .map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) + .orElseGet(() -> ResponseEntity.notFound().build()); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 92bc02fff1a..61dbc74e5b2 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -1,21 +1,13 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.microsoft.azure.simpletodo.model.TodoState; -import java.time.OffsetDateTime; -import org.springframework.format.annotation.DateTimeFormat; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; - - -import java.util.*; +import java.time.OffsetDateTime; +import java.util.Objects; import javax.annotation.Generated; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import org.springframework.format.annotation.DateTimeFormat; /** * A task that needs to be completed @@ -25,209 +17,163 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @JsonProperty("id") - private String id; - - @JsonProperty("listId") - private String listId; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - @JsonProperty("state") - private TodoState state; - - @JsonProperty("dueDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime dueDate; - - @JsonProperty("completedDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime completedDate; - - public TodoItem id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TodoItem listId(String listId) { - this.listId = listId; - return this; - } - - /** - * Get listId - * @return listId - */ - @NotNull - @Schema(name = "listId", required = true) - public String getListId() { - return listId; - } - - public void setListId(String listId) { - this.listId = listId; - } - - public TodoItem name(String name) { - this.name = name; - return this; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TodoItem description(String description) { - this.description = description; - return this; - } - - /** - * Get description - * @return description - */ - @NotNull - @Schema(name = "description", required = true) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public TodoItem state(TodoState state) { - this.state = state; - return this; - } - - /** - * Get state - * @return state - */ - @Valid - @Schema(name = "state", required = false) - public TodoState getState() { - return state; - } - - public void setState(TodoState state) { - this.state = state; - } - - public TodoItem dueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - return this; - } - - /** - * Get dueDate - * @return dueDate - */ - @Valid - @Schema(name = "dueDate", required = false) - public OffsetDateTime getDueDate() { - return dueDate; - } - - public void setDueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - } - - public TodoItem completedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - return this; - } - - /** - * Get completedDate - * @return completedDate - */ - @Valid - @Schema(name = "completedDate", required = false) - public OffsetDateTime getCompletedDate() { - return completedDate; - } - - public void setCompletedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TodoItem todoItem = (TodoItem) o; - return Objects.equals(this.id, todoItem.id) && - Objects.equals(this.listId, todoItem.listId) && - Objects.equals(this.name, todoItem.name) && - Objects.equals(this.description, todoItem.description) && - Objects.equals(this.state, todoItem.state) && - Objects.equals(this.dueDate, todoItem.dueDate) && - Objects.equals(this.completedDate, todoItem.completedDate); - } - - @Override - public int hashCode() { - return Objects.hash(id, listId, name, description, state, dueDate, completedDate); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TodoItem {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" listId: ").append(toIndentedString(listId)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append(" state: ").append(toIndentedString(state)).append("\n"); - sb.append(" dueDate: ").append(toIndentedString(dueDate)).append("\n"); - sb.append(" completedDate: ").append(toIndentedString(completedDate)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} + @JsonProperty("id") + private String id; + + @JsonProperty("listId") + private String listId; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("state") + private TodoState state; + + @JsonProperty("dueDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime dueDate; + + @JsonProperty("completedDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime completedDate; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get listId + * @return listId + */ + @NotNull + @Schema(name = "listId", required = true) + public String getListId() { + return listId; + } + + public void setListId(String listId) { + this.listId = listId; + } + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + @NotNull + @Schema(name = "description", required = true) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * Get state + * @return state + */ + @Valid + @Schema(name = "state", required = false) + public TodoState getState() { + return state; + } + + public void setState(TodoState state) { + this.state = state; + } + + /** + * Get dueDate + * @return dueDate + */ + @Valid + @Schema(name = "dueDate", required = false) + public OffsetDateTime getDueDate() { + return dueDate; + } + + public void setDueDate(OffsetDateTime dueDate) { + this.dueDate = dueDate; + } + + /** + * Get completedDate + * @return completedDate + */ + @Valid + @Schema(name = "completedDate", required = false) + public OffsetDateTime getCompletedDate() { + return completedDate; + } + + public void setCompletedDate(OffsetDateTime completedDate) { + this.completedDate = completedDate; + } + + public boolean equals(final Object o) { + // items are equal if they have the same `listId` and `id` + if (o == this) return true; + if (!(o instanceof TodoItem)) return false; + final TodoItem other = (TodoItem) o; + if (!((Object) this instanceof TodoItem)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$listId = this.getListId(); + final Object other$listId = other.getListId(); + if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.listId, this.id); + } + + public String toString() { + return ( + "TodoItem(id=" + + this.getId() + + ", listId=" + + this.getListId() + + ", name=" + + this.getName() + + ", description=" + + this.getDescription() + + ", state=" + + this.getState() + + ", dueDate=" + + this.getDueDate() + + ", completedDate=" + + this.getCompletedDate() + + ")" + ); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index e667387d99b..19925fb56da 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -1,132 +1,87 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; - - -import java.util.*; +import java.util.Objects; import javax.annotation.Generated; +import javax.validation.constraints.NotNull; /** - * A list of related Todo items + * A list of related Todo items */ @Schema(name = "TodoList", description = " A list of related Todo items") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @JsonProperty("id") - private String id; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - public TodoList id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TodoList name(String name) { - this.name = name; - return this; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TodoList description(String description) { - this.description = description; - return this; - } - - /** - * Get description - * @return description - */ - - @Schema(name = "description", required = false) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; } - if (o == null || getClass() != o.getClass()) { - return false; + + public void setId(String id) { + this.id = id; } - TodoList todoList = (TodoList) o; - return Objects.equals(this.id, todoList.id) && - Objects.equals(this.name, todoList.name) && - Objects.equals(this.description, todoList.description); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, description); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TodoList {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; + + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + + @Schema(name = "description", required = false) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; } - return o.toString().replace("\n", "\n "); - } -} + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof TodoList)) return false; + final TodoList other = (TodoList) o; + if (!((Object) this instanceof TodoList)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + // lists are equal if they have the same id + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.getId()); + } + + public String toString() { + return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ")"; + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java index 773481722e2..c26fd86f824 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java @@ -1,20 +1,8 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; -import com.fasterxml.jackson.annotation.JsonValue; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; -import io.swagger.v3.oas.annotations.media.Schema; - - -import java.util.*; -import javax.annotation.Generated; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; +import javax.annotation.Generated; /** * Gets or Sets TodoState @@ -22,37 +10,35 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public enum TodoState { - - TODO("todo"), - - INPROGRESS("inprogress"), - - DONE("done"); - - private String value; - - TodoState(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - - @JsonCreator - public static TodoState fromValue(String value) { - for (TodoState b : TodoState.values()) { - if (b.value.equals(value)) { - return b; - } + TODO("todo"), + + INPROGRESS("inprogress"), + + DONE("done"); + + private String value; + + TodoState(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; } - throw new IllegalArgumentException("Unexpected value '" + value + "'"); - } -} + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static TodoState fromValue(String value) { + for (TodoState b : TodoState.values()) { + if (b.value.equalsIgnoreCase(value)) { // ignore case + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java index b32b1320832..1d374ff0d09 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java @@ -1,29 +1,21 @@ package com.microsoft.azure.simpletodo.repository; +import com.microsoft.azure.simpletodo.model.TodoItem; import java.util.List; - +import java.util.Optional; import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; -import org.springframework.data.mongodb.repository.Query; - -import com.microsoft.azure.simpletodo.model.TodoItem; public interface TodoItemRepository extends MongoRepository { + TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); + + List findTodoItemsByListId(String listId); - @Query("{ 'listId' : ?0 }") - List findTodoItemsByTodoList(String listId); + Optional findTodoItemByListIdAndId(String listId, String id); - @Aggregation(pipeline = { - "{ '$match': { 'listId' : ?0 } }", - "{ '$skip': ?1 }", - "{ '$limit': ?2 }", - }) + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0 } }", "{ '$skip': ?1 }", "{ '$limit': ?2 }" }) List findTodoItemsByTodoList(String listId, int skip, int limit); - @Aggregation(pipeline = { - "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", - "{ '$skip': ?2 }", - "{ '$limit': ?3 }", - }) + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", "{ '$skip': ?2 }", "{ '$limit': ?3 }" }) List findTodoItemsByTodoListAndState(String listId, String state, int skip, int limit); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java index 5b9a7202ebb..5dcc2b70eef 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java @@ -1,16 +1,13 @@ package com.microsoft.azure.simpletodo.repository; import com.microsoft.azure.simpletodo.model.TodoList; - import java.util.List; - import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; public interface TodoListRepository extends MongoRepository { - @Aggregation(pipeline = { - "{ '$skip': ?0 }", - "{ '$limit': ?1 }", - }) + @Aggregation(pipeline = { "{ '$skip': ?0 }", "{ '$limit': ?1 }" }) List findAll(int skip, int limit); + + TodoList deleteTodoListById(String id); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java deleted file mode 100644 index b4f2e10a69b..00000000000 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.microsoft.azure.simpletodo.web; - -import com.microsoft.azure.simpletodo.api.ListsApi; -import com.microsoft.azure.simpletodo.model.TodoItem; -import com.microsoft.azure.simpletodo.model.TodoList; -import com.microsoft.azure.simpletodo.model.TodoState; -import com.microsoft.azure.simpletodo.repository.TodoItemRepository; -import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -import java.math.BigDecimal; -import java.net.URI; -import java.util.List; -import java.util.Optional; - -@RestController -public class TodoListsController implements ListsApi { - - private final TodoListRepository todoListRepository; - - private final TodoItemRepository todoItemRepository; - - public TodoListsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { - this.todoListRepository = todoListRepository; - this.todoItemRepository = todoItemRepository; - } - - @Override - public ResponseEntity createItem(String listId, TodoItem todoItem) { - Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isPresent()) { - todoItem.setListId(listId); - TodoItem savedTodoItem = todoItemRepository.save(todoItem); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoItem.getId()) - .toUri(); - return ResponseEntity.created(location).body(savedTodoItem); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity createList(TodoList todoList) { - TodoList savedTodoList = todoListRepository.save(todoList); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoList.getId()) - .toUri(); - return ResponseEntity.created(location).body(savedTodoList); - } - - @Override - public ResponseEntity deleteItemById(String listId, String itemId) { - Optional todoItem = getTodoItem(listId, itemId); - if (todoItem.isPresent()) { - todoItemRepository.deleteById(itemId); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity deleteListById(String listId) { - Optional todoList = todoListRepository.findById(listId); - if (todoList.isPresent()) { - todoListRepository.deleteById(listId); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity getItemById(String listId, String itemId) { - return getTodoItem(listId, itemId).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); - } - - @Override - public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } - Optional todoList = todoListRepository.findById(listId); - if (todoList.isPresent()) { - return ResponseEntity.ok(todoItemRepository.findTodoItemsByTodoList(listId, skip.intValue(), top.intValue())); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } - return ResponseEntity.ok( - todoItemRepository - .findTodoItemsByTodoListAndState(listId, state.name(), skip.intValue(), top.intValue())); - } - - @Override - public ResponseEntity getListById(String listId) { - return todoListRepository.findById(listId).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); - } - - @Override - public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } - return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); - } - - @Override - public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { - return getTodoItem(listId, itemId).map(t -> { - todoItemRepository.save(todoItem); - return ResponseEntity.ok(todoItem); - }).orElseGet(() -> ResponseEntity.notFound().build()); - } - - @Override - public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List requestBody) { - for (TodoItem todoItem : todoItemRepository.findTodoItemsByTodoList(listId)) { - todoItem.state(state); - todoItemRepository.save(todoItem); - } - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } - - @Override - public ResponseEntity updateListById(String listId, TodoList todoList) { - return todoListRepository - .findById(listId) - .map(t -> ResponseEntity.ok(todoListRepository.save(t))) - .orElseGet(() -> ResponseEntity.badRequest().build()); - } - - private Optional getTodoItem(String listId, String itemId) { - Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isEmpty()) { - return Optional.empty(); - } - Optional optionalTodoItem = todoItemRepository.findById(itemId); - if (optionalTodoItem.isPresent()) { - TodoItem todoItem = optionalTodoItem.get(); - if (todoItem.getListId().equals(listId)) { - return Optional.of(todoItem); - } else { - return Optional.empty(); - } - } else { - return Optional.empty(); - } - } -} diff --git a/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java b/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java index 7e373c79969..8970dee090a 100644 --- a/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java +++ b/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class SimpleTodoApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} }