package zw.qantra.tm.domain.controllers; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import zw.qantra.tm.domain.dtos.erp.VelocityAccountDto; import zw.qantra.tm.domain.dtos.erp.VelocityStatementDto; 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 @RequestMapping("/accounts") @RequiredArgsConstructor public class AccountController { private final VelocityAccountService velocityAccountService; private final WorkspaceService workspaceService; @GetMapping("/{workspaceId}/balance/{currency}") public ResponseEntity getAccount( @PathVariable UUID workspaceId, @PathVariable String currency ) { try { Workspace workspace = workspaceService.getWorkspace(workspaceId) .orElseThrow(() -> new IllegalArgumentException("Workspace not found")); String currencyPhoneConcat = currency + workspace.getPhone(); VelocityAccountDto account = velocityAccountService.getAccountByPhone(currencyPhoneConcat); return ResponseEntity.ok(account); } catch (Exception e) { return ResponseEntity.badRequest().body(Map.of("error", e.getMessage())); } } @GetMapping("/{workspaceId}/statement/{currency}") public ResponseEntity getStatement( @PathVariable UUID workspaceId, @PathVariable String currency, @RequestParam String startDate, @RequestParam String endDate) { try { Workspace workspace = workspaceService.getWorkspace(workspaceId) .orElseThrow(() -> new IllegalArgumentException("Workspace not found")); String currencyPhoneConcat = currency + workspace.getPhone(); VelocityStatementDto statement = velocityAccountService.getStatementByPhone( currencyPhoneConcat, startDate, endDate); return ResponseEntity.ok(statement); } catch (Exception e) { return ResponseEntity.badRequest().body(Map.of("error", e.getMessage())); } } }