/** * Finds all playlists for a user * * @param db * @param user * @param limit * @param offset * @return * @throws SQLException */ public static List<Playlist> findAllForUser( final Database db, final User user, final int limit, final int offset) throws SQLException { return user != null ? findPlaylistsForSql(db, limit, offset, " where p.user_id = '" + user.getId() + "' ") : new ArrayList<Playlist>(); }
/** * tries to delete a users playlist. needs to check things like did they create it, etc... if all * goes ok then sends back the ID so that the javascript handler can do whatever... * * @throws BadRequestException * @throws SQLException * @throws IOException */ protected void deletePlaylist() throws BadRequestException, SQLException, IOException { final Request req = getRequest(); final User user = getUser(); final Locale locale = getLocale(); if (user == null) throw new BadRequestException(locale.getString("www.json.error.notLoggedIn"), 403); final Database db = getDatabase(); final int id = Integer.parseInt(req.getUrlParam(2)); final String sql = " select 1 " + " from playlists p " + " where p.id = ? " + " and p.user_id = ? "; ResultSet rs = null; PreparedStatement st = null; try { // check user owns playlist before deleting it st = db.prepare(sql); st.setInt(1, id); st.setInt(2, user.getId()); rs = st.executeQuery(); if (!rs.next()) throw new BadRequestException("You don't own that playlist", 403); cm.removePlaylist(id); // done, send success response final TString tpl = new TString(); tpl.setResult(Integer.toString(id)); getResponse().showJson(tpl.makeRenderer()); } finally { Utils.close(rs); Utils.close(st); } }