history/since API endpoint

Closes #2208
This commit is contained in:
Mark McDowall 2017-10-22 12:05:21 -07:00
parent 12065948ca
commit 2a0df7e83e
No known key found for this signature in database
GPG Key ID: D4CEFA9A718052E0
5 changed files with 67 additions and 5 deletions

View File

@ -1,7 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.REST;
using NzbDrone.Api.Series;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.DecisionEngine;
@ -25,6 +28,7 @@ namespace NzbDrone.Api.History
_failedDownloadService = failedDownloadService;
GetResourcePaged = GetHistory;
Get["/since"] = x => GetHistorySince();
Post["/failed"] = x => MarkAsFailed();
}
@ -64,6 +68,27 @@ namespace NzbDrone.Api.History
return ApplyToPage(_historyService.Paged, pagingSpec, MapToResource);
}
private List<HistoryResource> GetHistorySince()
{
var queryDate = Request.Query.Date;
var queryEventType = Request.Query.EventType;
if (!queryDate.HasValue)
{
throw new BadRequestException("date is missing");
}
DateTime date = DateTime.Parse(queryDate.Value);
HistoryEventType? eventType = null;
if (queryEventType.HasValue)
{
eventType = (HistoryEventType)Convert.ToInt32(queryEventType.Value);
}
return _historyService.Since(date, eventType).Select(MapToResource).ToList();
}
private Response MarkAsFailed()
{
var id = (int)Request.Form.Id;

View File

@ -0,0 +1,14 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(118)]
public class add_history_eventType_index : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.Index().OnTable("History").OnColumn("EventType");
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Marr.Data.QGen;
using NzbDrone.Core.Datastore;
@ -16,6 +17,7 @@ namespace NzbDrone.Core.History
List<History> FindByDownloadId(string downloadId);
List<History> FindDownloadHistory(int idSeriesId, QualityModel quality);
void DeleteForSeries(int seriesId);
List<History> Since(DateTime date, HistoryEventType? eventType);
}
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
@ -76,5 +78,19 @@ namespace NzbDrone.Core.History
return base.GetPagedQuery(baseQuery, pagingSpec);
}
public List<History> Since(DateTime date, HistoryEventType? eventType)
{
var query = Query.Where(h => h.Date >= date);
if (eventType.HasValue)
{
query.AndWhere(h => h.EventType == eventType);
}
query.OrderBy(h => h.Date);
return query;
}
}
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -25,6 +25,7 @@ namespace NzbDrone.Core.History
History Get(int historyId);
List<History> Find(string downloadId, HistoryEventType eventType);
List<History> FindByDownloadId(string downloadId);
List<History> Since(DateTime date, HistoryEventType? eventType);
}
public class HistoryService : IHistoryService,
@ -290,5 +291,10 @@ namespace NzbDrone.Core.History
{
_historyRepository.DeleteForSeries(message.Series.Id);
}
public List<History> Since(DateTime date, HistoryEventType? eventType)
{
return _historyRepository.Since(date, eventType);
}
}
}
}

View File

@ -224,6 +224,7 @@
<Compile Include="Datastore\Migration\042_add_download_clients_table.cs" />
<Compile Include="Datastore\Migration\043_convert_config_to_download_clients.cs" />
<Compile Include="Datastore\Migration\044_fix_xbmc_episode_metadata.cs" />
<Compile Include="Datastore\Migration\118_add_history_eventType_index.cs" />
<Compile Include="Datastore\Migration\045_add_indexes.cs" />
<Compile Include="Datastore\Migration\046_fix_nzb_su_url.cs" />
<Compile Include="Datastore\Migration\047_add_published_date_blacklist_column.cs" />