completed migration from user to workspace
This commit is contained in:
@@ -10,6 +10,7 @@ import zw.qantra.tm.domain.models.Workspace;
|
|||||||
import zw.qantra.tm.domain.services.VelocityAccountService;
|
import zw.qantra.tm.domain.services.VelocityAccountService;
|
||||||
import zw.qantra.tm.domain.services.WorkspaceService;
|
import zw.qantra.tm.domain.services.WorkspaceService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -21,7 +22,7 @@ public class AccountController {
|
|||||||
private final WorkspaceService workspaceService;
|
private final WorkspaceService workspaceService;
|
||||||
|
|
||||||
@GetMapping("/{workspaceId}/balance/{currency}")
|
@GetMapping("/{workspaceId}/balance/{currency}")
|
||||||
public ResponseEntity<VelocityAccountDto> getAccount(
|
public ResponseEntity getAccount(
|
||||||
@PathVariable UUID workspaceId,
|
@PathVariable UUID workspaceId,
|
||||||
@PathVariable String currency
|
@PathVariable String currency
|
||||||
) {
|
) {
|
||||||
@@ -32,12 +33,12 @@ public class AccountController {
|
|||||||
VelocityAccountDto account = velocityAccountService.getAccountByPhone(currencyPhoneConcat);
|
VelocityAccountDto account = velocityAccountService.getAccountByPhone(currencyPhoneConcat);
|
||||||
return ResponseEntity.ok(account);
|
return ResponseEntity.ok(account);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{workspaceId}/statement/{currency}")
|
@GetMapping("/{workspaceId}/statement/{currency}")
|
||||||
public ResponseEntity<VelocityStatementDto> getStatement(
|
public ResponseEntity getStatement(
|
||||||
@PathVariable UUID workspaceId,
|
@PathVariable UUID workspaceId,
|
||||||
@PathVariable String currency,
|
@PathVariable String currency,
|
||||||
@RequestParam String startDate,
|
@RequestParam String startDate,
|
||||||
@@ -50,7 +51,7 @@ public class AccountController {
|
|||||||
currencyPhoneConcat, startDate, endDate);
|
currencyPhoneConcat, startDate, endDate);
|
||||||
return ResponseEntity.ok(statement);
|
return ResponseEntity.ok(statement);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package zw.qantra.tm.domain.controllers;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.kaczmarzyk.spring.data.jpa.domain.Equal;
|
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.And;
|
||||||
import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec;
|
import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@@ -91,6 +92,9 @@ public class GroupBatchController {
|
|||||||
@And({
|
@And({
|
||||||
@Spec(path = "groupBatchId", defaultVal = "null", spec = Equal.class),
|
@Spec(path = "groupBatchId", defaultVal = "null", spec = Equal.class),
|
||||||
@Spec(path = "recipientId", 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<GroupBatchItem> spec, Pageable pageable) {
|
}) Specification<GroupBatchItem> spec, Pageable pageable) {
|
||||||
return ResponseEntity.ok(groupBatchService.getBatchItems(spec, pageable));
|
return ResponseEntity.ok(groupBatchService.getBatchItems(spec, pageable));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,15 +57,19 @@ public class RecipientGroupController {
|
|||||||
@RequestParam(value = "description", required = false) String description,
|
@RequestParam(value = "description", required = false) String description,
|
||||||
@RequestParam(value = "requestedBy", required = false) String requestedBy,
|
@RequestParam(value = "requestedBy", required = false) String requestedBy,
|
||||||
@RequestParam(value = "currency", required = false) String currency,
|
@RequestParam(value = "currency", required = false) String currency,
|
||||||
@RequestParam("workspaceId") UUID workspaceId) {
|
@RequestParam("userId") UUID userId,
|
||||||
|
@RequestParam("workspaceId") UUID workspaceId
|
||||||
|
) {
|
||||||
|
|
||||||
GroupCreateFromFileRequest request = new GroupCreateFromFileRequest();
|
GroupCreateFromFileRequest request = new GroupCreateFromFileRequest();
|
||||||
request.setGroupName(groupName.trim());
|
request.setGroupName(groupName.trim());
|
||||||
request.setDescription(description.trim());
|
request.setDescription(description.trim());
|
||||||
request.setRequestedBy(requestedBy);
|
request.setRequestedBy(requestedBy);
|
||||||
request.setCurrency(currency);
|
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}")
|
@PutMapping("/update/{groupId}")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.util.UUID;
|
|||||||
public class GroupBatchCreateRequest {
|
public class GroupBatchCreateRequest {
|
||||||
private UUID recipientGroupId;
|
private UUID recipientGroupId;
|
||||||
private UUID workspaceId;
|
private UUID workspaceId;
|
||||||
|
private String userId;
|
||||||
private String description;
|
private String description;
|
||||||
private String requestedBy;
|
private String requestedBy;
|
||||||
private String currency;
|
private String currency;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
|||||||
import zw.qantra.tm.domain.models.Transaction;
|
import zw.qantra.tm.domain.models.Transaction;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
@@ -18,5 +19,7 @@ public class GroupCreateFromFileRequest {
|
|||||||
private String paymentProcessorLabel;
|
private String paymentProcessorLabel;
|
||||||
private String paymentProcessorName;
|
private String paymentProcessorName;
|
||||||
private String paymentProcessorImage;
|
private String paymentProcessorImage;
|
||||||
|
private UUID userId;
|
||||||
|
private UUID workspaceId;
|
||||||
private Transaction transactionTemplate;
|
private Transaction transactionTemplate;
|
||||||
}
|
}
|
||||||
@@ -78,6 +78,7 @@ public class GroupBatchService {
|
|||||||
|
|
||||||
GroupBatch batch = GroupBatch.builder()
|
GroupBatch batch = GroupBatch.builder()
|
||||||
.recipientGroupId(group.getId())
|
.recipientGroupId(group.getId())
|
||||||
|
.userId(request.getUserId())
|
||||||
.workspaceId(request.getWorkspaceId())
|
.workspaceId(request.getWorkspaceId())
|
||||||
.description(request.getDescription())
|
.description(request.getDescription())
|
||||||
.requestedBy(request.getRequestedBy())
|
.requestedBy(request.getRequestedBy())
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class GroupBatchWorkflowService {
|
|||||||
BigDecimal total = confirmedItems.stream()
|
BigDecimal total = confirmedItems.stream()
|
||||||
.map(item -> item.getAmount() == null ? BigDecimal.ZERO : item.getAmount())
|
.map(item -> item.getAmount() == null ? BigDecimal.ZERO : item.getAmount())
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.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 transaction = new Transaction();
|
||||||
transaction.setId(null);
|
transaction.setId(null);
|
||||||
@@ -113,6 +113,7 @@ public class GroupBatchWorkflowService {
|
|||||||
transaction.setAmount(total);
|
transaction.setAmount(total);
|
||||||
transaction.setTotalAmount(total);
|
transaction.setTotalAmount(total);
|
||||||
transaction.setReference("batch-" + batch.getId());
|
transaction.setReference("batch-" + batch.getId());
|
||||||
|
transaction.setUserId(batch.getUserId());
|
||||||
transaction.setWorkspaceId(batch.getWorkspaceId());
|
transaction.setWorkspaceId(batch.getWorkspaceId());
|
||||||
transaction.setPaymentProcessorLabel(batch.getPaymentProcessorLabel());
|
transaction.setPaymentProcessorLabel(batch.getPaymentProcessorLabel());
|
||||||
transaction.setPaymentProcessorName(batch.getPaymentProcessorName());
|
transaction.setPaymentProcessorName(batch.getPaymentProcessorName());
|
||||||
@@ -205,7 +206,7 @@ public class GroupBatchWorkflowService {
|
|||||||
private void confirmItem(GroupBatch batch, GroupBatchItem item) {
|
private void confirmItem(GroupBatch batch, GroupBatchItem item) {
|
||||||
GroupBatchItem mutableItem = groupBatchItemRepository.findById(item.getId()).orElse(item);
|
GroupBatchItem mutableItem = groupBatchItemRepository.findById(item.getId()).orElse(item);
|
||||||
try {
|
try {
|
||||||
User user = userService.getUserRepository().findByUsername(SecurityUtils.getCurrentUsername()).orElseThrow();
|
User user = userService.getUserRepository().findById(UUID.fromString(batch.getUserId())).orElseThrow();
|
||||||
Transaction transaction = new Transaction();
|
Transaction transaction = new Transaction();
|
||||||
transaction.setId(null);
|
transaction.setId(null);
|
||||||
transaction.setDebitPhone(user.getPhone());
|
transaction.setDebitPhone(user.getPhone());
|
||||||
@@ -219,6 +220,7 @@ public class GroupBatchWorkflowService {
|
|||||||
transaction.setProviderImage(item.getProviderImage());
|
transaction.setProviderImage(item.getProviderImage());
|
||||||
transaction.setProviderLabel(item.getProviderLabel());
|
transaction.setProviderLabel(item.getProviderLabel());
|
||||||
|
|
||||||
|
transaction.setUserId(batch.getUserId());
|
||||||
transaction.setWorkspaceId(batch.getWorkspaceId());
|
transaction.setWorkspaceId(batch.getWorkspaceId());
|
||||||
transaction.setType(RequestType.CONFIRM);
|
transaction.setType(RequestType.CONFIRM);
|
||||||
transaction.setPartyType(PartyType.BATCH);
|
transaction.setPartyType(PartyType.BATCH);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class RecipientGroupService {
|
|||||||
* 5. Return the batch + any row-level errors
|
* 5. Return the batch + any row-level errors
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public GroupCreateFromFileResult createFromFile(MultipartFile file, GroupCreateFromFileRequest request, UUID workspaceId) {
|
public GroupCreateFromFileResult createFromFile(MultipartFile file, GroupCreateFromFileRequest request) {
|
||||||
ParseResult parseResult = parseCsv(file);
|
ParseResult parseResult = parseCsv(file);
|
||||||
|
|
||||||
if(!parseResult.parseErrors.isEmpty()) {
|
if(!parseResult.parseErrors.isEmpty()) {
|
||||||
@@ -77,7 +77,8 @@ public class RecipientGroupService {
|
|||||||
.name(row.name)
|
.name(row.name)
|
||||||
.account(row.account)
|
.account(row.account)
|
||||||
.phoneNumber(row.phone)
|
.phoneNumber(row.phone)
|
||||||
.workspaceId(workspaceId)
|
.userId(request.getUserId().toString())
|
||||||
|
.workspaceId(request.getWorkspaceId())
|
||||||
.build();
|
.build();
|
||||||
recipients.add(recipient);
|
recipients.add(recipient);
|
||||||
}
|
}
|
||||||
@@ -86,15 +87,16 @@ public class RecipientGroupService {
|
|||||||
RecipientGroup group = RecipientGroup.builder()
|
RecipientGroup group = RecipientGroup.builder()
|
||||||
.name(request.getGroupName())
|
.name(request.getGroupName())
|
||||||
.description(request.getDescription())
|
.description(request.getDescription())
|
||||||
.workspaceId(workspaceId)
|
.userId(request.getUserId().toString())
|
||||||
|
.workspaceId(request.getWorkspaceId())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
RecipientGroup savedGroup = recipientGroupRepository.save(group);
|
RecipientGroup savedGroup = recipientGroupRepository.save(group);
|
||||||
|
|
||||||
List<RecipientGroupMember> members = addMembers(savedGroup.getId(), workspaceId, recipients);
|
List<RecipientGroupMember> members = addMembers(savedGroup.getId(), request.getWorkspaceId(), recipients);
|
||||||
|
|
||||||
// Step 3: create group batch (inline to avoid circular dependency with GroupBatchService)
|
// 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
|
// Step 4: update batch items with bill/provider fields from CSV
|
||||||
List<GroupBatchItem> batchItems = groupBatchItemRepository.findAllByGroupBatchId(batch.getId());
|
List<GroupBatchItem> batchItems = groupBatchItemRepository.findAllByGroupBatchId(batch.getId());
|
||||||
@@ -136,7 +138,7 @@ public class RecipientGroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the updated batch + errors
|
// 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"));
|
.orElseThrow(() -> new ApiException("Batch not found after creation"));
|
||||||
|
|
||||||
return GroupCreateFromFileResult.builder()
|
return GroupCreateFromFileResult.builder()
|
||||||
@@ -157,6 +159,7 @@ public class RecipientGroupService {
|
|||||||
List<RecipientGroupMember> members) {
|
List<RecipientGroupMember> members) {
|
||||||
GroupBatch batch = GroupBatch.builder()
|
GroupBatch batch = GroupBatch.builder()
|
||||||
.recipientGroupId(recipientGroupId)
|
.recipientGroupId(recipientGroupId)
|
||||||
|
.userId(request.getUserId().toString())
|
||||||
.workspaceId(workspaceId)
|
.workspaceId(workspaceId)
|
||||||
.description(request.getDescription())
|
.description(request.getDescription())
|
||||||
.requestedBy(request.getRequestedBy())
|
.requestedBy(request.getRequestedBy())
|
||||||
|
|||||||
@@ -291,6 +291,11 @@ public class VelocityPaymentService {
|
|||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void updateSalesOrderWorkflow(Transaction transaction) {
|
public void updateSalesOrderWorkflow(Transaction transaction) {
|
||||||
|
if(transaction.getOrderTrace() == null) {
|
||||||
|
log.error("Order trace is null for transaction: {}", transaction.getTrace());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LinkedHashMap response = makeRequest(
|
LinkedHashMap response = makeRequest(
|
||||||
HttpMethod.PUT,
|
HttpMethod.PUT,
|
||||||
VELOCITY_API_UPDATE_WORKFLOW_PATH.replace("{traceId}", transaction.getOrderTrace()),
|
VELOCITY_API_UPDATE_WORKFLOW_PATH.replace("{traceId}", transaction.getOrderTrace()),
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class ProviderSeeder implements Seeder {
|
|||||||
.requiresAmount(false)
|
.requiresAmount(false)
|
||||||
.requiresPhone(true)
|
.requiresPhone(true)
|
||||||
.requiresProducts(true)
|
.requiresProducts(true)
|
||||||
.requiresProducts(false)
|
.requiresProducts(true)
|
||||||
.priority(4)
|
.priority(4)
|
||||||
.meta("{\"hotProductId\": \"16\"}")
|
.meta("{\"hotProductId\": \"16\"}")
|
||||||
.uid(Utils.getUid())
|
.uid(Utils.getUid())
|
||||||
|
|||||||
Reference in New Issue
Block a user