Skip to content

Commit

Permalink
bunch of models, working on search
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Mill committed Nov 12, 2015
1 parent bfd6223 commit f457f38
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 0 deletions.
Binary file modified API_REF.xlsx
Binary file not shown.
63 changes: 63 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Web.Http;
using TeamDBAwesome.Models;

namespace TeamDBAwesome.Controllers
{
public class SearchController : ApiController
{
// GET: api/Search
public HttpResponseMessage Get(string search="")
{
//make the message that we are going to return
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

//by default we're going to return everything, unless we get something with the expression type:'type'
//for instance type:artist will only return artist types
Regex regex = new Regex("type:(Media|Album|Artist|Track|Composer|Genre)");
MatchCollection m = regex.Matches(search);
Debug.WriteLine(m);
Search dbsearch = new Search();
if(m.Count > 0)
{
//set each one to blank first
dbsearch.Media = "";
dbsearch.Album = "";
dbsearch.Artist = "";
dbsearch.Track = "";
dbsearch.Composer = "";
dbsearch.Genre = "";

foreach (Match match in m)
{
string tag = match.Value.Split(':')[1];
if (tag == "Media") { dbsearch.Media = search; }
else if (tag == "Album") { dbsearch.Album = search; }
else if (tag == "Artist") { dbsearch.Artist = search; }
else if (tag == "Track") { dbsearch.Track = search; }
else if (tag == "Composer") { dbsearch.Composer = search; }
else if (tag == "Genre") { dbsearch.Genre = search; }
}
}
else
{
dbsearch.Media = search;
dbsearch.Album = search;
dbsearch.Artist = search;
dbsearch.Track = search;
dbsearch.Composer = search;
dbsearch.Genre = search;
}
//return it
return message;
}


}
}
14 changes: 14 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Album.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Album
{
public int AlbumId { get; set; }
public string Title { get; set; }
public int ArtistId { get; set; }
}
}
13 changes: 13 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Artist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Artist
{
public int ArtistId { get; set; }
public string Name { get; set; }
}
}
13 changes: 13 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Genre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Genre
{
public int GenreId { get; set; }
public string Name { get; set; }
}
}
14 changes: 14 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Media.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Media
{
//as a note, in the DB this is mediatype
public int MediaTypeId { get; set; }
public string Name { get; set; }
}
}
17 changes: 17 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Search
{
public string Media { get; set; }
public string Album { get; set; }
public string Artist { get; set; }
public string Track { get; set; }
public string Composer { get; set; }
public string Genre { get; set; }
}
}
17 changes: 17 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/SearchResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class SearchResult
{
List<String> Media { get; set; }
List<String> Album { get; set; }
List<String> Artist { get; set; }
List<String> Track { get; set; }
List<String> Composer { get; set; }
List<String> Genre { get; set; }
}
}
20 changes: 20 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Track.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class Track
{
public int TrackId { get; set; }
public string Name { get; set; }
public int AlbumId { get; set; }
public int MediaTypeId { get; set; }
public int GenreId { get; set; }
public string Composer { get; set; }
public int Milliseconds { get; set; }
public int Bytes { get; set; }
public float UnitPrice { get; set; }
}
}
21 changes: 21 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,30 @@ public Customer GetCustomer(int PersonID)
}

}

private string GetDBString(string SqlFieldName, MySqlDataReader Reader)
{
return Reader[SqlFieldName].Equals(DBNull.Value) ? String.Empty : Reader.GetString(SqlFieldName);
}

public SearchResult Search(Search search)
{
bool open = this.OpenConnection();
SearchResult result = new SearchResult();

if(open == true)
{
//do the search
//need to make the track, album, genre,media,composer, artist models
//nope. composer is inside of track
}
else
{
//handle a failure
}


return result;
}
}
}
1 change: 1 addition & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\NewCustomerController.cs" />
<Compile Include="Controllers\SearchController.cs" />
<Compile Include="Controllers\TestController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand Down

0 comments on commit f457f38

Please sign in to comment.