src/main/java/com/kshrd/derphsar_api/rest/restcontroller/PromotionRestController.java
/**
     * Post a promotion
     *
     * @param promotionRequestModel - Promotion request model
     * @return - Return response message
     */
Post a promotion
@param promotionRequestModel - Promotion request model
@return - Return response message
Post a promotion @param promotionRequestModel - Promotion request model @return - Return response message
@PostMapping("/promotions")
    @ApiOperation(value = "create a promotion", response = PromotionCreateFirstResponse.class)
    public ResponseEntity<BaseApiNoPaginationResponse<PromotionCreateFirstResponse>> createPromotion(@RequestBody PromotionRequestModel promotionRequestModel) throws ParseException {
        ModelMapper mapper = new ModelMapper();
        UUID uuid = UUID.randomUUID();
        BaseApiNoPaginationResponse<PromotionCreateFirstResponse> response = new BaseApiNoPaginationResponse<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        PromotionDto promotionDto = mapper.map(promotionRequestModel,PromotionDto.class);
        if(!promotionRequestModel.getTitle().isEmpty() && promotionRequestModel.getStartRank() !=0 && promotionRequestModel.getEndRank() !=0 && promotionRequestModel.getStartDate() != null && promotionRequestModel.getEndDate() !=null && promotionRequestModel.getShop_id() !=0){
            if(promotionRequestModel.getStartRank() > promotionRequestModel.getEndRank() || promotionRequestModel.getStartDate().after(promotionRequestModel.getEndDate())){
                response.setMessage(message.insertError("Promotion"));
                response.setStatus(HttpStatus.BAD_REQUEST);
            }else {
                promotionDto.setPromoId("DP"+uuid.toString().substring(0,10));
                promotionDto.setStatus(true);
                PromotionDto promotionDto1 = promotionServiceImp.createPromotion(promotionDto);
                PromotionCreateFirstResponse promotionCreateFirstResponse = mapper.map(promotionDto1, PromotionCreateFirstResponse.class);
                response.setMessage(message.inserted("Promotion"));
                response.setData(promotionCreateFirstResponse);
                response.setStatus(HttpStatus.CREATED);
            }
        }else {
            response.setMessage(message.insertError("Promotion"));
            response.setStatus(HttpStatus.BAD_REQUEST);
        }
        response.setTime(new Timestamp(System.currentTimeMillis()));
        return ResponseEntity.ok(response);
    }
@ PostMapping ( "/promotions" ) @ ApiOperation ( value = "create a promotion" , response = PromotionCreateFirstResponse . class ) public ResponseEntity < BaseApiNoPaginationResponse < PromotionCreateFirstResponse > > createPromotion ( @ RequestBody PromotionRequestModel promotionRequestModel ) throws ParseException { ModelMapper mapper = new ModelMapper ( ) ; UUID uuid = UUID . randomUUID ( ) ; BaseApiNoPaginationResponse < PromotionCreateFirstResponse > response = new BaseApiNoPaginationResponse < > ( ) ; SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd" ) ; PromotionDto promotionDto = mapper . map ( promotionRequestModel , PromotionDto . class ) ; if ( ! promotionRequestModel . getTitle ( ) . isEmpty ( ) && promotionRequestModel . getStartRank ( ) != 0 && promotionRequestModel . getEndRank ( ) != 0 && promotionRequestModel . getStartDate ( ) != null && promotionRequestModel . getEndDate ( ) != null && promotionRequestModel . getShop_id ( ) != 0 ) { if ( promotionRequestModel . getStartRank ( ) > promotionRequestModel . getEndRank ( ) || promotionRequestModel . getStartDate ( ) . after ( promotionRequestModel . getEndDate ( ) ) ) { response . setMessage ( message . insertError ( "Promotion" ) ) ; response . setStatus ( HttpStatus . BAD_REQUEST ) ; } else { promotionDto . setPromoId ( "DP" + uuid . toString ( ) . substring ( 0 , 10 ) ) ; promotionDto . setStatus ( true ) ; PromotionDto promotionDto1 = promotionServiceImp . createPromotion ( promotionDto ) ; PromotionCreateFirstResponse promotionCreateFirstResponse = mapper . map ( promotionDto1 , PromotionCreateFirstResponse . class ) ; response . setMessage ( message . inserted ( "Promotion" ) ) ; response . setData ( promotionCreateFirstResponse ) ; response . setStatus ( HttpStatus . CREATED ) ; } } else { response . setMessage ( message . insertError ( "Promotion" ) ) ; response . setStatus ( HttpStatus . BAD_REQUEST ) ; } response . setTime ( new Timestamp ( System . currentTimeMillis ( ) ) ) ; return ResponseEntity . ok ( response ) ; }
Post a promotion
 @param promotionRequestModel - Promotion request model
 @return - Return response message
Post a promotion @param promotionRequestModel - Promotion request model @return - Return response message