PoC: data set based input validation (backend)
This commit is contained in:
parent
1f1794b4f8
commit
603bd4ad67
@ -1,9 +1,11 @@
|
|||||||
package org.hostsharing.hsadminng.service;
|
package org.hostsharing.hsadminng.service;
|
||||||
|
|
||||||
import org.hostsharing.hsadminng.domain.Share;
|
import org.hostsharing.hsadminng.domain.Share;
|
||||||
|
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
|
||||||
import org.hostsharing.hsadminng.repository.ShareRepository;
|
import org.hostsharing.hsadminng.repository.ShareRepository;
|
||||||
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
import org.hostsharing.hsadminng.service.dto.ShareDTO;
|
||||||
import org.hostsharing.hsadminng.service.mapper.ShareMapper;
|
import org.hostsharing.hsadminng.service.mapper.ShareMapper;
|
||||||
|
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -40,6 +42,12 @@ public class ShareService {
|
|||||||
*/
|
*/
|
||||||
public ShareDTO save(ShareDTO shareDTO) {
|
public ShareDTO save(ShareDTO shareDTO) {
|
||||||
log.debug("Request to save Share : {}", 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 share = shareMapper.toEntity(shareDTO);
|
||||||
share = shareRepository.save(share);
|
share = shareRepository.save(share);
|
||||||
return shareMapper.toDto(share);
|
return shareMapper.toDto(share);
|
||||||
|
6
src/main/webapp/i18n/de/custom-error.json
Normal file
6
src/main/webapp/i18n/de/custom-error.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
6
src/main/webapp/i18n/en/custom-error.json
Normal file
6
src/main/webapp/i18n/en/custom-error.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"error": {
|
||||||
|
"sharesubscriptionpositivquantity": "Share subscriptions require a positive quantity",
|
||||||
|
"sharecancellationnegativequantity": "Share cancellations require a negative quantity"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user