diff --git a/.circleci/config.yml b/.circleci/config.yml
index 5e3e4d8c4..437fb1c87 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -30,6 +30,7 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
+
- run: mvn dependency:go-offline
- save_cache:
diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
new file mode 100644
index 000000000..e76d1f324
--- /dev/null
+++ b/.mvn/wrapper/MavenWrapperDownloader.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2007-present the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.net.*;
+import java.io.*;
+import java.nio.channels.*;
+import java.util.Properties;
+
+public class MavenWrapperDownloader {
+
+ private static final String WRAPPER_VERSION = "0.5.6";
+ /**
+ * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
+ */
+ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
+
+ /**
+ * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
+ * use instead of the default one.
+ */
+ private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
+ ".mvn/wrapper/maven-wrapper.properties";
+
+ /**
+ * Path where the maven-wrapper.jar will be saved to.
+ */
+ private static final String MAVEN_WRAPPER_JAR_PATH =
+ ".mvn/wrapper/maven-wrapper.jar";
+
+ /**
+ * Name of the property which should be used to override the default download url for the wrapper.
+ */
+ private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
+
+ public static void main(String args[]) {
+ System.out.println("- Downloader started");
+ File baseDirectory = new File(args[0]);
+ System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
+
+ // If the maven-wrapper.properties exists, read it and check if it contains a custom
+ // wrapperUrl parameter.
+ File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
+ String url = DEFAULT_DOWNLOAD_URL;
+ if(mavenWrapperPropertyFile.exists()) {
+ FileInputStream mavenWrapperPropertyFileInputStream = null;
+ try {
+ mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
+ Properties mavenWrapperProperties = new Properties();
+ mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
+ url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
+ } catch (IOException e) {
+ System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
+ } finally {
+ try {
+ if(mavenWrapperPropertyFileInputStream != null) {
+ mavenWrapperPropertyFileInputStream.close();
+ }
+ } catch (IOException e) {
+ // Ignore ...
+ }
+ }
+ }
+ System.out.println("- Downloading from: " + url);
+
+ File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
+ if(!outputFile.getParentFile().exists()) {
+ if(!outputFile.getParentFile().mkdirs()) {
+ System.out.println(
+ "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
+ }
+ }
+ System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
+ try {
+ downloadFileFromURL(url, outputFile);
+ System.out.println("Done");
+ System.exit(0);
+ } catch (Throwable e) {
+ System.out.println("- Error downloading");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ private static void downloadFileFromURL(String urlString, File destination) throws Exception {
+ if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
+ String username = System.getenv("MVNW_USERNAME");
+ char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(username, password);
+ }
+ });
+ }
+ URL website = new URL(urlString);
+ ReadableByteChannel rbc;
+ rbc = Channels.newChannel(website.openStream());
+ FileOutputStream fos = new FileOutputStream(destination);
+ fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+ fos.close();
+ rbc.close();
+ }
+
+}
diff --git a/HELP.md b/HELP.md
new file mode 100644
index 000000000..ee42ad0d4
--- /dev/null
+++ b/HELP.md
@@ -0,0 +1,9 @@
+# Getting Started
+
+### Reference Documentation
+For further reference, please consider the following sections:
+
+* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
+* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.4.0/maven-plugin/reference/html/)
+* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.4.0/maven-plugin/reference/html/#build-image)
+
diff --git a/pom.xml b/pom.xml
index fba1a29a1..b22c1bd9f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,11 @@
guru.springfamework
spring5-mvc-rest
0.0.1-SNAPSHOT
- jar
+
+ rest-model
+ spring5-mvc-rest-app
+
+ pom
spring5-mvc-rest
Demo project for Spring Boot
@@ -14,7 +18,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.1.0.RELEASE
+ 2.3.6.RELEASE
@@ -22,67 +26,11 @@
UTF-8
UTF-8
1.8
+ 2.7.0
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
- org.springframework.boot
- spring-boot-devtools
- runtime
-
-
- com.h2database
- h2
- runtime
-
-
- org.projectlombok
- lombok
- true
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
-
- html
- xml
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.22.1
-
- false
-
-
-
-
+
diff --git a/rest-model/pom.xml b/rest-model/pom.xml
new file mode 100644
index 000000000..476156773
--- /dev/null
+++ b/rest-model/pom.xml
@@ -0,0 +1,56 @@
+
+
+
+ spring5-mvc-rest
+ guru.springfamework
+ 0.0.1-SNAPSHOT
+
+ 4.0.0
+
+ rest-model
+ spring-rest-model
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.0
+
+
+ com.sun.xml.bind
+ jaxb-core
+ 2.3.0
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ 2.3.0
+
+
+
+
+
+ org.codehaus.mojo
+ jaxb2-maven-plugin
+ 2.5.0
+
+
+ xjc
+
+ xjc
+
+
+
+
+
+ guru.springfamework.model
+
+ src/main/resources/xsd
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring5-mvc-rest-app/pom.xml b/spring5-mvc-rest-app/pom.xml
new file mode 100644
index 000000000..921042f20
--- /dev/null
+++ b/spring5-mvc-rest-app/pom.xml
@@ -0,0 +1,128 @@
+
+
+
+ spring5-mvc-rest
+ guru.springfamework
+ 0.0.1-SNAPSHOT
+
+ 4.0.0
+
+ spring5-mvc-rest-app
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+
+
+ com.h2database
+ h2
+ runtime
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.mapstruct
+ mapstruct
+ 1.4.1.Final
+
+
+ io.springfox
+ springfox-swagger2
+ ${springfox-swagger-version}
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${springfox-swagger-version}
+
+
+ org.codehaus.woodstox
+ woodstox-core-asl
+ 4.4.1
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+
+
+ guru.springfamework
+ rest-model
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+
+ html
+ xml
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.1
+
+ false
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.7.0
+
+ 1.8
+ 1.8
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+ org.mapstruct
+ mapstruct-processor
+ 1.4.1.Final
+
+
+
+
+ -Amapstruct.defaultComponentModel=spring
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/guru/springfamework/Spring5MvcRestApplication.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/Spring5MvcRestApplication.java
similarity index 86%
rename from src/main/java/guru/springfamework/Spring5MvcRestApplication.java
rename to spring5-mvc-rest-app/src/main/java/guru/springfamework/Spring5MvcRestApplication.java
index dabeae054..3cdd0d308 100644
--- a/src/main/java/guru/springfamework/Spring5MvcRestApplication.java
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/Spring5MvcRestApplication.java
@@ -4,9 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-public class Spring5MvcRestApplication {
+
+public class Spring5MvcRestApplication {
public static void main(String[] args) {
SpringApplication.run(Spring5MvcRestApplication.class, args);
}
+
+
}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CategoryMapper.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CategoryMapper.java
new file mode 100644
index 000000000..306a2caf1
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CategoryMapper.java
@@ -0,0 +1,21 @@
+package guru.springfamework.api.v1.mapper;
+
+
+import guru.springfamework.api.v1.model.CategoryDTO;
+import guru.springfamework.domain.Category;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * Darcy Xian 21/11/20 12:37 pm spring5-mvc-rest
+ */
+@Mapper
+public interface CategoryMapper {
+
+ CategoryMapper INSTANCE = Mappers.getMapper(CategoryMapper.class);
+
+ @Mapping(source = "id", target = "id")
+ CategoryDTO categoryToCategoryDTO(Category category);
+
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CustomerMapper.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CustomerMapper.java
new file mode 100644
index 000000000..32a0b1cc2
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/CustomerMapper.java
@@ -0,0 +1,24 @@
+package guru.springfamework.api.v1.mapper;
+
+
+import guru.springfamework.domain.Customer;
+import guru.springfamework.model.CustomerDTO;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * Darcy Xian 22/11/20 4:51 pm spring5-mvc-rest
+ */
+@Mapper
+public interface CustomerMapper {
+
+ CustomerMapper INSTANCE = Mappers.getMapper(CustomerMapper.class);
+
+ @Mapping(source = "id",target = "id")
+ CustomerDTO CustomerToCustomerDTO(Customer customer);
+
+ @Mapping(source = "id",target = "id")
+ Customer CustomerDTOToCustomer(CustomerDTO customerDTO);
+
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/VendorMapper.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/VendorMapper.java
new file mode 100644
index 000000000..ead9a175d
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/mapper/VendorMapper.java
@@ -0,0 +1,25 @@
+package guru.springfamework.api.v1.mapper;
+
+import guru.springfamework.api.v1.model.VendorDTO;
+import guru.springfamework.domain.Vendor;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+
+/**
+ * Darcy Xian 24/11/20 3:36 pm spring5-mvc-rest
+ */
+@Mapper
+public interface VendorMapper {
+
+ VendorMapper INSTANCE = Mappers.getMapper(VendorMapper.class);
+
+ @Mapping(source = "id", target = "id")
+ VendorDTO vendorToVendorDTO(Vendor vendor);
+
+ @Mapping(source = "id", target = "id")
+ Vendor vendorDTOToVendor(VendorDTO vendorDTO);
+
+
+}
diff --git a/src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java
similarity index 85%
rename from src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java
rename to spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java
index 135ca3621..94c0ecb7b 100644
--- a/src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryDTO.java
@@ -1,8 +1,11 @@
package guru.springfamework.api.v1.model;
+import lombok.Data;
+
/**
* Created by jt on 9/24/17.
*/
+@Data
public class CategoryDTO {
private Long id;
private String name;
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryListDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryListDTO.java
new file mode 100644
index 000000000..b42d632b1
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CategoryListDTO.java
@@ -0,0 +1,15 @@
+package guru.springfamework.api.v1.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * Darcy Xian 21/11/20 7:42 pm spring5-mvc-rest
+ */
+@Data
+@AllArgsConstructor
+public class CategoryListDTO {
+ List categoryListDTOS;
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerDTO.java
new file mode 100644
index 000000000..fe77f21a3
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerDTO.java
@@ -0,0 +1,18 @@
+package guru.springfamework.api.v1.model;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * Darcy Xian 22/11/20 4:46 pm spring5-mvc-rest
+ */
+@Data
+public class CustomerDTO {
+
+ private Long id;
+ @ApiModelProperty(value = "This is the first name",required = true)
+ private String firstname;
+ @ApiModelProperty(value = "This is the first name",required = false)
+ private String lastname;
+ private String customerUrl;
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerListDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerListDTO.java
new file mode 100644
index 000000000..305b32ddd
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/CustomerListDTO.java
@@ -0,0 +1,18 @@
+package guru.springfamework.api.v1.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * Darcy Xian 22/11/20 4:47 pm spring5-mvc-rest
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class CustomerListDTO {
+
+ List customerListDTOS;
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorDTO.java
new file mode 100644
index 000000000..fa3a32e4e
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorDTO.java
@@ -0,0 +1,21 @@
+package guru.springfamework.api.v1.model;
+
+import lombok.Data;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * Darcy Xian 24/11/20 3:30 pm spring5-mvc-rest
+ */
+@Data
+public class VendorDTO {
+
+
+ private Long id;
+ private String name;
+ private String nickName;
+ private String vendorUrl;
+
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorListDTO.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorListDTO.java
new file mode 100644
index 000000000..f649301d9
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/api/v1/model/VendorListDTO.java
@@ -0,0 +1,13 @@
+
+package guru.springfamework.api.v1.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+public class VendorListDTO
+{
+ List vendorDTOS;
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/bootstrap/Bootstrap.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/bootstrap/Bootstrap.java
new file mode 100644
index 000000000..acec4186a
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/bootstrap/Bootstrap.java
@@ -0,0 +1,88 @@
+package guru.springfamework.bootstrap;
+
+import guru.springfamework.domain.Category;
+import guru.springfamework.domain.Customer;
+import guru.springfamework.domain.Vendor;
+import guru.springfamework.repositories.CategoryRepository;
+import guru.springfamework.repositories.CustomerRepository;
+import guru.springfamework.repositories.VendorRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+/**
+ * Darcy Xian 21/11/20 11:25 am spring5-mvc-rest
+ */
+@Component
+@AllArgsConstructor
+public class Bootstrap implements CommandLineRunner {
+ private CategoryRepository categoryRepository;
+ private CustomerRepository customerRepository;
+ private VendorRepository vendorRepository;
+
+
+ @Override
+ public void run(String... args) throws Exception {
+ loadCategories();
+ loadCustomers();
+ loadVendors();
+
+ }
+
+ private void loadCategories() {
+ // for category
+ Category fruits = new Category();
+ fruits.setName("Fruits");
+
+ Category dried = new Category();
+ dried.setName("Dried");
+
+ Category fresh = new Category();
+ fresh.setName("Fresh");
+
+ Category exotic = new Category();
+ exotic.setName("Exotic");
+
+ Category nuts = new Category();
+ nuts.setName("nuts");
+
+ categoryRepository.save(fruits);
+ categoryRepository.save(dried);
+ categoryRepository.save(fresh);
+ categoryRepository.save(exotic);
+ categoryRepository.save(nuts);
+
+ System.out.println("Data Loaded = " + categoryRepository.count());
+ }
+
+ private void loadCustomers(){
+ // for Customer
+ Customer customer = new Customer();
+ customer.setFirstname("Lin");
+ customer.setLastname("Ken");
+
+ Customer customer1 = new Customer();
+ customer1.setFirstname("Jerry");
+ customer1.setLastname("Joe");
+
+ customerRepository.save(customer1);
+ customerRepository.save(customer);
+ System.out.println("Customers Loaded = " + customerRepository.count());
+ }
+
+ private void loadVendors(){
+ Vendor vendor = new Vendor();
+ vendor.setName("Nike");
+ vendor.setNickName("ccccc");
+
+ Vendor vendor1 = new Vendor();
+ vendor1.setName("Addidass");
+ vendor1.setNickName("kkkkkk");
+
+ vendorRepository.save(vendor);
+ vendorRepository.save(vendor1);
+ System.out.println("Vendors Loaded = " + vendorRepository.count());
+
+
+ }
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/config/SwaggerConfig.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/config/SwaggerConfig.java
new file mode 100644
index 000000000..bc5a6d590
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/config/SwaggerConfig.java
@@ -0,0 +1,58 @@
+package guru.springfamework.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Contact;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+
+/**
+ * Darcy Xian 25/11/20 9:58 am spring5-mvc-rest
+ */
+@EnableSwagger2
+@Configuration
+
+public class SwaggerConfig extends WebMvcConfigurationSupport {
+ @Bean
+ public Docket api(){
+ return new Docket(DocumentationType.SWAGGER_2)
+ .select().apis(RequestHandlerSelectors.basePackage("guru.springfamework.controllers.v1"))
+ .paths(PathSelectors.any())
+ .build()
+ .pathMapping("/")
+ .apiInfo(metaData());
+ }
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/swagger-ui.html")
+ .addResourceLocations("classpath:/META-INF/resources/");
+
+ registry.addResourceHandler("/webjars/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+ private ApiInfo metaData(){
+ Contact contact = new Contact("Darcy Xian","http","asdfadf@gmail.com");
+
+ return new ApiInfo(
+ "Spring Framework Darcy",
+ "Spring Framework 5",
+ "1.0",
+ "terms of service: blah",
+ contact,
+ "Apache License Version 2.0",
+ "https://www.apache.org/licenses/LICENSE-2.0",
+ new ArrayList<>());
+
+
+ }
+
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CategoryController.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CategoryController.java
new file mode 100644
index 000000000..fed9b2904
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CategoryController.java
@@ -0,0 +1,35 @@
+package guru.springfamework.controllers.v1;
+
+import guru.springfamework.services.CategoryService;
+import guru.springfamework.api.v1.model.CategoryDTO;
+import guru.springfamework.api.v1.model.CategoryListDTO;
+import lombok.AllArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Darcy Xian 21/11/20 7:37 pm spring5-mvc-rest
+ */
+@RestController
+@RequestMapping(CategoryController.BASE_URL)
+@AllArgsConstructor
+public class CategoryController {
+
+ public static final String BASE_URL = "/api/v1/categories/";
+
+ private final CategoryService categoryService;
+
+
+ @GetMapping
+ @ResponseStatus(HttpStatus.OK)
+ public CategoryListDTO getAllCategories(){
+ return new CategoryListDTO(categoryService.getAllCategories());
+ }
+ @GetMapping("{name}")
+ @ResponseStatus(HttpStatus.OK)
+ public CategoryDTO getCategoryByName (@PathVariable String name){
+ return categoryService.getCategoryByName(name);
+ }
+
+
+}
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CustomerController.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CustomerController.java
new file mode 100644
index 000000000..26c205e84
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/CustomerController.java
@@ -0,0 +1,142 @@
+package guru.springfamework.controllers.v1;
+
+
+import guru.springfamework.model.CustomerDTO;
+import guru.springfamework.model.CustomerListDTO;
+import guru.springfamework.services.CustomerService;
+
+
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Darcy Xian 22/11/20 5:05 pm spring5-mvc-rest
+ */
+@Api(description = "This is my Customer controller")
+@RestController
+@RequestMapping(CustomerController.BASE_URL)
+@AllArgsConstructor
+public class CustomerController {
+
+ public static final String BASE_URL = "/api/v1/customers";
+
+
+ CustomerService customerService;
+
+ @ApiOperation(value = "This will get a list of customers.", notes = "These are some notes about the API")
+ @GetMapping
+ @ResponseStatus(HttpStatus.OK)
+ public CustomerListDTO getAllCustomers (){
+
+ CustomerListDTO customerListDTO = new CustomerListDTO();
+ customerListDTO.getCustomerDTOs().addAll( customerService.findAllCustomers());
+ return customerListDTO;
+ }
+
+ @GetMapping("/{id}")
+ @ResponseStatus(HttpStatus.OK)
+ public CustomerDTO getCustomerById(@PathVariable Long id){
+ CustomerDTO customerDTO = customerService.findCustomerById(id);
+ customerDTO.setCustomerUrl(BASE_URL + id);
+
+
+ return customerDTO;
+ }
+
+ @PostMapping
+ @ResponseStatus(HttpStatus.CREATED)
+ // @RequestBody tell Sping mVC to look at the body of the request and parse it and try to create a
+ // CustomerDTO out of that
+ public CustomerDTO createNewCustomer(@RequestBody CustomerDTO customerDTO){
+ return customerService.createNewCustomer(customerDTO);
+ }
+
+ @PutMapping({"/{id}"})
+ @ResponseStatus(HttpStatus.OK)
+ // @RequestBody tell Sping mVC to look at the body of the request and parse it and try to create a
+ // CustomerDTO out of that
+ public CustomerDTO updateCustomer(
+ @PathVariable Long id,
+ @RequestBody CustomerDTO customerDTO){
+ return customerService.saveCustomerByDTO(id,customerDTO);
+ }
+
+ @PatchMapping({"/{id}"})
+ @ResponseStatus(HttpStatus.OK)
+ // @RequestBody tell Sping mVC to look at the body of the request and parse it and try to create a
+ // CustomerDTO out of that
+ public CustomerDTO patchCustomer(
+ @PathVariable Long id,
+ @RequestBody CustomerDTO customerDTO){
+ return customerService.patchCustomer(id,customerDTO);
+ }
+
+
+ @DeleteMapping({"/{id}"})
+ @ResponseStatus(HttpStatus.OK)
+ // @RequestBody tell Sping mVC to look at the body of the request and parse it and try to create a
+ // CustomerDTO out of that
+ public void deleteCustomer(
+ @PathVariable Long id){
+
+ customerService.deleteCustomerById(id);
+
+ return ;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/RestReponseEntityExceptionHandler.java b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/RestReponseEntityExceptionHandler.java
new file mode 100644
index 000000000..446751a25
--- /dev/null
+++ b/spring5-mvc-rest-app/src/main/java/guru/springfamework/controllers/v1/RestReponseEntityExceptionHandler.java
@@ -0,0 +1,23 @@
+package guru.springfamework.controllers.v1;
+
+import guru.springfamework.services.ResourceNotFoundException;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+/**
+ * Darcy Xian 24/11/20 12:13 pm spring5-mvc-rest
+ */
+@ControllerAdvice
+public class RestReponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
+
+ @ExceptionHandler({ResourceNotFoundException.class})
+ public ResponseEntity