forked from TranDatk/spring-boot-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
165 additions
and
206 deletions.
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
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
spring-boot-swagger/src/main/java/me/loda/spring/swagger/config/Swagger2Config.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
spring-boot-swagger/src/main/java/me/loda/spring/swagger/controller/EmployeeController.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
spring-boot-swagger/src/main/java/me/loda/spring/swagger/model/Employee.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
spring-boot-swagger/src/main/java/me/loda/spring/swagger/repository/EmployeeRepository.java
This file was deleted.
Oops, something went wrong.
Empty file.
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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<parent> | ||
<artifactId>spring-boot-learning</artifactId> | ||
<groupId>me.loda.spring</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-swagger2</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger-ui</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
|
||
<!--spring jpa--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<!--in memory database--> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
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
34 changes: 34 additions & 0 deletions
34
spring-boot-swagger2/src/main/java/me/loda/spring/swagger/config/Swagger2Config.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,34 @@ | ||
package me.loda.spring.swagger.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import springfox.documentation.builders.ApiInfoBuilder; | ||
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; | ||
|
||
@Configuration | ||
@EnableSwagger2 | ||
public class Swagger2Config { | ||
@Bean | ||
public Docket api() { | ||
return new Docket(DocumentationType.SWAGGER_2).select() | ||
.apis(RequestHandlerSelectors.basePackage("me.loda.spring.swagger.controller")) | ||
.paths(PathSelectors.regex("/.*")) | ||
.build().apiInfo(apiEndPointsInfo()); | ||
} | ||
private ApiInfo apiEndPointsInfo() { | ||
return new ApiInfoBuilder().title("Spring Boot REST API") | ||
.description("Employee Management REST API") | ||
.contact(new Contact("loda", "https://loda.me/", "[email protected]")) | ||
.license("Apache 2.0") | ||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") | ||
.version("1.0.0") | ||
.build(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
spring-boot-swagger2/src/main/java/me/loda/spring/swagger/controller/EmployeeController.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,51 @@ | ||
package me.loda.spring.swagger.controller; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.Valid; | ||
|
||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.loda.spring.swagger.model.Employee; | ||
import me.loda.spring.swagger.repository.EmployeeRepository; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class EmployeeController { | ||
private final EmployeeRepository employeeRepository; | ||
|
||
@GetMapping("/employees") | ||
public List<Employee> getAllEmployees() { | ||
return employeeRepository.findAll(); | ||
} | ||
|
||
@GetMapping("/employees/{id}") | ||
public Employee getEmployee(@PathVariable("id") Long id) { | ||
return employeeRepository.findById(id).orElse(new Employee()); | ||
} | ||
|
||
@PostMapping("/employees") | ||
public Employee createEmployee(@Valid @RequestBody Employee employee) { | ||
return employeeRepository.save(employee); | ||
} | ||
|
||
@PutMapping("/employees/{id}") | ||
public Employee updateEmployee(@PathVariable("id") Long id, @Valid @RequestBody Employee employee) { | ||
employee.setId(id); | ||
return employeeRepository.save(employee); | ||
} | ||
|
||
@DeleteMapping("/employees/{id}") | ||
public void deleteEmployee(@PathVariable("id") Long id) { | ||
employeeRepository.deleteById(id); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
spring-boot-swagger2/src/main/java/me/loda/spring/swagger/model/Employee.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,26 @@ | ||
package me.loda.spring.swagger.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Entity | ||
@Table | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Employee { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String firstName; | ||
private String lastName; | ||
private String email; | ||
} |
Oops, something went wrong.