Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 335 #28

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```## Feature_334
## Feature_335
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.7.0</version>
</dependency>

<dependency>
Expand Down
37 changes: 4 additions & 33 deletions src/main/java/net/codejava/SalesDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,13 @@ public List<Sale> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/js/styles.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
70 changes: 0 additions & 70 deletions src/test/java/net/codejava/JUnit5ExampleTest11.java

This file was deleted.

Loading