Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
playlist API's are up
  • Loading branch information
Jeremy Mill committed Dec 3, 2015
1 parent d6de9da commit 2e5fc64
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 1 deletion.
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.Models;
using TeamDBAwesome.SqlService;
using Newtonsoft.Json;

namespace TeamDBAwesome.Controllers
{
public class GetCustomPlaylistController : ApiController
{
public HttpResponseMessage Get(int PlaylistID)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

List<Track> trackList = sql.GetCustomPlayListTracks(PlaylistID);

string serialzed = JsonConvert.SerializeObject(trackList);

message.Content = new StringContent(serialzed);

return message;
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.Models;
using TeamDBAwesome.SqlService;
using Newtonsoft.Json;

namespace TeamDBAwesome.Controllers
{
public class GetCustomPlaylistsController : ApiController
{
public HttpResponseMessage Get(int CustomerID)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

List<Playlist> playlistList = sql.GetCustomPlaylist(CustomerID);

string serialzed = JsonConvert.SerializeObject(playlistList);

message.Content = new StringContent(serialzed);

return message;
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.Models;
using TeamDBAwesome.SqlService;
using Newtonsoft.Json;

namespace TeamDBAwesome.Controllers
{
public class GetPlaylistListController : ApiController
{
public HttpResponseMessage Get()
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

List<Playlist> playlistList = sql.GetPlaylists();

string serialzed = JsonConvert.SerializeObject(playlistList);

message.Content = new StringContent(serialzed);

return message;
}

}
}
13 changes: 13 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Playlist.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Playlist
{
public int PlaylistID { get; set; }
public string Name { get; set; }
}
}
116 changes: 115 additions & 1 deletion TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -477,8 +477,13 @@ namespace TeamDBAwesome.SqlService


return payList;
}
}

/// <summary>
/// Get A preformed playlist
/// </summary>
/// <param name="PlaylistID">ID of a preformed playlist</param>
/// <returns>List of tracks</returns>
public List<Track> GetPlayListTracks(int PlaylistID)
{
List<Track> tracklist = new List<Track>();
Expand Down Expand Up @@ -525,6 +530,115 @@ namespace TeamDBAwesome.SqlService
return tracklist;
}

/// <summary>
/// send it a playlist ID, get a list of tracks
/// </summary>
/// <param name="PlaylistID">ID of a custom playlist</param>
/// <returns>list of tracks</returns>
public List<Track> GetCustomPlayListTracks(int PlaylistID)
{
List<Track> tracklist = new List<Track>();
bool open = this.OpenConnection();
if (open == true)
{
string query = "select track.TrackId as TrackID, track.Name as trackname,track.Composer as trackcomposer, " +
"track.Milliseconds,track.Bytes, track.UnitPrice, Album.Title as albumtitle,MediaType.Name as mediatype, " +
"Genre.Name as genre " +
"from track " +
"left join MyPlaylistTrack on track.TrackId = MyPlaylistTrack.trackid " +
"left join MyPlayList on MyPlayList.PlaylistId = MyPlaylistTrack.PlaylistId " +
"left join Album on track.AlbumId = Album.AlbumId " +
"left join mediatype on track.MediaTypeId=mediatype.MediaTypeId " +
"left join genre on track.GenreId = genre.GenreId " +
"where playlist.PlaylistId = " + PlaylistID;

MySqlCommand cmd = new MySqlCommand(query, SqlConn);

MySqlDataReader reader = cmd.ExecuteReader();

Track track;

while (reader.Read())
{
track = new Track();

track.TrackId = int.Parse(GetDBString("TrackId", reader));
track.TrackName = GetDBString("trackname", reader);
track.Composer = GetDBString("trackcomposer", reader);
track.Milliseconds = int.Parse(GetDBString("Milliseconds", reader));
track.Bytes = int.Parse(GetDBString("Bytes", reader));
track.UnitPrice = float.Parse(GetDBString("UnitPrice", reader));
track.AlbumTitle = GetDBString("albumtitle", reader);
track.MediaType = GetDBString("mediatype", reader);
track.Genre = GetDBString("genre", reader);

tracklist.Add(track);
}

}


return tracklist;
}

public List<Playlist> GetPlaylists()
{
List<Playlist> playlistList = new List<Playlist>();
bool open = this.OpenConnection();
if (open == true)
{
string query = "Select * from chinook.playlist";

MySqlCommand cmd = new MySqlCommand(query, SqlConn);

MySqlDataReader reader = cmd.ExecuteReader();

Playlist playlist;

while (reader.Read())
{
playlist = new Playlist();

playlist.PlaylistID = int.Parse(GetDBString("PlaylistId", reader));
playlist.Name = GetDBString("Name", reader);

playlistList.Add(playlist);
}
}


return playlistList;
}

public List<Playlist> GetCustomPlaylist(int CustomerID)
{
List<Playlist> playlistList = new List<Playlist>();
bool open = this.OpenConnection();
if (open == true)
{
string query = "Select * from chinook.myplaylist where CustomerID = " + CustomerID;

MySqlCommand cmd = new MySqlCommand(query, SqlConn);

MySqlDataReader reader = cmd.ExecuteReader();

Playlist playlist;

while (reader.Read())
{
playlist = new Playlist();

playlist.PlaylistID = int.Parse(GetDBString("PlaylistId", reader));
playlist.Name = GetDBString("Name", reader);

playlistList.Add(playlist);
}
}


return playlistList;
}

/// <summary>
/// Gets a track from the DB
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Expand Up @@ -165,8 +165,11 @@
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\GetCustomPlaylistController.cs" />
<Compile Include="Controllers\GetCustomPlaylistsController.cs" />
<Compile Include="Controllers\GetPaymentController.cs" />
<Compile Include="Controllers\GetPlaylistController.cs" />
<Compile Include="Controllers\GetPlaylistListController.cs" />
<Compile Include="Controllers\GetTrackController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\NewCustomerController.cs" />
Expand All @@ -182,6 +185,7 @@
<Compile Include="Models\Genre.cs" />
<Compile Include="Models\Media.cs" />
<Compile Include="Models\Payment.cs" />
<Compile Include="Models\Playlist.cs" />
<Compile Include="Models\Search.cs" />
<Compile Include="Models\SearchResult.cs" />
<Compile Include="Models\Track.cs" />
Expand Down

0 comments on commit 2e5fc64

Please sign in to comment.