Skip to content
Snippets Groups Projects
Commit c60cc3bc authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Fix in webbooks retrieval

parent 7b26bc2a
Branches
No related tags found
No related merge requests found
Pipeline #94401 passed
......@@ -23,7 +23,7 @@ public class WebhookEventService {
private static final String WEBHOOK_EVENT_NOT_FOUND = "WebhookEvent not found.";
@Autowired
public WebhookEventService(WebhookEventRepository webhookRepository, EncryptionService encryptionService, ModelMapper modelMapper){
public WebhookEventService(WebhookEventRepository webhookRepository, EncryptionService encryptionService, ModelMapper modelMapper) {
this.webhookRepository = webhookRepository;
this.encryptionService = encryptionService;
this.modelMapper = modelMapper;
......@@ -50,20 +50,21 @@ public class WebhookEventService {
webhookEvent.setAuthorizationHeader(webhookEventDto.getAuthorizationHeader());
}
public void remove(Long id){
public void remove(Long id) {
WebhookEvent webhookEvent = webhookRepository.findById(id).orElseThrow(() -> new MissingElementException(WEBHOOK_EVENT_NOT_FOUND));
webhookRepository.delete(webhookEvent);
}
public List<WebhookEventDto> getAllWebhooks() {
return webhookRepository.findAll().stream().map(x ->
{
return webhookRepository.findAll().stream()
.map(x -> {
try {
x.setTokenValue(x.getTokenValue() == null ? null : encryptionService.decrypt(x.getTokenValue()));
WebhookEventDto dto = modelMapper.map(x, WebhookEventDto.class);
dto.setTokenValue(x.getTokenValue() == null ? null : encryptionService.decrypt(x.getTokenValue()));
return dto;
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
return modelMapper.map(x, WebhookEventDto.class);
}).toList();
}
......@@ -74,7 +75,8 @@ public class WebhookEventService {
public WebhookEventDto getById(Long id) throws GeneralSecurityException {
WebhookEvent event = webhookRepository.findById(id)
.orElseThrow(() -> new MissingElementException(String.format("WebhookEventType with id: %d cannot be found", id)));
event.setTokenValue(event.getTokenValue() == null ? null : encryptionService.decrypt(event.getTokenValue()));
return modelMapper.map(event, WebhookEventDto.class);
WebhookEventDto dto = modelMapper.map(event, WebhookEventDto.class);
dto.setTokenValue(event.getTokenValue() == null ? null : encryptionService.decrypt(event.getTokenValue()));
return dto;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment