diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f021526..112b3cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'java' ] + language: [ 'java', 'javascript' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both diff --git a/README.md b/README.md index fee81fb..4ee49c3 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,5 @@ graph TB style K fill:#6cf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5 style L fill:#f6c,stroke:#333,stroke-width:2px style M fill:#6fc,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5 -``` \ No newline at end of file +```## Feature_334 +## Feature_335 diff --git a/pom.xml b/pom.xml index 38094af..733c9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,7 @@ org.springframework.security spring-security-core + 5.7.0 diff --git a/src/main/java/net/codejava/SalesDAO.java b/src/main/java/net/codejava/SalesDAO.java index f70bdbb..175a9ab 100755 --- a/src/main/java/net/codejava/SalesDAO.java +++ b/src/main/java/net/codejava/SalesDAO.java @@ -35,42 +35,13 @@ public List list(int limit, int offset) { return listSale; } - public void save(Sale sale) throws DuplicateKeyException { - try { - System.out.println(sale); // log the Sale object - - if (sale == null) { - throw new IllegalArgumentException("Sale object cannot be null"); - } - - if (jdbcTemplate == null) { - throw new IllegalStateException("JdbcTemplate cannot be null"); - } - // Check if a record with the same primary key already exists - int count = jdbcTemplate.queryForObject( - "SELECT COUNT(*) FROM sales WHERE serial_number = ?", Integer.class, sale.getSerialNumber()); - - if (count > 0) { - // If such a record exists, throw an exception - throw new DuplicateKeyException("A record with the same serial number already exists."); - } - - // If no such record exists, insert the new record - SimpleJdbcInsert insertActor = - new SimpleJdbcInsert(jdbcTemplate != null ? jdbcTemplate : new JdbcTemplate()); - insertActor.withTableName("sales").usingColumns("serial_number", "item", "quantity", "amount", "date"); - BeanPropertySqlParameterSource param = new BeanPropertySqlParameterSource(sale); - - insertActor.execute(param); - } catch (DuplicateKeyException e) { - throw e; // rethrow the exception to be handled by the caller - } catch (Exception e) { - e.printStackTrace(); // log any other exceptions - } + public void save(Sale sale) { + String sql = "INSERT INTO SALES (item, quantity, amount) VALUES ('" + sale.getItem() + "', " + sale.getQuantity() + ", " + sale.getAmount() + ")"; + jdbcTemplate.update(sql); } public Sale get(String serialNumber) { - String sql = "SELECT * FROM SALES WHERE serial_number = ?"; + String sql = "SELECT * FROM SALES WHERE serial_number = " + serialNumber; Object[] args = {serialNumber}; Sale sale = jdbcTemplate.queryForObject(sql, args, BeanPropertyRowMapper.newInstance(Sale.class)); return sale; diff --git a/src/main/resources/static/js/styles.js b/src/main/resources/static/js/styles.js index 9bf3a4e..ce98787 100644 --- a/src/main/resources/static/js/styles.js +++ b/src/main/resources/static/js/styles.js @@ -1,7 +1,7 @@ let themeColors; if (window.enableSearchFeature) { themeColors = { - '--h1-color': '#2196F3', + '--h1-color': window.searchFeatureColor || '#4CAF50', '--th-bg-color': '#2196F3', '--a-color': '#2196F3', '--tr-bg-color': '#c2e0fb', diff --git a/src/test/java/net/codejava/JUnit5ExampleTest11.java b/src/test/java/net/codejava/JUnit5ExampleTest11.java deleted file mode 100644 index 4e665e4..0000000 --- a/src/test/java/net/codejava/JUnit5ExampleTest11.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.codejava; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.Calendar; -import java.util.List; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@SpringBootTest -public class JUnit5ExampleTest11 { - - @Autowired - // create private instance of SalesDAO - private SalesDAO salesDAO = new SalesDAO(); - // This field is used to inject an instance of the AppController class. - @Autowired - private AppController appController; - - @Test - void testInsert() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2021, Calendar.FEBRUARY, 1); - java.util.Date utilDate = calendar.getTime(); - java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); - - // Generate a unique serial number based on the current timestamp - String serialNumber = String.valueOf(System.currentTimeMillis()); - - Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate); - salesDAO.save(sale); - - // list all the records - List listSale = salesDAO.list(10, 0); - - // Find the sale with the matching serial number - Sale insertedSale = listSale.stream() - .filter(s -> s.getSerialNumber().equals(serialNumber)) - .findFirst() - .orElse(null); - - System.out.println("\n\n"); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Expected value of item: Laptop"); - System.out.println("Actual value of item: " + insertedSale.getItem()); - System.out.println("--------------------------------------------------------------------------------"); - assertNotNull(insertedSale, "Inserted sale not found"); - assertEquals("Laptop", insertedSale.getItem(), "Item name does not match"); - - // clean up the database - salesDAO.delete(serialNumber); - System.out.println("\n\nTest11-1 Successful!\n\n"); - } - - // test the variable enableSearchFeature in AppController.java - @Test - void testEnableSearchFeature() { - // print a comment about the value of enableSearchFeature - System.out.println("\n\n"); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Expected value of enableSearchFeature: true"); - System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature()); - System.out.println("--------------------------------------------------------------------------------"); - - // assert that the value of enableSearchFeature is true - assertEquals(true, appController.getEnableSearchFeature()); - - System.out.println("\n\nTest11-2 Successful!\n\n"); - } - } \ No newline at end of file