PoC: data set based input validation (backend)

This commit is contained in:
Michael Hierweck 2019-04-03 14:29:12 +02:00
parent 1f1794b4f8
commit 603bd4ad67
3 changed files with 20 additions and 0 deletions

View File

@ -1,9 +1,11 @@
package org.hostsharing.hsadminng.service;
import org.hostsharing.hsadminng.domain.Share;
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
import org.hostsharing.hsadminng.repository.ShareRepository;
import org.hostsharing.hsadminng.service.dto.ShareDTO;
import org.hostsharing.hsadminng.service.mapper.ShareMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -40,6 +42,12 @@ public class ShareService {
*/
public ShareDTO save(ShareDTO shareDTO) {
log.debug("Request to save Share : {}", shareDTO);
if((shareDTO.getAction() == ShareAction.SUBSCRIPTION) && (shareDTO.getQuantity() <= 0)) {
throw new BadRequestAlertException("Share subscriptions require a positive quantity", "share", "sharesubscriptionpositivquantity");
}
if((shareDTO.getAction() == ShareAction.CANCELLATION) && (shareDTO.getQuantity() >= 0)) {
throw new BadRequestAlertException("Share cancellations require a negative quantity", "share", "sharecancellationnegativequantity");
}
Share share = shareMapper.toEntity(shareDTO);
share = shareRepository.save(share);
return shareMapper.toDto(share);

View File

@ -0,0 +1,6 @@
{
"error": {
"sharesubscriptionpositivquantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl",
"sharecancellationnegativequantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl"
}
}

View File

@ -0,0 +1,6 @@
{
"error": {
"sharesubscriptionpositivquantity": "Share subscriptions require a positive quantity",
"sharecancellationnegativequantity": "Share cancellations require a negative quantity"
}
}