예제 #1
0
  /** CRUD */
  public static JSONObject createGiftTransaction(JSONObject inputJson) {
    JSONObject returnJson = new JSONObject();
    try {
      GiftInventory giftInventory =
          GiftInventoryDAO.getGiftInventoryById((long) inputJson.get(Key.GIFTINVENTORYID));
      if (giftInventory != null) {
        Student student = StudentDAO.getStudentById((long) inputJson.get(Key.STUDENTID));
        if (student != null) {
          long giftQuantity = (long) inputJson.get(Key.GIFTQUANTITY);
          double studentPoints = Double.valueOf((String) inputJson.get(Key.STUDENTPOINTS));

          GiftTransaction giftTransaction =
              new GiftTransaction(giftQuantity, studentPoints, giftInventory, student);
          GiftTransactionDAO.addGiftTransaction(giftTransaction);
          returnJson.put(Key.STATUS, Value.SUCCESS);
          returnJson.put(Key.MESSAGE, giftTransaction.toJsonSimple());
        } else {
          returnJson.put(Key.STATUS, Value.FAIL);
          returnJson.put(Key.MESSAGE, Message.STUDENTNOTEXIST);
        }
      } else {
        returnJson.put(Key.STATUS, Value.FAIL);
        returnJson.put(Key.MESSAGE, Message.GIFTINVENTORYNOTEXIST);
      }
    } catch (Exception e) {
      e.printStackTrace();
      returnJson.put(Key.STATUS, Value.FAIL);
      returnJson.put(Key.MESSAGE, e);
    }
    return returnJson;
  }
예제 #2
0
 // features
 // Get giftTransactions by giftInventory
 public static JSONObject getGiftTransactionsByGiftInventory(JSONObject inputJson) {
   JSONObject returnJson = new JSONObject();
   try {
     GiftInventory giftInventory =
         GiftInventoryDAO.getGiftInventoryById((long) inputJson.get(Key.GIFTINVENTORYID));
     if (giftInventory != null) {
       JSONArray giftTransactionArr = new JSONArray();
       for (GiftTransaction giftTransaction :
           GiftTransactionDAO.getGiftTransactionsByGiftInventory(giftInventory)) {
         giftTransactionArr.add(giftTransaction.toJsonSimple());
       }
       returnJson.put(Key.STATUS, Value.SUCCESS);
       returnJson.put(Key.MESSAGE, giftTransactionArr);
     } else {
       returnJson.put(Key.STATUS, Value.FAIL);
       returnJson.put(Key.MESSAGE, Message.GIFTTRANSACTIONNOTEXIST);
     }
   } catch (Exception e) {
     e.printStackTrace();
     returnJson.put(Key.STATUS, Value.FAIL);
     returnJson.put(Key.MESSAGE, e);
   }
   return returnJson;
 }