completed initial charge logic
This commit is contained in:
@@ -1,11 +1,87 @@
|
||||
package zw.qantra.tm.domain.services;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import zw.qantra.tm.domain.dtos.SBZProductDto;
|
||||
import zw.qantra.tm.domain.models.Provider;
|
||||
import zw.qantra.tm.domain.repositories.ChargeRepository;
|
||||
import zw.qantra.tm.domain.repositories.ProviderRepository;
|
||||
import zw.qantra.tm.rest.RestService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProviderService {
|
||||
private final ProviderRepository providerRepository;
|
||||
private final RestService restService;
|
||||
|
||||
@Value("${sbz.aggregator.url}")
|
||||
private String aggregatorUrl;
|
||||
|
||||
public ProviderRepository getProviderRepository() {
|
||||
return providerRepository;
|
||||
}
|
||||
|
||||
public List<SBZProductDto> getProviderProducts(UUID providerId) {
|
||||
String token = restService.getMerchantToken();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setBearerAuth(token);
|
||||
|
||||
LinkedHashMap response = this.restService.getAs(
|
||||
aggregatorUrl + "/merchant/aggregation/products?size=100&clientUid=" + providerId.toString(),
|
||||
headers,
|
||||
LinkedHashMap.class
|
||||
);
|
||||
|
||||
LinkedHashMap body = (LinkedHashMap) response.get("body");
|
||||
List<LinkedHashMap> content = (List<LinkedHashMap>) body.get("content");
|
||||
|
||||
List<SBZProductDto> products = new ArrayList<>();
|
||||
for (LinkedHashMap product : content) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
SBZProductDto productDto = mapper.convertValue(product, SBZProductDto.class);
|
||||
products.add(productDto);
|
||||
}
|
||||
|
||||
return products;
|
||||
}
|
||||
|
||||
public List<Provider> getProviders() {
|
||||
return providerRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<Provider> getProvider(UUID id) {
|
||||
return providerRepository.findById(id);
|
||||
}
|
||||
|
||||
public Provider createProvider(Provider provider) {
|
||||
return providerRepository.save(provider);
|
||||
}
|
||||
|
||||
public Provider updateProvider(UUID id, Provider provider) {
|
||||
if (providerRepository.existsById(id)) {
|
||||
provider.setId(id);
|
||||
return providerRepository.save(provider);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteProvider(UUID id) {
|
||||
if (providerRepository.existsById(id)) {
|
||||
providerRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user