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

Pd 470 #38

Closed
wants to merge 11 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,11 @@ 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
```
```## PD-463
## PD-464
## PD-465
## PD-466
## PD-467
## PD-468
## PD-469
## PD-470
3 changes: 2 additions & 1 deletion my-chart/templates/redis_db-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ spec:
ports:
- containerPort: 6379
resources: {{- toYaml .Values.redisDatabaseDeployment.redisDatabaseContainer.resources
| nindent 10 }}
| nindent 10 }}

9 changes: 8 additions & 1 deletion src/main/java/net/codejava/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,12 @@ public void exportToCSV(HttpServletResponse response) throws IOException {
writer.newLine();
}
writer.flush();
}
}

@RequestMapping("/high-quantity-items")
public String getHighQuantityItems(@RequestParam int threshold, Model model) {
List<Sale> highQuantityItems = dao.getItemsWithHighestQuantity(threshold);
model.addAttribute("highQuantityItems", highQuantityItems);
return "high_quantity_items"; // This should be the name of your view file
}
}
5 changes: 3 additions & 2 deletions src/main/java/net/codejava/EnableWebSecurity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.codejava;

public @interface EnableWebSecurity {

}
String message() default "Web security enabled";
int securityLevel() default 1;
}
13 changes: 13 additions & 0 deletions src/main/java/net/codejava/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.codejava;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Role {
@Id
private Long id;
private String roleName;

// getters and setters
}
8 changes: 8 additions & 0 deletions src/main/java/net/codejava/RoleRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.codejava;

import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;

public interface RoleRepository extends JpaRepository<Role, Long> {
List<Role> findByRoleName(String roleName);
}
15 changes: 15 additions & 0 deletions src/main/java/net/codejava/Sale.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ public void setEditing(boolean isEditing) {
public String toString() {
return "Sale [serial_number=" + serialNumber + ", item=" + item + ", quantity=" + quantity + ", amount=" + amount + ", date=" + date + "]";
}

public float calculateTotalAmount(float pricePerItem) {
return this.quantity * pricePerItem;
}

public boolean isRecentSale(int days) {
Date now = new Date();
long millisInADay = 24 * 60 * 60 * 1000;
return (now.getTime() - this.date.getTime()) / millisInADay <= days;
}

public void updateSale(int quantity, float amount) {
this.quantity = quantity;
this.amount = amount;
}
}
6 changes: 6 additions & 0 deletions src/main/java/net/codejava/SalesDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ public List<Sale> listAll() {
List<Sale> listSale = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(Sale.class));
return listSale;
}

public List<Sale> getItemsWithHighestQuantity(int threshold) {
String sql = "SELECT * FROM sales WHERE quantity >= ?";
List<Sale> listSale = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(Sale.class), threshold);
return listSale;
}
}
15 changes: 11 additions & 4 deletions src/main/java/net/codejava/SalesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
@SpringBootApplication
public class SalesManager {

/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(SalesManager.class, args);
}
}

// A simple static method to print a greeting
public static void printGreeting() {
System.out.println("Hello, welcome to Sales Manager!");
}

// A simple static method to calculate the sum of two numbers
public static int sum(int a, int b) {
return a + b;
}
}
20 changes: 19 additions & 1 deletion src/main/java/net/codejava/SessionConfig.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
package net.codejava;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Configuration
@EnableRedisHttpSession
public class SessionConfig {
// This class is intentionally left blank.

// Override Redis configuration action
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}

// Customize Redis template
@Bean
public RedisTemplate<Object, Object> sessionRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
// Add any custom configuration here
return template;
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/codejava/UserDetailsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private static final Logger logger = LoggerFactory.getLogger(UserDetailsServiceImpl.class);

@Autowired
private UserRepository userRepository;
private RoleRepository userRepository;

@Autowired
private PasswordEncoder passwordEncoder;
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/net/codejava/UserRepository.java

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/resources/db/changelog/changelog_version-3.3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,26 @@
</rollback>
</changeSet>

<changeSet id="5" author="TsviZ">
<createTable tableName="role">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet id="6" author="TsviZ">
<insert tableName="role">
<column name="name" value="ROLE_USER" />
</insert>
<rollback>
<delete tableName="role">
<where>name = 'ROLE_USER'</where>
</delete>
</rollback>
</changeSet>

</databaseChangeLog>
29 changes: 29 additions & 0 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ <h1>Inventory Records</h1>
<a class="button" th:href="@{'/clear/' + ${sale.serialNumber}}" onclick="return confirm('Clear: This action is irreversible. Are you sure you want to clear the sale record?')" style="color: #ff7f7f;">Clear</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<form action="/high-quantity-items" method="get">
<label for="threshold">Set threshold for high quantity items:</label>
<input type="number" id="threshold" name="threshold" min="0" />
<button type="submit">Set Threshold</button>
</form>
</div>
<div class="quantity-table" th:if="${highQuantityItems}">
<h2>High Quantity Items</h2>
<table style="width: 35%" border="1" cellpadding="10" class="main-table">
<thead>
<tr>
<th>Serial Number</th>
<th>Item Name</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr th:each="sale : ${highQuantityItems}">
<td th:text="${sale.serialNumber}">serial Number</td>
<td th:text="${sale.item}">Item Name</td>
<td th:text="${sale.quantity}">Quantity</td>
<td th:text="${sale.amount}">Amount</td>
</tr>
</tbody>
</table>
</div>
Expand Down
Loading