completed initial charge logic
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package zw.qantra.tm.domain.controllers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import zw.qantra.tm.domain.enums.ChargeConditionType;
|
||||
import zw.qantra.tm.domain.enums.ChargeLabelEnum;
|
||||
import zw.qantra.tm.domain.enums.CurrencyType;
|
||||
import zw.qantra.tm.domain.models.Charge;
|
||||
import zw.qantra.tm.domain.models.ChargeCondition;
|
||||
import zw.qantra.tm.domain.services.ChargeConditionService;
|
||||
import zw.qantra.tm.domain.services.ChargeService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/configs")
|
||||
@RequiredArgsConstructor
|
||||
public class ConfigController {
|
||||
private final ChargeConditionService chargeConditionService;
|
||||
private final ChargeService chargeService;
|
||||
|
||||
@GetMapping("/charges")
|
||||
public ResponseEntity charges(){
|
||||
List<ChargeCondition> chargeConditions = Arrays.asList(
|
||||
ChargeCondition.builder()
|
||||
.name("Ecocash Gateway")
|
||||
.type(ChargeConditionType.GATEWAY)
|
||||
.codes("ECOCASH")
|
||||
.build(),
|
||||
ChargeCondition.builder()
|
||||
.name("Steward Gateway")
|
||||
.type(ChargeConditionType.GATEWAY)
|
||||
.codes("STEWARD")
|
||||
.build(),
|
||||
ChargeCondition.builder()
|
||||
.name("Mastercard Gateway")
|
||||
.type(ChargeConditionType.GATEWAY)
|
||||
.codes("MPGS")
|
||||
.build()
|
||||
);
|
||||
chargeService.getChargeRepository().deleteAll();
|
||||
chargeConditionService.getChargeConditionRepository().deleteAll();
|
||||
chargeConditionService.getChargeConditionRepository().saveAll(chargeConditions);
|
||||
|
||||
List<Charge> charges = Arrays.asList(
|
||||
Charge.builder()
|
||||
.description("Gateway fee")
|
||||
.chargeLabel(ChargeLabelEnum.GATEWAY_FEE)
|
||||
.currency(CurrencyType.USD)
|
||||
.percentageRate(new BigDecimal("1"))
|
||||
.includes(new HashSet<>() {{
|
||||
add(chargeConditions.get(0));
|
||||
add(chargeConditions.get(1));
|
||||
add(chargeConditions.get(2));
|
||||
}})
|
||||
.build(),
|
||||
Charge.builder()
|
||||
.description("Tax")
|
||||
.chargeLabel(ChargeLabelEnum.TAX)
|
||||
.currency(CurrencyType.USD)
|
||||
.percentageRate(new BigDecimal("2"))
|
||||
.max(new BigDecimal("10150"))
|
||||
.minimumAmount(new BigDecimal("5"))
|
||||
.maximumAmount(new BigDecimal("500000"))
|
||||
.includes(new HashSet<>() {{
|
||||
add(chargeConditions.get(0));
|
||||
add(chargeConditions.get(1));
|
||||
add(chargeConditions.get(2));
|
||||
}})
|
||||
.build()
|
||||
);
|
||||
|
||||
chargeService.getChargeRepository().saveAll(charges);
|
||||
|
||||
return ResponseEntity.ok("Charges configuration complete");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package zw.qantra.tm.domain.controllers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import zw.qantra.tm.domain.models.Provider;
|
||||
import zw.qantra.tm.domain.services.ProviderService;
|
||||
import zw.qantra.tm.rest.ApiResponse;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/providers")
|
||||
@RequiredArgsConstructor
|
||||
public class ProviderController {
|
||||
|
||||
private final ProviderService providerService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity getProviders() {
|
||||
return ApiResponse.ok(providerService.getProviders());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/products")
|
||||
public ResponseEntity getProducts(@PathVariable UUID id) {
|
||||
return ApiResponse.ok(providerService.getProviderProducts(id));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity getProvider(@PathVariable UUID id) {
|
||||
return providerService.getProvider(id)
|
||||
.map(ApiResponse::ok)
|
||||
.orElse(ApiResponse.notFound());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity createProvider(@RequestBody Provider provider) {
|
||||
return ApiResponse.ok(providerService.createProvider(provider));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity updateProvider(@PathVariable UUID id, @RequestBody Provider provider) {
|
||||
Provider updatedProvider = providerService.updateProvider(id, provider);
|
||||
if (updatedProvider != null) {
|
||||
return ApiResponse.ok(updatedProvider);
|
||||
}
|
||||
return ApiResponse.notFound();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity deleteProvider(@PathVariable UUID id) {
|
||||
if (providerService.deleteProvider(id)) {
|
||||
return ApiResponse.ok("Provider deleted successfully");
|
||||
}
|
||||
return ApiResponse.notFound();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,53 @@
|
||||
package zw.qantra.tm.domain.controllers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import zw.qantra.tm.domain.services.TransactionService;
|
||||
import zw.qantra.tm.domain.models.Transaction;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/transaction")
|
||||
@RequiredArgsConstructor
|
||||
public class TransactonController {
|
||||
@PostMapping()
|
||||
public ResponseEntity post(@RequestBody Object transactionRequest) {
|
||||
return ResponseEntity.ok("Transaction endpoint is working");
|
||||
|
||||
private final TransactionService transactionService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Transaction>> getAll() {
|
||||
return ResponseEntity.ok(transactionService.getTransactionRepository().findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Transaction> getById(@PathVariable UUID id) {
|
||||
return transactionService.getTransactionRepository().findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Transaction> create(@RequestBody Transaction transaction) {
|
||||
return ResponseEntity.ok(transactionService.execute(transaction));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Transaction> update(@PathVariable UUID id, @RequestBody Transaction transaction) {
|
||||
if (!transactionService.getTransactionRepository().existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
transaction.setId(id);
|
||||
return ResponseEntity.ok(transactionService.execute(transaction));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable UUID id) {
|
||||
if (!transactionService.getTransactionRepository().existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
transactionService.getTransactionRepository().deleteById(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user