-
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 #3 from nhkhai/main
(SIS-19) & (SIS-23): Added basic CI and basic test cases for testing the CI system.
- Loading branch information
Showing
15 changed files
with
348 additions
and
81 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# This workflow will build a Java Spring Boot Application with Maven, and run test cases. | ||
name: Build and Test Java Spring Boot Application | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
run-unit-tests: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:latest | ||
|
||
env: | ||
POSTGRES_USER: postgres | ||
# POSTGRES_PASSWORD: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
POSTGRES_DB: smart_inventory | ||
|
||
# Set health checks to wait until postgres has started. | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
# Maps tcp port 5432 on service container to the host. | ||
- 5432:5432 | ||
|
||
steps: | ||
- name: Pull repository | ||
uses: actions/[email protected] | ||
|
||
- name: Set up JDK | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
# cache: maven # Uncomment and configure if needed. | ||
|
||
- name: Run unit tests | ||
run: mvn test | ||
|
||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive. | ||
# - name: Update dependency graph | ||
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 | ||
|
||
- name: Build Jar file | ||
run: mvn package -DskipTests # Skip tests since they were already run. | ||
|
||
- name: Save Jar file | ||
uses: actions/[email protected] | ||
with: | ||
name: smart-inventory-0.0.1-SNAPSHOT | ||
path: target/smart-inventory-0.0.1-SNAPSHOT.jar | ||
retention-days: 1 |
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,6 +1,6 @@ | ||
package sg.com.smartinventory; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
// import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
|
@@ -13,44 +13,53 @@ | |
|
||
@Component | ||
public class DataLoader { | ||
//Inject all repositories | ||
// Inject all repositories. | ||
private CustomerRepository customerRepository; | ||
private ProductRepository productRepository; | ||
private ReviewRepository reviewRepository; | ||
|
||
@Autowired | ||
public DataLoader(CustomerRepository customerRepository, ProductRepository productRepository, 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 | ||
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", 12345, 1234567890, "[email protected]", 101)); | ||
customerRepository.save(new Customer("Alice", "Smith", "Canada", "456 Maple Ave", 54321, 987654321, "[email protected]", 102)); | ||
customerRepository.save(new Customer("Michael", "Johnson", "UK", "789 Oak Rd", 67890, 987612345, "[email protected]", 103)); | ||
customerRepository.save(new Customer("Emily", "Brown", "Australia", "321 Elm St", 13579, 456789123, "[email protected]", 104)); | ||
customerRepository.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 98765, 369852147, "[email protected]", 105)); | ||
// 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")); | ||
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)); | ||
|
||
} | ||
|
||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/sg/com/smartinventory/controllers/CustomerController.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,35 @@ | ||
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.entity.Customer; | ||
import sg.com.smartinventory.services.CustomerService; | ||
|
||
@RestController | ||
@RequestMapping("/customers") | ||
public class CustomerController { | ||
private CustomerService customerService; | ||
|
||
// @Autowired | ||
public CustomerController(CustomerService customerService) { | ||
this.customerService = customerService; | ||
} | ||
|
||
// CREATE. | ||
@PostMapping("") | ||
public ResponseEntity<Customer> createCustomer(@Valid @RequestBody Customer customer) { | ||
|
||
// if(bindingResult.hasErrors()) { | ||
// return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
// } | ||
|
||
Customer newCustomer = customerService.createCustomer(customer); | ||
return new ResponseEntity<>(newCustomer, 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
Oops, something went wrong.