forked from javabyranjith/spring-boot
-
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
1 parent
b76d564
commit 70fed32
Showing
12 changed files
with
163 additions
and
113 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 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 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 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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
|
||
|
||
plugins { | ||
id 'org.springframework.boot' version '2.2.4.RELEASE' | ||
id 'java' | ||
} | ||
|
||
apply plugin: 'io.spring.dependency-management' | ||
|
||
sourceCompatibility = '1.8' | ||
targetCompatibility = '1.8' | ||
|
||
repositories { | ||
jcenter() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.0.0.RELEASE', ext: 'pom' | ||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE' | ||
testImplementation 'junit:junit:4.12' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
|
||
runtime('com.h2database:h2') | ||
|
||
implementation 'org.projectlombok:lombok:1.18.12' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
runtime('org.springframework.boot:spring-boot-devtools') | ||
testCompile('org.springframework.boot:spring-boot-starter-test') | ||
} |
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
11 changes: 11 additions & 0 deletions
11
sboot-rest/src/main/java/jbr/springboot/restapi/dao/ProductRepository.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,11 @@ | ||
package jbr.springboot.restapi.dao; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import jbr.springboot.restapi.model.Product; | ||
|
||
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, String> { | ||
|
||
Product findProductByName(String name); | ||
} |
68 changes: 16 additions & 52 deletions
68
sboot-rest/src/main/java/jbr/springboot/restapi/model/Product.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 |
---|---|---|
@@ -1,63 +1,27 @@ | ||
package jbr.springboot.restapi.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Product Model. | ||
* | ||
* @author Ranjith Sekar | ||
* @since 2018, Jun 20 | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
public class Product { | ||
|
||
private String id; | ||
private String name; | ||
private String type; | ||
private String price; | ||
|
||
public Product() { | ||
} | ||
|
||
public Product(String id, String name, String type, String price) { | ||
this.id = id; | ||
this.name = name; | ||
this.type = type; | ||
this.price = price; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(String price) { | ||
this.price = price; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "id:" + this.id + " | name: " + this.name + " | type: " + this.type + " | price: " + this.price; | ||
} | ||
|
||
@Id | ||
private String id; | ||
private String name; | ||
private String category; | ||
private String price; | ||
} |
14 changes: 14 additions & 0 deletions
14
sboot-rest/src/main/java/jbr/springboot/restapi/model/ProductApiResponse.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,14 @@ | ||
package jbr.springboot.restapi.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ProductApiResponse<T> { | ||
private int status; | ||
private String message; | ||
private Object result; | ||
} |
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
42 changes: 42 additions & 0 deletions
42
sboot-rest/src/main/java/jbr/springboot/restapi/service/ProductServiceImpl.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,42 @@ | ||
package jbr.springboot.restapi.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import jbr.springboot.restapi.dao.ProductRepository; | ||
import jbr.springboot.restapi.model.Product; | ||
|
||
@Service | ||
public class ProductServiceImpl implements ProductService { | ||
|
||
@Autowired | ||
private ProductRepository productRepository; | ||
|
||
@Override | ||
public List<Product> getAllProducts() { | ||
return productRepository.findAll(); | ||
} | ||
|
||
@Override | ||
public Product getProductById(String id) { | ||
return productRepository.findById(id).get(); | ||
} | ||
|
||
@Override | ||
public void addProduct(Product product) { | ||
|
||
} | ||
|
||
@Override | ||
public void updateProduct(Product product, String id) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteProduct(String id) { | ||
|
||
} | ||
|
||
} |
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,16 @@ | ||
server: | ||
servlet: | ||
context-path: /springboot-restapi | ||
port: 6060 | ||
|
||
spring: | ||
datasource: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:testdb | ||
username: ranjith | ||
password: sekar | ||
|
||
h2: | ||
console: | ||
path: /h2-console | ||
enabled: true |
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,5 @@ | ||
INSERT INTO product(id, name, category, price) VALUES('100', 'Samsung S8', 'Mobile', '75000'); | ||
INSERT INTO product(id, name, category, price) VALUES('200', 'Usha Fan', 'Fan', '6000'); | ||
INSERT INTO product(id, name, category, price) VALUES('300', 'Dell Vostro', 'Laptop', '79000'); | ||
INSERT INTO product(id, name, category, price) VALUES('400', 'IFB Washer', 'Washing Machine', '25000'); | ||
INSERT INTO product(id, name, category, price) VALUES('500', 'Redmi 8', 'Mobile', '5000'); |