From 299cdf6e35c872e15c7e41db336fb0d378eeda7e Mon Sep 17 00:00:00 2001 From: Vusa Date: Mon, 22 Jun 2026 22:11:20 +0200 Subject: [PATCH] completed migration from user to workspace --- .../tm/domain/controllers/AccountController.java | 9 +++++---- .../domain/controllers/GroupBatchController.java | 4 ++++ .../controllers/RecipientGroupController.java | 8 ++++++-- .../tm/domain/dtos/GroupBatchCreateRequest.java | 1 + .../domain/dtos/GroupCreateFromFileRequest.java | 3 +++ .../tm/domain/services/GroupBatchService.java | 1 + .../services/GroupBatchWorkflowService.java | 6 ++++-- .../tm/domain/services/RecipientGroupService.java | 15 +++++++++------ .../domain/services/VelocityPaymentService.java | 5 +++++ .../java/zw/qantra/tm/seeders/ProviderSeeder.java | 2 +- 10 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/zw/qantra/tm/domain/controllers/AccountController.java b/src/main/java/zw/qantra/tm/domain/controllers/AccountController.java index c5aef0d..3a68d0f 100644 --- a/src/main/java/zw/qantra/tm/domain/controllers/AccountController.java +++ b/src/main/java/zw/qantra/tm/domain/controllers/AccountController.java @@ -10,6 +10,7 @@ import zw.qantra.tm.domain.models.Workspace; import zw.qantra.tm.domain.services.VelocityAccountService; import zw.qantra.tm.domain.services.WorkspaceService; +import java.util.Map; import java.util.UUID; @RestController @@ -21,7 +22,7 @@ public class AccountController { private final WorkspaceService workspaceService; @GetMapping("/{workspaceId}/balance/{currency}") - public ResponseEntity getAccount( + public ResponseEntity getAccount( @PathVariable UUID workspaceId, @PathVariable String currency ) { @@ -32,12 +33,12 @@ public class AccountController { VelocityAccountDto account = velocityAccountService.getAccountByPhone(currencyPhoneConcat); return ResponseEntity.ok(account); } catch (Exception e) { - return ResponseEntity.badRequest().build(); + return ResponseEntity.badRequest().body(Map.of("error", e.getMessage())); } } @GetMapping("/{workspaceId}/statement/{currency}") - public ResponseEntity getStatement( + public ResponseEntity getStatement( @PathVariable UUID workspaceId, @PathVariable String currency, @RequestParam String startDate, @@ -50,7 +51,7 @@ public class AccountController { currencyPhoneConcat, startDate, endDate); return ResponseEntity.ok(statement); } catch (Exception e) { - return ResponseEntity.badRequest().build(); + return ResponseEntity.badRequest().body(Map.of("error", e.getMessage())); } } } \ No newline at end of file diff --git a/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java b/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java index 9fdd1ee..d450fd0 100644 --- a/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java +++ b/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java @@ -2,6 +2,7 @@ package zw.qantra.tm.domain.controllers; import lombok.RequiredArgsConstructor; import net.kaczmarzyk.spring.data.jpa.domain.Equal; +import net.kaczmarzyk.spring.data.jpa.domain.EqualIgnoreCase; import net.kaczmarzyk.spring.data.jpa.web.annotation.And; import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec; import org.springframework.data.domain.Pageable; @@ -91,6 +92,9 @@ public class GroupBatchController { @And({ @Spec(path = "groupBatchId", defaultVal = "null", spec = Equal.class), @Spec(path = "recipientId", spec = Equal.class), + @Spec(path = "recipientName", spec = EqualIgnoreCase.class), + @Spec(path = "recipientAccount", spec = Equal.class), + @Spec(path = "status", spec = Equal.class), }) Specification spec, Pageable pageable) { return ResponseEntity.ok(groupBatchService.getBatchItems(spec, pageable)); } diff --git a/src/main/java/zw/qantra/tm/domain/controllers/RecipientGroupController.java b/src/main/java/zw/qantra/tm/domain/controllers/RecipientGroupController.java index 4800e2b..51d1e84 100644 --- a/src/main/java/zw/qantra/tm/domain/controllers/RecipientGroupController.java +++ b/src/main/java/zw/qantra/tm/domain/controllers/RecipientGroupController.java @@ -57,15 +57,19 @@ public class RecipientGroupController { @RequestParam(value = "description", required = false) String description, @RequestParam(value = "requestedBy", required = false) String requestedBy, @RequestParam(value = "currency", required = false) String currency, - @RequestParam("workspaceId") UUID workspaceId) { + @RequestParam("userId") UUID userId, + @RequestParam("workspaceId") UUID workspaceId + ) { GroupCreateFromFileRequest request = new GroupCreateFromFileRequest(); request.setGroupName(groupName.trim()); request.setDescription(description.trim()); request.setRequestedBy(requestedBy); request.setCurrency(currency); + request.setWorkspaceId(workspaceId); + request.setUserId(userId); - return ResponseEntity.ok(recipientGroupService.createFromFile(file, request, workspaceId)); + return ResponseEntity.ok(recipientGroupService.createFromFile(file, request)); } @PutMapping("/update/{groupId}") diff --git a/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchCreateRequest.java b/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchCreateRequest.java index dbfc1c5..45af547 100644 --- a/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchCreateRequest.java +++ b/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchCreateRequest.java @@ -12,6 +12,7 @@ import java.util.UUID; public class GroupBatchCreateRequest { private UUID recipientGroupId; private UUID workspaceId; + private String userId; private String description; private String requestedBy; private String currency; diff --git a/src/main/java/zw/qantra/tm/domain/dtos/GroupCreateFromFileRequest.java b/src/main/java/zw/qantra/tm/domain/dtos/GroupCreateFromFileRequest.java index 048f0df..660bb97 100644 --- a/src/main/java/zw/qantra/tm/domain/dtos/GroupCreateFromFileRequest.java +++ b/src/main/java/zw/qantra/tm/domain/dtos/GroupCreateFromFileRequest.java @@ -5,6 +5,7 @@ import lombok.Data; import zw.qantra.tm.domain.models.Transaction; import java.math.BigDecimal; +import java.util.UUID; @Data @JsonInclude(JsonInclude.Include.NON_NULL) @@ -18,5 +19,7 @@ public class GroupCreateFromFileRequest { private String paymentProcessorLabel; private String paymentProcessorName; private String paymentProcessorImage; + private UUID userId; + private UUID workspaceId; private Transaction transactionTemplate; } \ No newline at end of file diff --git a/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java b/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java index b2a12aa..4749718 100644 --- a/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java +++ b/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java @@ -78,6 +78,7 @@ public class GroupBatchService { GroupBatch batch = GroupBatch.builder() .recipientGroupId(group.getId()) + .userId(request.getUserId()) .workspaceId(request.getWorkspaceId()) .description(request.getDescription()) .requestedBy(request.getRequestedBy()) diff --git a/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java b/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java index 2892ae6..1a76f5c 100644 --- a/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java +++ b/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java @@ -98,7 +98,7 @@ public class GroupBatchWorkflowService { BigDecimal total = confirmedItems.stream() .map(item -> item.getAmount() == null ? BigDecimal.ZERO : item.getAmount()) .reduce(BigDecimal.ZERO, BigDecimal::add); - User user = userService.getUserRepository().findByUsername(SecurityUtils.getCurrentUsername()).orElseThrow(); + User user = userService.getUserRepository().findById(UUID.fromString(batch.getUserId())).orElseThrow(); Transaction transaction = new Transaction(); transaction.setId(null); @@ -113,6 +113,7 @@ public class GroupBatchWorkflowService { transaction.setAmount(total); transaction.setTotalAmount(total); transaction.setReference("batch-" + batch.getId()); + transaction.setUserId(batch.getUserId()); transaction.setWorkspaceId(batch.getWorkspaceId()); transaction.setPaymentProcessorLabel(batch.getPaymentProcessorLabel()); transaction.setPaymentProcessorName(batch.getPaymentProcessorName()); @@ -205,7 +206,7 @@ public class GroupBatchWorkflowService { private void confirmItem(GroupBatch batch, GroupBatchItem item) { GroupBatchItem mutableItem = groupBatchItemRepository.findById(item.getId()).orElse(item); try { - User user = userService.getUserRepository().findByUsername(SecurityUtils.getCurrentUsername()).orElseThrow(); + User user = userService.getUserRepository().findById(UUID.fromString(batch.getUserId())).orElseThrow(); Transaction transaction = new Transaction(); transaction.setId(null); transaction.setDebitPhone(user.getPhone()); @@ -219,6 +220,7 @@ public class GroupBatchWorkflowService { transaction.setProviderImage(item.getProviderImage()); transaction.setProviderLabel(item.getProviderLabel()); + transaction.setUserId(batch.getUserId()); transaction.setWorkspaceId(batch.getWorkspaceId()); transaction.setType(RequestType.CONFIRM); transaction.setPartyType(PartyType.BATCH); diff --git a/src/main/java/zw/qantra/tm/domain/services/RecipientGroupService.java b/src/main/java/zw/qantra/tm/domain/services/RecipientGroupService.java index 53a04cb..6a8609c 100644 --- a/src/main/java/zw/qantra/tm/domain/services/RecipientGroupService.java +++ b/src/main/java/zw/qantra/tm/domain/services/RecipientGroupService.java @@ -55,7 +55,7 @@ public class RecipientGroupService { * 5. Return the batch + any row-level errors */ @Transactional - public GroupCreateFromFileResult createFromFile(MultipartFile file, GroupCreateFromFileRequest request, UUID workspaceId) { + public GroupCreateFromFileResult createFromFile(MultipartFile file, GroupCreateFromFileRequest request) { ParseResult parseResult = parseCsv(file); if(!parseResult.parseErrors.isEmpty()) { @@ -77,7 +77,8 @@ public class RecipientGroupService { .name(row.name) .account(row.account) .phoneNumber(row.phone) - .workspaceId(workspaceId) + .userId(request.getUserId().toString()) + .workspaceId(request.getWorkspaceId()) .build(); recipients.add(recipient); } @@ -86,15 +87,16 @@ public class RecipientGroupService { RecipientGroup group = RecipientGroup.builder() .name(request.getGroupName()) .description(request.getDescription()) - .workspaceId(workspaceId) + .userId(request.getUserId().toString()) + .workspaceId(request.getWorkspaceId()) .build(); RecipientGroup savedGroup = recipientGroupRepository.save(group); - List members = addMembers(savedGroup.getId(), workspaceId, recipients); + List members = addMembers(savedGroup.getId(), request.getWorkspaceId(), recipients); // Step 3: create group batch (inline to avoid circular dependency with GroupBatchService) - GroupBatch batch = createBatchInline(savedGroup.getId(), workspaceId, request, members); + GroupBatch batch = createBatchInline(savedGroup.getId(), request.getWorkspaceId(), request, members); // Step 4: update batch items with bill/provider fields from CSV List batchItems = groupBatchItemRepository.findAllByGroupBatchId(batch.getId()); @@ -136,7 +138,7 @@ public class RecipientGroupService { } // Return the updated batch + errors - GroupBatch resultBatch = groupBatchRepository.findByIdAndWorkspaceId(batch.getId(), workspaceId) + GroupBatch resultBatch = groupBatchRepository.findByIdAndWorkspaceId(batch.getId(), request.getWorkspaceId()) .orElseThrow(() -> new ApiException("Batch not found after creation")); return GroupCreateFromFileResult.builder() @@ -157,6 +159,7 @@ public class RecipientGroupService { List members) { GroupBatch batch = GroupBatch.builder() .recipientGroupId(recipientGroupId) + .userId(request.getUserId().toString()) .workspaceId(workspaceId) .description(request.getDescription()) .requestedBy(request.getRequestedBy()) diff --git a/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java b/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java index 5116c22..c4fb6c0 100644 --- a/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java +++ b/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java @@ -291,6 +291,11 @@ public class VelocityPaymentService { @Async public void updateSalesOrderWorkflow(Transaction transaction) { + if(transaction.getOrderTrace() == null) { + log.error("Order trace is null for transaction: {}", transaction.getTrace()); + return; + } + LinkedHashMap response = makeRequest( HttpMethod.PUT, VELOCITY_API_UPDATE_WORKFLOW_PATH.replace("{traceId}", transaction.getOrderTrace()), diff --git a/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java b/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java index d1c1b5a..079cbb6 100644 --- a/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java +++ b/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java @@ -162,7 +162,7 @@ public class ProviderSeeder implements Seeder { .requiresAmount(false) .requiresPhone(true) .requiresProducts(true) - .requiresProducts(false) + .requiresProducts(true) .priority(4) .meta("{\"hotProductId\": \"16\"}") .uid(Utils.getUid())