diff --git a/RequestPlex.Core/SettingsService.cs b/RequestPlex.Core/SettingsService.cs index a7e8abb21..81b33cc5d 100644 --- a/RequestPlex.Core/SettingsService.cs +++ b/RequestPlex.Core/SettingsService.cs @@ -38,5 +38,36 @@ namespace RequestPlex.Core return settings; } + + public void AddRequest(int tmdbid, RequestType type) + { + var model = new RequestedModel + { + Tmdbid = tmdbid, + Type = type + }; + + var db = new DbConfiguration(new SqliteFactory()); + var repo = new GenericRepository(db); + + repo.Insert(model); + } + + public bool CheckRequest(int tmdbid) + { + var db = new DbConfiguration(new SqliteFactory()); + var repo = new GenericRepository(db); + + return repo.GetAll().Any(x => x.Tmdbid == tmdbid); + } + + public void DeleteRequest(int tmdbId) + { + var db = new DbConfiguration(new SqliteFactory()); + var repo = new GenericRepository(db); + var entity = repo.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId); + repo.Delete(entity); + } + } } diff --git a/RequestPlex.Store/RequestPlex.Store.csproj b/RequestPlex.Store/RequestPlex.Store.csproj index 6866dbe0a..a51323bed 100644 --- a/RequestPlex.Store/RequestPlex.Store.csproj +++ b/RequestPlex.Store/RequestPlex.Store.csproj @@ -58,6 +58,7 @@ + True diff --git a/RequestPlex.Store/RequestedModel.cs b/RequestPlex.Store/RequestedModel.cs new file mode 100644 index 000000000..3f594c613 --- /dev/null +++ b/RequestPlex.Store/RequestedModel.cs @@ -0,0 +1,18 @@ +using Dapper.Contrib.Extensions; + +namespace RequestPlex.Store +{ + [Table("Requested")] + public class RequestedModel : Entity + { + // ReSharper disable once IdentifierTypo + public int Tmdbid { get; set; } + public RequestType Type { get; set; } + } + + public enum RequestType + { + Movie, + TvShow + } +} diff --git a/RequestPlex.Store/SqlTables.sql b/RequestPlex.Store/SqlTables.sql index 407b6584a..8b035ae0f 100644 --- a/RequestPlex.Store/SqlTables.sql +++ b/RequestPlex.Store/SqlTables.sql @@ -12,4 +12,11 @@ CREATE TABLE IF NOT EXISTS Settings ( Id INTEGER PRIMARY KEY AUTOINCREMENT, Port INTEGER NOT NULL +); + +CREATE TABLE IF NOT EXISTS Requested +( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Type INTEGER NOT NULL, + Tmdbid INTEGER NOT NULL ); \ No newline at end of file diff --git a/RequestPlex.UI/Content/search.js b/RequestPlex.UI/Content/search.js index 63fb449e2..e4ebdf7c9 100644 --- a/RequestPlex.UI/Content/search.js +++ b/RequestPlex.UI/Content/search.js @@ -17,6 +17,34 @@ $("#tvSearchContent").on("keyup", function (e) { tvimer = setTimeout(tvSearch(), 400); }); + +$("#test").click(function (e) { + e.preventDefault(); + + var $form = $('#form'+e.target.id); + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: $form.serialize(), + dataType: "json", + success: function (response) { + console.log(response); + if (response.Result === true) { + generateNotify("Success!", "success"); + } else { + generateNotify(response.Message, "warning"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + + function movieSearch() { $("#movieList").html(""); var query = $("#movieSearchContent").val(); diff --git a/RequestPlex.UI/Modules/SearchModule.cs b/RequestPlex.UI/Modules/SearchModule.cs index 90fe3be0f..8cc46f583 100644 --- a/RequestPlex.UI/Modules/SearchModule.cs +++ b/RequestPlex.UI/Modules/SearchModule.cs @@ -2,6 +2,8 @@ using Nancy; using Nancy.Responses.Negotiation; using RequestPlex.Api; +using RequestPlex.Core; +using RequestPlex.Store; namespace RequestPlex.UI.Modules { @@ -34,7 +36,7 @@ namespace RequestPlex.UI.Modules Post["search/request/tv"] = parameters => { - var tvShowId = (int)Request.Form.showId; + var tvShowId = (int)Request.Form.tvId; var latest = (bool)Request.Form.latestSeason; return RequestTvShow(tvShowId, latest); }; @@ -47,6 +49,7 @@ namespace RequestPlex.UI.Modules private Response SearchMovie(string searchTerm) { + var s = new SettingsService(); var api = new TheMovieDbApi(); var movies = api.SearchMovie(searchTerm); var result = movies.Result; @@ -79,12 +82,21 @@ namespace RequestPlex.UI.Modules private Response RequestMovie(int movieId) { - return Response.AsJson(""); + var s = new SettingsService(); + if (s.CheckRequest(movieId)) + { + return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" }); + } + s.AddRequest(movieId, RequestType.Movie); + return Response.AsJson(new { Result = true }); } private Response RequestTvShow(int showId, bool latest) { - return Response.AsJson(""); + // Latest send to Sonarr and no need to store in DB + var s = new SettingsService(); + s.AddRequest(showId, RequestType.TvShow); + return Response.AsJson(new {Result = true }); } } } \ No newline at end of file diff --git a/RequestPlex.UI/Views/Search/Index.cshtml b/RequestPlex.UI/Views/Search/Index.cshtml index 3660d7f43..8dc337963 100644 --- a/RequestPlex.UI/Views/Search/Index.cshtml +++ b/RequestPlex.UI/Views/Search/Index.cshtml @@ -48,11 +48,11 @@
{{#if posterPath}} - poster + poster {{/if}}
-
+

{{title}} ({{year}})

@@ -62,9 +62,10 @@
Vote Average: {{voteAverage}} Vote Count: {{voteCount}} - +
+ + +