Пример #1
0
  @BodyParser.Of(BodyParser.Json.class)
  public static Result getMenuItemsForSeller() {
    try {
      Long sellerId = RequestParser.getJsonFromRequest(request(), Long.class);
      List<MenuItem> menuItemsForSeller = sellerTableQueries.getMenuItemsForSeller(sellerId);

      JsonNode jsonNode = new ObjectMapper().valueToTree(menuItemsForSeller);
      return ok(jsonNode);
    } catch (Exception ex) {
      return ok("Internal Server Error");
    }
  }
Пример #2
0
 @BodyParser.Of(BodyParser.Json.class)
 public static Result addNewSeller() {
   try {
     Seller seller = RequestParser.getJsonFromRequest(request(), Seller.class);
     boolean addNewSellerSuccess = sellerTableQueries.addNewSeller(seller);
     ObjectNode result =
         addNewSellerSuccess
             ? ResponseSerializer.createJson("success")
             : ResponseSerializer.createJson("failure");
     return ok(result);
   } catch (Exception ex) {
     return ok("error handling query");
   }
 }
Пример #3
0
 @BodyParser.Of(BodyParser.Json.class)
 public static Result validateEmail() {
   try {
     String email = RequestParser.getJsonFromRequest(request(), String.class);
     boolean validEmail = sellerTableQueries.validateEmail(email);
     ObjectNode result =
         validEmail
             ? ResponseSerializer.createJson("success")
             : ResponseSerializer.createJson("failure");
     return ok(result);
   } catch (Exception ex) {
     return ok("Internal Server Error");
   }
 }
Пример #4
0
  @BodyParser.Of(BodyParser.Json.class)
  public static Result loginSeller() {
    try {
      EmailPassword emailPassword =
          RequestParser.getJsonFromRequest(request(), EmailPassword.class);
      LoginCredentials loginCredentials =
          new LoginCredentials(emailPassword, LoginCredentials.UserType.SELLER);
      boolean sellerCredentialsVerified =
          sellerTableQueries.checkSellerCredentials(loginCredentials);

      if (sellerCredentialsVerified) {
        session(USER_EMAIL, emailPassword.email);
        String lastLoginTimestamp = "" + System.currentTimeMillis();
        session(USER_LAST_LOGIN_TIMESTAMP, lastLoginTimestamp);
      }
      ObjectNode result =
          sellerCredentialsVerified
              ? ResponseSerializer.createJson("success")
              : ResponseSerializer.createJson("failure");
      return ok(result);
    } catch (Exception ex) {
      return ok("error handling query");
    }
  }