Пример #1
0
 public static Result updateGift(String giftId) {
   if (!Utils.checkCredentials(request())) {
     return unauthorized();
   }
   if (!Utils.checkJsonInput(request())) {
     Logger.info("Bad request data for Invite Code " + request().body());
     return generateBadRequest("Bad input json" + request().body());
   }
   Logger.info("Updating Gift Card. GiftId" + giftId);
   Gift gift;
   String giftStatus = "";
   try {
     gift = GiftDAO.getInstance().findGiftById(giftId);
     JsonNode jsonReq = request().body().asJson();
     giftStatus = jsonReq.get("giftStatus").asText();
     gift.setGiftStatus(Gift.GiftStatus.valueOf(giftStatus));
     GiftDAO.getInstance().updateGift(gift);
     Logger.info("Gift Card Updated. GiftId" + giftId);
   } catch (Exception e) {
     Logger.info("Gift Card Update Failed. GiftId" + giftId);
     return generateBadRequest("Invalid Gift Status. Details:" + e);
   }
   // send email to merchant who has challenge with this gift card.
   try {
     if (giftStatus.equals("FUNDED")) {
       EmailService.sendMail(giftId);
     }
   } catch (Exception e) {
     Logger.error("Failed to send Email. GiftId" + giftId);
   }
   return ok(gift.toJson());
 }
Пример #2
0
  public static Result addGiftCard() {
    if (!Utils.checkCredentials(request())) {
      return unauthorized();
    }
    if (!Utils.checkJsonInput(request())) {
      Logger.info("Add Gift Card : Bad request data for watch request " + request().body());
      return generateBadRequest("Bad input json");
    }
    Logger.info("Adding Gift Card");
    JsonNode jsonReq = request().body().asJson();
    Gift gift = new Gift();
    gift.setGiftName(jsonReq.get("giftName").asText());
    gift.setAmount(jsonReq.get("amount").asDouble());
    gift.setDescription(jsonReq.get("description").asText());
    gift.setMaxGifts(jsonReq.get("maxGift").asInt());
    // gift.setGiftLogoUrl(jsonReq.get("giftUrl").asText());
    gift.setGiftStatus(GiftStatus.ADDED);
    gift.setGivenGiftCount(0);
    String merchantId = "";
    try {
      merchantId = Utils.safeStringFromJson(jsonReq, "merchantId");
      if (StringUtils.isNotEmpty(merchantId)) {
        MerchantDAO.getInstance().findMerchantById(merchantId);
        gift.setMerchantId(merchantId);
        gift.setGiftLogoUrl(MerchantDAO.getInstance().getMerchantURLLogo(gift.getMerchantId()));
      }
    } catch (Exception e) {
      return generateBadRequest("Invalid merchant Id");
    }

    String giftId = GiftDAO.getInstance().insertGift(gift);
    try {
      gift = GiftDAO.getInstance().findGiftById(giftId);
      Logger.info("Gift Card Added. GiftId" + giftId);
      return ok(gift.toJson());
    } catch (Exception e) {
      Logger.info("Gift Card Not Inserted Properly. Reason" + e.getMessage());
      return generateInternalServer("gift not inserted properly");
    }
  }