Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
call function
Browse files Browse the repository at this point in the history
  • Loading branch information
tklein1801 committed Nov 28, 2023
1 parent 3cc850c commit 5fce5b8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.budgetbuddy.backend.transaction;

public enum DailyTransactionType {
INCOME, SPENDINGS, BALANCE
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public Transaction(User owner, Category category, PaymentMethod paymentMethod, D
this.createdAt = new Date();
}

@Data
public static class DailyTransaction {
private Date date;
private Double amount;
}

@Data
public static class Create {
private UUID owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,30 @@ public ResponseEntity<ApiResponse<Transaction>> deleteTransaction(@RequestBody T
.status(HttpStatus.OK)
.body(new ApiResponse<>(transaction));
}

@GetMapping("/test")
public ResponseEntity<ApiResponse<String>> test() {
UUID uuid = UUID.fromString("c9e470be-8e83-4dd7-b70b-9fd79898e896");
return ResponseEntity
.status(200)
.body(new ApiResponse<>(transactionRepository.test2(uuid)));
}

@GetMapping("/test2")
public ResponseEntity<ApiResponse<List<Transaction.DailyTransaction>>> test1() {
UUID uuid = UUID.fromString("c9e470be-8e83-4dd7-b70b-9fd79898e896");
List<Object[]> test = transactionRepository.test1(uuid);

List<Transaction.DailyTransaction> dailyTransactions = new ArrayList<>();
for (Object[] row : test) {
Transaction.DailyTransaction dailyTransaction = new Transaction.DailyTransaction();
dailyTransaction.setDate((Date) row[0]);
dailyTransaction.setAmount((Double) row[1]);
dailyTransactions.add(dailyTransaction);
}

return ResponseEntity
.status(200)
.body(new ApiResponse<>(dailyTransactions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

import de.budgetbuddy.backend.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

public interface TransactionRepository extends JpaRepository<Transaction, Long> {
List<Transaction> findAllByOwner(User owner);
List<Transaction> findAllByOwnerOrderByProcessedAtDesc(User owner);
// @Procedure(name = "f_get_daily_transactions")
// List<Transaction.DailyTransaction> getDailyTransactions(
// @Param("start_date") Date startDate,
// @Param("end_date") Date endDate,
// @Param("requested_data") DailyTransactionType requested,
// @Param("user_id") UUID uuid);

@Query(value = "select f_get_daily_transactions('2023-10-01', '2023-12-01', 'SPENDINGS', ?1)", nativeQuery = true)
List<Object[]> test1(UUID uuid);

@Query(value = "select f_demo_function(?1)", nativeQuery = true)
String test2(UUID uuid);
}

0 comments on commit 5fce5b8

Please sign in to comment.