Commit 6b8a768e authored by jade.woodward's avatar jade.woodward

Recommitting database code

parent 36d03f82
......@@ -32,7 +32,7 @@ public class databaseInterface {
chill,
happy,
energetic,
busy,
calming,
any
}
public enum Time {
......@@ -100,6 +100,40 @@ public class databaseInterface {
return ids;
}
/*
* takes in an array list of spotify ids and a title for the playlist
* makes a new playlist in the database
* adds the songs to the playlist
* returns true if the playlist was made correctly
* returns false if something went wrong
*/
public Boolean savePlaylist(String title, ArrayList<String> spotifyIDs){
HashMap<String, String> params = new HashMap<>();
params.put("title", title);
String url = "https://cs2s.yorkdc.net/~jade.woodward/mobile-app-development/newPlaylist.php";
String playlistid = getFromDatabase(url, params);
String url2 = "https://cs2s.yorkdc.net/~jade.woodward/mobile-app-development/getsongbyspotify.php";
String url3 = "https://cs2s.yorkdc.net/~jade.woodward/mobile-app-development/addplaylistsongbyids.php";
for (String s: spotifyIDs) {
HashMap<String, String> param2 = new HashMap<>();
param2.put("id", s);
String id = getFromDatabase(url2, param2);
HashMap<String, String> param3 = new HashMap<>();
param3.put("song", id);
param3.put("playlist", playlistid);
if(!getFromDatabase(url3, param3).equals("added a song to playlist")){
return false;
}
}
return true;
}
/*
* one string input - should still be in 123 format though
* gets a list of song ids from the database
......@@ -131,21 +165,17 @@ public class databaseInterface {
i++;
}
String spotify = "failed to fetch from database";
String spotify = "failed to connect to database";
try {
String url = "https://cs2s.yorkdc.net/~jade.woodward/mobile-app-development/getplaylistbyid.php";
URL urlObj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.connect();
String paramsString = sbParams.toString();
......@@ -183,20 +213,10 @@ public class databaseInterface {
return spotify;
}
public ArrayList<String> getPlaylistByID(String id) {
String songids = getPlaylistSongIDsByID(id);
ArrayList<String> ids = parseOutSpaces(songids);
ArrayList<String> spotifys = new ArrayList<>();
for (String indv: ids) {
String spotty = getSongByID(indv);
spotifys.add(spotty);
}
return spotifys;
}
/*
* splits a string into words by splitting at spaces.
*/
private ArrayList<String> parseOutSpaces(String original) {
ArrayList<String> results = new ArrayList<>();
......@@ -206,5 +226,4 @@ public class databaseInterface {
return results;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment