Skip to content

Commit

Permalink
feat: support specify user in buy-product api (#94)
Browse files Browse the repository at this point in the history
* feat: support specify user in buy-product api

* fix: fix code format
  • Loading branch information
dacongda authored Oct 15, 2024
1 parent 9361a85 commit e53c5be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/casbin/casdoor/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public CasdoorResponse<String, Object> updateProduct(Product product) throws IOE
return modifyProduct(ProductOperations.UPDATE_PRODUCT, product, null);
}

public Product buyProduct(String name, String providerName) throws IOException {
public Product buyProduct(String name, String providerName, String userName) throws IOException {
java.util.Map<String, String> queryMap = Map.of(
"id", config.organizationName + "/" + name,
"providerName", providerName
"providerName", providerName,
"userName", userName
);
CasdoorResponse<Product, Object> response = doPost("buy-product", queryMap, "", new TypeReference<CasdoorResponse<Product, Object>>() {
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/casbin/casdoor/ProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -47,6 +48,8 @@ public void testProduct() {
0,
"Published"
);
product.providers = new ArrayList<>();
product.providers.add("provider_payment_dummy");
assertDoesNotThrow(() -> productService.addProduct(product));

// Get all objects, check if our added object is inside the list
Expand Down Expand Up @@ -89,7 +92,7 @@ public void testProduct() {
// Test the buyProduct function
Product boughtProduct;
try {
boughtProduct = productService.buyProduct(name, "provider_payment_paypal");
boughtProduct = productService.buyProduct(name, "provider_payment_dummy", "admin");
} catch (Exception e) {
String errorMessage = e.getMessage();
if (errorMessage.contains("The user") && errorMessage.contains("doesn't exist")) {
Expand Down

0 comments on commit e53c5be

Please sign in to comment.