-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from nhkhai/main
SIS-1: Created skeleton class files and updated project structure.
- Loading branch information
Showing
28 changed files
with
648 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ build/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
src/main/java/sg/com/smartinventory/logfile |
This file was deleted.
Oops, something went wrong.
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
src/main/java/sg/com/smartinventory/controllers/ProductController.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 sg.com.smartinventory.controllers; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import sg.com.smartinventory.entities.Product; | ||
import sg.com.smartinventory.services.ProductService; | ||
|
||
@RestController | ||
@RequestMapping("/products") | ||
public class ProductController { | ||
private ProductService productService; | ||
|
||
// @Autowired | ||
public ProductController(ProductService productService) { | ||
this.productService = productService; | ||
} | ||
|
||
// CREATE. | ||
@PostMapping("") | ||
public ResponseEntity<Product> createProduct(@Valid @RequestBody Product product) { | ||
// if(bindingResult.hasErrors()) { | ||
// return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
// } | ||
|
||
Product newProduct = productService.createProduct(product); | ||
return new ResponseEntity<>(newProduct, HttpStatus.CREATED); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/sg/com/smartinventory/controllers/ReviewController.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 sg.com.smartinventory.controllers; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import sg.com.smartinventory.entities.Review; | ||
import sg.com.smartinventory.services.ReviewService; | ||
|
||
@RestController | ||
@RequestMapping("/reviews") | ||
public class ReviewController { | ||
private ReviewService reviewService; | ||
|
||
// @Autowired | ||
public ReviewController(ReviewService reviewService) { | ||
this.reviewService = reviewService; | ||
} | ||
|
||
// CREATE. | ||
@PostMapping("") | ||
public ResponseEntity<Review> createReview(@Valid @RequestBody Review review) { | ||
// if(bindingResult.hasErrors()) { | ||
// return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
// } | ||
|
||
Review newReview = reviewService.createReview(review); | ||
return new ResponseEntity<>(newReview, HttpStatus.CREATED); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/sg/com/smartinventory/exceptions/CustomerNotFoundException.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,7 @@ | ||
package sg.com.smartinventory.exceptions; | ||
|
||
public class CustomerNotFoundException extends RuntimeException { | ||
public CustomerNotFoundException(Long id) { | ||
super("Could not find customer with id: " + id + ". "); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sg/com/smartinventory/exceptions/ProductNotFoundException.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,7 @@ | ||
package sg.com.smartinventory.exceptions; | ||
|
||
public class ProductNotFoundException extends RuntimeException { | ||
public ProductNotFoundException(String id) { | ||
super("Could not find product with id: " + id + ". "); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sg/com/smartinventory/exceptions/ReviewNotFoundException.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,7 @@ | ||
package sg.com.smartinventory.exceptions; | ||
|
||
public class ReviewNotFoundException extends RuntimeException { | ||
public ReviewNotFoundException(String id) { | ||
super("Could not find review with id: " + 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
24 changes: 24 additions & 0 deletions
24
src/main/java/sg/com/smartinventory/serviceImpls/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,24 @@ | ||
package sg.com.smartinventory.serviceImpls; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import sg.com.smartinventory.entities.Product; | ||
import sg.com.smartinventory.repositories.ProductRepository; | ||
import sg.com.smartinventory.services.ProductService; | ||
|
||
@Service | ||
public class ProductServiceImpl implements ProductService { | ||
private ProductRepository productRepository; | ||
|
||
// @Autowired | ||
public ProductServiceImpl(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
} | ||
|
||
@Override | ||
public Product createProduct(Product product) { | ||
Product newProduct = productRepository.save(product); | ||
|
||
return newProduct; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/sg/com/smartinventory/serviceImpls/ReviewServiceImpl.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,24 @@ | ||
package sg.com.smartinventory.serviceImpls; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import sg.com.smartinventory.entities.Review; | ||
import sg.com.smartinventory.repositories.ReviewRepository; | ||
import sg.com.smartinventory.services.ReviewService; | ||
|
||
@Service | ||
public class ReviewServiceImpl implements ReviewService { | ||
private ReviewRepository reviewRepository; | ||
|
||
// @Autowired | ||
public ReviewServiceImpl(ReviewRepository reviewRepository) { | ||
this.reviewRepository = reviewRepository; | ||
} | ||
|
||
@Override | ||
public Review createReview(Review review) { | ||
Review newReview = reviewRepository.save(review); | ||
|
||
return newReview; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sg/com/smartinventory/services/ProductService.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,7 @@ | ||
package sg.com.smartinventory.services; | ||
|
||
import sg.com.smartinventory.entities.Product; | ||
|
||
public interface ProductService { | ||
Product createProduct(Product product); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/sg/com/smartinventory/services/ReviewService.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,7 @@ | ||
package sg.com.smartinventory.services; | ||
|
||
import sg.com.smartinventory.entities.Review; | ||
|
||
public interface ReviewService { | ||
Review createReview(Review review); | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/sg/com/smartinventory/utility/DataLoader.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,72 @@ | ||
package sg.com.smartinventory.utility; | ||
|
||
// import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
|
||
import sg.com.smartinventory.entities.Customer; | ||
import sg.com.smartinventory.entities.Product; | ||
import sg.com.smartinventory.entities.Review; | ||
import sg.com.smartinventory.repositories.CustomerRepository; | ||
import sg.com.smartinventory.repositories.ProductRepository; | ||
import sg.com.smartinventory.repositories.ReviewRepository; | ||
|
||
@Component | ||
public class DataLoader { | ||
// Inject all repositories. | ||
private CustomerRepository customerRepository; | ||
private ProductRepository productRepository; | ||
private ReviewRepository reviewRepository; | ||
|
||
// @Autowired | ||
public DataLoader(CustomerRepository customerRepository, ProductRepository productRepository, | ||
ReviewRepository reviewRepository) { | ||
this.customerRepository = customerRepository; | ||
this.productRepository = productRepository; | ||
this.reviewRepository = reviewRepository; | ||
} | ||
|
||
@PostConstruct | ||
public void loadData() { | ||
// Clear all data. | ||
customerRepository.deleteAll(); | ||
productRepository.deleteAll(); | ||
reviewRepository.deleteAll(); | ||
|
||
// Create fake data. | ||
customerRepository.save(new Customer("John", "Doe", "USA", "123 Main St", 123456, 12345678, | ||
"[email protected]", 101)); | ||
|
||
customerRepository.save(new Customer("Alice", "Smith", "Canada", "456 Maple Ave", 543210, 98765432, | ||
"[email protected]", 102)); | ||
customerRepository.save(new Customer("Michael", "Johnson", "UK", "789 Oak Rd", 567890, 98761234, | ||
"[email protected]", 103)); | ||
customerRepository.save(new Customer("Emily", "Brown", "Australia", "321 Elm St", 135790, 45678912, | ||
"[email protected]", 104)); | ||
customerRepository.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214, | ||
"[email protected]", 105)); | ||
|
||
productRepository.save(new Product("Electronics", "Smartphone", | ||
"High-end smartphone with advanced features. ", 999.99, 100, 101)); | ||
productRepository.save(new Product("Clothing", "Men's T-Shirt", | ||
"Comfortable cotton t-shirt for everyday wear. ", 29.99, 500, 102)); | ||
productRepository.save(new Product("Home & Kitchen", "Coffee Maker", | ||
"Automatic coffee maker with programmable settings. ", 49.99, 50, 103)); | ||
productRepository.save(new Product("Beauty", "Perfume", | ||
"Elegant fragrance with floral and citrus notes. ", 79.99, 200, 104)); | ||
productRepository.save(new Product("Books", "Science Fiction Novel", | ||
"Bestselling sci-fi novel set in a dystopian future. ", 14.99, 300, 105)); | ||
|
||
reviewRepository.save(new Review("Electronics", "Great smartphone with excellent features. ", | ||
5, 101, 201)); | ||
reviewRepository.save(new Review("Clothing", "Very comfortable t-shirt, fits perfectly. ", | ||
4, 102, 202)); | ||
reviewRepository.save(new Review("Home & Kitchen", "Makes delicious coffee, easy to use. ", | ||
4, 103, 203)); | ||
reviewRepository.save(new Review("Beauty", "Lovely fragrance, long-lasting. ", | ||
5, 104, 204)); | ||
reviewRepository.save(new Review("Books", "Intriguing plot, couldn't put it down. ", | ||
5, 105, 205)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.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
3 changes: 2 additions & 1 deletion
3
...martinventory/CustomerControllerTest.java → ...y/controllers/CustomerControllerTest.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
Oops, something went wrong.