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

Merge Dev #7

Merged
merged 43 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8fa5354
fixed mail-feedback
Paulsenik Apr 19, 2024
1160028
Merge remote-tracking branch 'origin/dev' into dev
Paulsenik Apr 19, 2024
96562e3
Merge branch 'main' into dev
Paulsenik Apr 20, 2024
054230d
cleanup container build
Paulsenik Apr 20, 2024
8272b76
changed compose rebranding
Paulsenik Apr 20, 2024
479149a
Merge remote-tracking branch 'origin/dev' into dev
Paulsenik Apr 22, 2024
ea66d71
moved method functionality from ShopController to ShopService
Apr 23, 2024
ec50578
Added user limits
Apr 23, 2024
36f5eec
added base-path & smaller histories
Paulsenik Apr 23, 2024
2996308
Optional Allowed-Origins
Paulsenik Apr 23, 2024
28b65ef
added frontend kaffekassen build-path
Paulsenik Apr 29, 2024
63cda8c
added frontend kaffekassen build-path 2
Paulsenik Apr 29, 2024
6214cdd
Fixed item disable not working
Apr 29, 2024
c7eb282
Merge remote-tracking branch 'origin/dev' into dev
Apr 29, 2024
80dfb2a
Setup frontend Dockerfile for production use and integrate VITE_BASE_…
FDHoho007 Apr 29, 2024
3271288
fixed nullpointer
Paulsenik Apr 30, 2024
aae918d
fixed paths
Paulsenik Apr 30, 2024
0cb3744
added prev-amount to transactionHistory
Paulsenik Apr 30, 2024
44ee128
refactored style.css
Paulsenik Apr 30, 2024
476cbde
refactored all css-tables
Paulsenik May 2, 2024
51e3c37
reworked acceptance of valid email address
May 6, 2024
85f2060
Merge remote-tracking branch 'origin/dev' into dev
May 6, 2024
f20e3ff
fixed mail-errors & item-/user-modify ui
Paulsenik May 7, 2024
8cdb177
removed data-init & old ldap-adminuser
Paulsenik May 7, 2024
c8c1acc
changed database H2 to MariaDB
Paulsenik May 13, 2024
0872e32
fixed price & balance limits
Paulsenik May 14, 2024
689b391
added changeable Money-Spent & changed invoice-limits
Paulsenik May 14, 2024
761b17d
added Liquibase
Paulsenik May 14, 2024
035fa3c
added initial data-infos
Paulsenik May 14, 2024
2dc4f98
fixed variable-limits of all services & controller
Paulsenik May 18, 2024
47f67b9
fixed name/id-filter & added maximum deposit-value
Paulsenik May 18, 2024
b51de3a
added kiosk-user
Paulsenik May 20, 2024
f65e16a
added personal-tabs in admin-view
Paulsenik May 20, 2024
2bf672d
fixed mobile (mostly)
Paulsenik May 20, 2024
6e25c44
fixed blue-style & progress-bar
Paulsenik May 20, 2024
eba56a8
added frontend user-input linting & polish
Paulsenik May 20, 2024
1e6f200
css cleanup
Paulsenik May 21, 2024
547f544
added ShopHistoryServiceTest
Paulsenik May 21, 2024
47aadad
fixed ShopHistory tests
Paulsenik May 22, 2024
3e90c2d
Added AuthenticationService tests
Paulsenik May 23, 2024
3f3f3ce
fixed css-img-paths
Paulsenik May 23, 2024
1cf3704
added last Tests
Paulsenik May 23, 2024
40a00ff
Merge branch 'refs/heads/testing' into dev
Paulsenik May 23, 2024
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ npm run dev
- [Google-Java-Codestyle](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml)
- Intellij: Settings > Editor > Codestyle > Scheme

Run backend mit LDAP-Container:
Run backend-stack:
```bash
docker compose up ldap backend --build
docker compose up ldap backend mariadb --build
```
2 changes: 0 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ WORKDIR /app
COPY --from=backend /app/backend/target/*.jar ./backend.jar
EXPOSE 8081
ENV DATA_LOCATION /data
ARG LDAP_URI
ENV LDAP_URI $LDAP_URI
CMD ["java", "-jar", "backend.jar"]
12 changes: 9 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@


<dependency>
<artifactId>h2</artifactId>
<groupId>com.h2database</groupId>
<scope>runtime</scope>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.27.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public Page<InvoiceDTO> getInvoices(
@RequestParam(defaultValue = "10") int s,
@RequestParam(required = false) String userId,
@RequestParam(required = false) Boolean mailed) {
return invoiceService.getInvoices(Math.max(0, p), Math.max(1, s), mailed, userId);
return invoiceService.getInvoices(Math.max(0, p), Math.min(Math.max(1, s), 100), mailed,
userId);
}

/**
Expand All @@ -50,11 +51,14 @@ public Page<InvoiceDTO> getInvoices(
@GetMapping("/me")
public Page<InvoiceDTO> getPersonalInvoices(
@RequestParam(defaultValue = "0") int p,
@RequestParam(defaultValue = "10") int s,
@RequestParam(required = false) Boolean mailed, Authentication authentication) {
@RequestParam(defaultValue = "10") int s, Authentication authentication) {
if (authentication == null) {
return Page.empty();
}

CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

return invoiceService.getPersonalInvoices(Math.max(0, p), Math.max(1, s), mailed,
return invoiceService.getInvoices(Math.max(0, p), Math.min(Math.max(1, s), 100), true,
userDetails.getUsername());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public ResponseEntity<FileSystemResource> getDisplayImage(@RequestParam String i
@PostMapping("/item/consume")
public ResponseEntity<String> consume(@RequestParam String id, @RequestParam String userId,
@RequestParam(required = false) Integer n, Authentication authentication) {
if (authentication == null) {
return ResponseEntity.badRequest().build();
}

CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

Collection<UserAccessRole> roles = authService.getRoles(authentication);
Expand All @@ -107,14 +111,15 @@ public ResponseEntity<String> consume(@RequestParam String id, @RequestParam Str
(n == null ? 1 : n), userDetails.getUsername())) {
return ResponseEntity.ok().build();
}
return ResponseEntity.badRequest().build();
return ResponseEntity.badRequest().body(permitted + " " + highestPermission);

}

@PostMapping("/settings/create")
public ResponseEntity<ShopItem> create(@RequestBody ShopItem itemTemplate) {
Optional<ShopItem> shopItem = shopService.createItem(itemTemplate.getId(), itemTemplate.getDisplayName(),
itemTemplate.getCategory(), itemTemplate.getPrice());
Optional<ShopItem> shopItem = shopService.createItem(itemTemplate.getId(),
itemTemplate.getDisplayName(),
itemTemplate.getCategory(), itemTemplate.getPrice());

return shopItem.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.badRequest().build());
}
Expand All @@ -132,7 +137,7 @@ public ResponseEntity<Optional<ShopItem>> delete(@RequestParam String id) {
@PostMapping("/settings/item/displayname")
public ResponseEntity<String> displayName(@RequestParam String id,
@RequestParam String value) {
Optional<ShopItem> shopItem = shopService.changeDisplayName(id,value);
Optional<ShopItem> shopItem = shopService.changeDisplayName(id, value);

if (shopItem.isPresent()) {
return ResponseEntity.ok().build();
Expand All @@ -143,7 +148,7 @@ public ResponseEntity<String> displayName(@RequestParam String id,
@PostMapping("/settings/item/category")
public ResponseEntity<String> displayCategory(@RequestParam String id,
@RequestParam String value) {
Optional<ShopItem> shopItem = shopService.changeCategory(id,value);
Optional<ShopItem> shopItem = shopService.changeCategory(id, value);

if (shopItem.isPresent()) {
return ResponseEntity.ok().build();
Expand All @@ -154,7 +159,7 @@ public ResponseEntity<String> displayCategory(@RequestParam String id,
@PostMapping("/settings/item/price")
public ResponseEntity<String> price(@RequestParam String id,
@RequestParam String value) {
Optional<ShopItem> shopItem = shopService.changePrice(id,value);
Optional<ShopItem> shopItem = shopService.changePrice(id, value);

if (shopItem.isPresent()) {
return ResponseEntity.ok().build();
Expand All @@ -180,21 +185,17 @@ public ResponseEntity<String> setDisplayImage(@RequestParam String id,

@PostMapping("/settings/item/enable")
public ResponseEntity<String> enable(@RequestParam String id) {
Optional<ShopItem> item = itemRepository.findById(id);
if (item.isPresent()) {
item.get().setEnabled(true);
itemRepository.save(item.get());
Optional<ShopItem> shopItem = shopService.enable(id);
if (shopItem.isPresent()) {
return ResponseEntity.ok().build();
}
return ResponseEntity.badRequest().build();
}

@PostMapping("/settings/item/disable")
public ResponseEntity<String> disable(@RequestParam String id) {
Optional<ShopItem> item = itemRepository.findById(id);
if (item.isPresent()) {
item.get().setEnabled(false);
itemRepository.save(item.get());
Optional<ShopItem> shopItem = shopService.disable(id);
if (shopItem.isPresent()) {
return ResponseEntity.ok().build();
}
return ResponseEntity.badRequest().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.unipassau.fim.fsinfo.prost.data.dto.ShopItemHistoryEntryDTO;
import de.unipassau.fim.fsinfo.prost.security.CustomUserDetailsContextMapper.CustomUserDetails;
import de.unipassau.fim.fsinfo.prost.service.ShopHistoryService;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -32,7 +33,13 @@ public Page<ShopItemHistoryEntryDTO> getTransactions(
@RequestParam(defaultValue = "0") int p,
@RequestParam(defaultValue = "10") int s,
@RequestParam(required = false) String receiverId) {
return shopHistoryService.getHistory(Math.max(0, p), Math.max(1, s), receiverId);
if (receiverId == null) {
return shopHistoryService.getHistory(Math.max(0, p), Math.min(Math.max(1, s), 100),
Optional.empty());
} else {
return shopHistoryService.getHistory(Math.max(0, p), Math.min(Math.max(1, s), 100),
Optional.of(receiverId));
}
}

/**
Expand All @@ -45,9 +52,12 @@ public Page<ShopItemHistoryEntryDTO> getPersonalTransactions(
@RequestParam(defaultValue = "0") int p,
@RequestParam(defaultValue = "10") int s,
Authentication authentication) {
if (authentication == null) {
return Page.empty();
}
CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

return shopHistoryService.getHistory(Math.max(0, p), Math.max(1, s),
userDetails.getUsername());
return shopHistoryService.getHistory(Math.max(0, p), Math.min(Math.max(1, s), 100),
Optional.of(userDetails.getUsername()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public TransactionController(TransactionService transactionService) {
@PostMapping("/change")
public ResponseEntity<BigDecimal> balance(@RequestParam String id,
@RequestParam String value, Authentication authentication) {
if (authentication == null || value == null || id == null) {
return ResponseEntity.badRequest().build();
}

CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

try {
Expand All @@ -50,6 +54,10 @@ public ResponseEntity<BigDecimal> balance(@RequestParam String id,
@PostMapping("/deposit")
public ResponseEntity<BigDecimal> deposit(@RequestParam String id,
@RequestParam String value, Authentication authentication) {
if (authentication == null || value == null || id == null) {
return ResponseEntity.badRequest().build();
}

CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

try {
Expand Down Expand Up @@ -77,7 +85,8 @@ public Page<TransactionEntry> getTransactions(
@RequestParam(defaultValue = "0") int p,
@RequestParam(defaultValue = "10") int s,
@RequestParam(required = false) String receiverId) {
return transactionService.getTransactions(Math.max(0, p), Math.max(1, s), receiverId);
return transactionService.getTransactions(Math.max(0, p), Math.min(Math.max(1, s), 100),
receiverId);
}

/**
Expand All @@ -90,9 +99,13 @@ public Page<TransactionEntry> getPersonalTransactions(
@RequestParam(defaultValue = "0") int p,
@RequestParam(defaultValue = "10") int s,
Authentication authentication) {
if (authentication == null) {
return Page.empty();
}

CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

return transactionService.getPersonalTransactions(Math.max(0, p), Math.max(1, s),
return transactionService.getPersonalTransactions(Math.max(0, p), Math.min(Math.max(1, s), 100),
userDetails.getUsername());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.unipassau.fim.fsinfo.prost.data.dao.ProstUser;
import de.unipassau.fim.fsinfo.prost.security.CustomUserDetailsContextMapper.CustomUserDetails;
import de.unipassau.fim.fsinfo.prost.service.TransactionService;
import de.unipassau.fim.fsinfo.prost.service.UserService;
import java.util.List;
import java.util.Optional;
Expand All @@ -22,12 +21,10 @@
public class UserController {

private final UserService userService;
private final TransactionService transactionService;

@Autowired
public UserController(UserService userService, TransactionService transactionService) {
public UserController(UserService userService) {
this.userService = userService;
this.transactionService = transactionService;
}

/**
Expand All @@ -43,6 +40,9 @@ public ResponseEntity<List<ProstUser>> list(@RequestParam(required = false) Stri

@GetMapping("/me")
public ResponseEntity<ProstUser> me(Authentication authentication) {
if (authentication == null) {
return ResponseEntity.badRequest().build();
}
CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();

Optional<List<ProstUser>> users = userService.info(userDetails.getUsername());
Expand All @@ -55,7 +55,11 @@ public ResponseEntity<ProstUser> create(@RequestBody ProstUser userTemplate) {

Optional<ProstUser> user = userService.createUser(userTemplate.getId(),
userTemplate.getDisplayName(),
userTemplate.getEmail());
userTemplate.getEmail(), true);

if (user.isPresent() && userTemplate.getTotalSpent() != null) {
userService.setMoneySpent(user.get().getId(), userTemplate.getTotalSpent().toString());
}

return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.badRequest().build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.unipassau.fim.fsinfo.prost.data;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataFilter {

private static final String EMAIL_PATTERN = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\\.+[a-zA-Z0-9.-]+$";
final static int MAX_NAME_LENGTH = 30;

public static boolean isValidString(String value, String name) {
if (value == null || value.isBlank()) {
System.out.println("[DF] :: " + name + " is empty");
return false;
}
if (value.length() > MAX_NAME_LENGTH) {
System.out.println("[DF] :: " + name + " size to large");
return false;
}
return true;
}

/**
* Filters all kind of ids that have to be readable to be lowercase and without spaces
*
* @param id the previous id
* @return the filtered id
*/
public static String filterNameId(String id) {
StringBuilder filtered = new StringBuilder();
for (char c : id.toLowerCase().toCharArray()) {
if (Character.isLowerCase(c) || Character.isDigit(c)) {
filtered.append(c);
}
}

return filtered.toString();
}

public static boolean isValidEmail(String email) {
if (email == null) {
return false;
}

Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}

public static String formatMoney(BigDecimal amount) {
if (amount == null) {
amount = new BigDecimal(0);
}
DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.GERMANY);
df.setMinimumFractionDigits(2); // Ensure two decimal places
df.setMaximumFractionDigits(2); // Ensure two decimal places
return df.format(amount);
}

}

This file was deleted.

Loading
Loading