-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created catalog microservice demo based on Spring Boot
- Loading branch information
Showing
14 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.glassfish.javaeetutorial</groupId> | ||
<artifactId>dukes-forest</artifactId> | ||
<version>7.0.6-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>catalog-microservice</artifactId> | ||
<name>Catalog microservice</name> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>1.2.2.RELEASE</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-undertow</artifactId> | ||
<version>1.2.2.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.javaeetutorial</groupId> | ||
<artifactId>usecases-catalog</artifactId> | ||
<version>7.0.6-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jsondoc</groupId> | ||
<artifactId>spring-boot-starter-jsondoc</artifactId> | ||
<version>1.1.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jsondoc</groupId> | ||
<artifactId>jsondoc-ui-webjar</artifactId> | ||
<version>1.1.12</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<!-- Package as an executable jar --> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
|
||
</project> |
17 changes: 17 additions & 0 deletions
17
catalog-microservice/src/main/java/com/forest/micro/catalog/CatalogApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.forest.micro.catalog; | ||
|
||
import org.jsondoc.spring.boot.starter.EnableJSONDoc; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
@EnableAutoConfiguration | ||
@ComponentScan | ||
@EnableJSONDoc | ||
public class CatalogApp { | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(CatalogApp.class, args); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
catalog-microservice/src/main/java/com/forest/micro/catalog/CategoryEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.forest.micro.catalog; | ||
|
||
import java.util.List; | ||
|
||
import org.jsondoc.core.annotation.Api; | ||
import org.jsondoc.core.annotation.ApiAuthNone; | ||
import org.jsondoc.core.annotation.ApiBodyObject; | ||
import org.jsondoc.core.annotation.ApiMethod; | ||
import org.jsondoc.core.annotation.ApiPathParam; | ||
import org.jsondoc.core.annotation.ApiResponseObject; | ||
import org.jsondoc.core.annotation.ApiVersion; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.forest.micro.catalog.model.CategoryObject; | ||
import com.forest.micro.catalog.wiring.CategoryManager; | ||
import com.forest.model.Category; | ||
|
||
@RestController | ||
@Api(name = "Category", description = "Methods for managing categories") | ||
@ApiVersion(since = "1.0") | ||
@ApiAuthNone | ||
public class CategoryEndpoint { | ||
|
||
private CategoryManager categoryManager; | ||
|
||
@Autowired | ||
public CategoryEndpoint(CategoryManager categoryManager) { | ||
this.categoryManager = categoryManager; | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Get a list of all categories") | ||
@ApiResponseObject | ||
@RequestMapping("/cetegories") | ||
List<Category> getCategories() { | ||
return categoryManager.getAll(); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Returns a caregory with given id") | ||
@ApiResponseObject | ||
@RequestMapping(value = "/category/{id}", produces = "application/json") | ||
CategoryObject getCategory( | ||
@PathVariable("id") @ApiPathParam(description = "The id of the category") int id) { | ||
return (CategoryObject) categoryManager.getCategory(id); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Creates new category") | ||
@ApiResponseObject | ||
@RequestMapping(method = RequestMethod.POST, value = "/category", consumes = "application/json") | ||
void addCategory(@RequestBody @ApiBodyObject CategoryObject category) { | ||
categoryManager.createCategory(category); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Updates existing category") | ||
@ApiResponseObject | ||
@RequestMapping(method = RequestMethod.PUT, value = "/category/{id}", consumes = "application/json") | ||
void updateCategory( | ||
@PathVariable("id") @ApiPathParam(description = "The id of the category") int id, | ||
@RequestBody @ApiBodyObject CategoryObject category) { | ||
|
||
category.setId(id); | ||
categoryManager.updateCategory(category); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
catalog-microservice/src/main/java/com/forest/micro/catalog/ProductEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.forest.micro.catalog; | ||
|
||
import java.util.List; | ||
|
||
import org.jsondoc.core.annotation.Api; | ||
import org.jsondoc.core.annotation.ApiAuthNone; | ||
import org.jsondoc.core.annotation.ApiBodyObject; | ||
import org.jsondoc.core.annotation.ApiMethod; | ||
import org.jsondoc.core.annotation.ApiPathParam; | ||
import org.jsondoc.core.annotation.ApiQueryParam; | ||
import org.jsondoc.core.annotation.ApiResponseObject; | ||
import org.jsondoc.core.annotation.ApiVersion; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.forest.micro.catalog.model.ProductObject; | ||
import com.forest.micro.catalog.wiring.ProductManager; | ||
import com.forest.model.Product; | ||
|
||
@RestController | ||
@Api(name = "Product", description = "Methods for managing products") | ||
@ApiVersion(since = "1.0") | ||
@ApiAuthNone | ||
public class ProductEndpoint { | ||
|
||
private ProductManager productManager; | ||
|
||
@Autowired | ||
public ProductEndpoint(ProductManager productManager) { | ||
this.productManager = productManager; | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Get a list of all products") | ||
@ApiResponseObject | ||
@RequestMapping("/products") | ||
List<Product> getProducts() { | ||
return productManager.getAll(); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Returns a product with given id") | ||
@ApiResponseObject | ||
@RequestMapping(value = "/product/{id}", produces = "application/json") | ||
ProductObject getProduct( | ||
@PathVariable("id") @ApiPathParam(description = "The id of the product") int id) { | ||
return (ProductObject) productManager.getProduct(id); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Creates new product") | ||
@ApiResponseObject | ||
@RequestMapping(method = RequestMethod.POST, value = "/product", consumes = "application/json") | ||
void addProduct(@RequestBody @ApiBodyObject ProductObject product) { | ||
productManager.createProduct(product); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Updates existing product") | ||
@ApiResponseObject | ||
@RequestMapping(method = RequestMethod.PUT, value = "/product/{id}", consumes = "application/json") | ||
void updateProduct( | ||
@PathVariable("id") @ApiPathParam(description = "The id of the product") int id, | ||
@RequestBody @ApiBodyObject ProductObject product) { | ||
|
||
product.setId(id); | ||
productManager.updateProduct(product); | ||
} | ||
|
||
@ApiMethod(produces = "application/json", description = "Gets products in given category") | ||
@ApiResponseObject | ||
@RequestMapping(method = RequestMethod.GET, value = "/category/{id}/products", produces = "application/json") | ||
List<Product> getProductInCategory( | ||
@PathVariable("id") @ApiPathParam(description = "The id of the category") int id, | ||
@RequestParam(defaultValue = "0", required = false) @ApiQueryParam(name = "from", defaultvalue = "0", required = false) int from, | ||
@RequestParam(defaultValue = "10", required = false) @ApiQueryParam(name = "to", defaultvalue = "10", required = false) int to) { | ||
|
||
return productManager.getProductsInCategory(id, from, to); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
catalog-microservice/src/main/java/com/forest/micro/catalog/model/CategoryObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* You may not modify, use, reproduce, or distribute this software except in | ||
* compliance with the terms of the License at: | ||
* http://java.net/projects/javaeetutorial/pages/BerkeleyLicense | ||
*/ | ||
package com.forest.micro.catalog.model; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
import org.jsondoc.core.annotation.ApiObject; | ||
import org.jsondoc.core.annotation.ApiObjectField; | ||
|
||
import com.forest.model.Category; | ||
|
||
@ApiObject(name = "Category", description = "Category") | ||
@XmlRootElement | ||
public class CategoryObject extends Category { | ||
|
||
private static final long serialVersionUID = -5400424750505982222L; | ||
|
||
@ApiObjectField(description = "Category name", required = true) | ||
protected String name; | ||
|
||
@ApiObjectField(description = "Tags") | ||
protected String tags; | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
catalog-microservice/src/main/java/com/forest/micro/catalog/model/ProductObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* You may not modify, use, reproduce, or distribute this software except in | ||
* compliance with the terms of the License at: | ||
* http://java.net/projects/javaeetutorial/pages/BerkeleyLicense | ||
*/ | ||
package com.forest.micro.catalog.model; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.XmlTransient; | ||
|
||
import org.jsondoc.core.annotation.ApiObject; | ||
import org.jsondoc.core.annotation.ApiObjectField; | ||
|
||
import com.forest.model.Category; | ||
import com.forest.model.Product; | ||
|
||
@ApiObject (name="Product", description="Product") | ||
@XmlRootElement | ||
public class ProductObject extends Product { | ||
|
||
private static final long serialVersionUID = -9109112921000514199L; | ||
|
||
|
||
@ApiObjectField(description="Product name", required=true) | ||
protected String name; | ||
|
||
@ApiObjectField(description="Product price") | ||
protected double price; | ||
|
||
@ApiObjectField(description="Product description") | ||
protected String description; | ||
|
||
@XmlTransient | ||
protected Category category; | ||
|
||
@ApiObjectField(description="Category to add to") | ||
protected Integer categoryId; | ||
|
||
public Integer getCategoryId() { | ||
return categoryId; | ||
} | ||
|
||
public void setCategoryId(Integer categoryId) { | ||
this.categoryId = categoryId; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
catalog-microservice/src/main/java/com/forest/micro/catalog/wiring/CategoryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.forest.micro.catalog.wiring; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.forest.usecase.catalog.AbstractBaseCategoryManager; | ||
import com.forest.usecase.catalog.persistence.CategoryPersistence; | ||
|
||
|
||
@Component | ||
public class CategoryManager extends AbstractBaseCategoryManager { | ||
|
||
@Autowired | ||
private CategoryPersistence categoryPersistence; | ||
|
||
@Override | ||
protected CategoryPersistence getCategoryPersistence() { | ||
return categoryPersistence; | ||
} | ||
|
||
} |
Oops, something went wrong.