Added better error checking on the new route requests

This commit is contained in:
James Tombleson 2023-03-13 21:57:32 -07:00
parent 799668a059
commit 578197cb75
3 changed files with 12 additions and 29 deletions

View File

@ -40,7 +40,7 @@ public class DiscordWebHookController : ControllerBase
{
var exists = _webhooks.GetByUrl(url);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (exists is not null)
if (exists.ID != Guid.Empty)
{
return DiscordWebHookDto.Convert(exists);
}

View File

@ -13,14 +13,15 @@ namespace Newsbot.Collector.Api.Controllers;
public class SourcesController : ControllerBase
{
private readonly ILogger<SourcesController> _logger;
private readonly ConnectionStrings _settings;
//private readonly ConnectionStrings _settings;
private readonly ISourcesRepository _sources;
public SourcesController(ILogger<SourcesController> logger, IOptions<ConnectionStrings> settings)
{
_logger = logger;
_settings = settings.Value;
_sources = new SourcesTable(_settings.Database);
//_settings = settings.Value;
_sources = new SourcesTable(settings.Value.Database);
}
[HttpGet(Name = "GetSources")]
@ -28,10 +29,7 @@ public class SourcesController : ControllerBase
{
var res = new List<SourceDto>();
var temp = _sources.List(page, 25);
foreach (var item in temp)
{
res.Add(SourceDto.Convert(item));
}
foreach (var item in temp) res.Add(SourceDto.Convert(item));
return res;
}
@ -40,10 +38,7 @@ public class SourcesController : ControllerBase
{
var res = new List<SourceDto>();
var temp = _sources.ListByType(type);
foreach (var item in temp)
{
res.Add(SourceDto.Convert(item));
}
foreach (var item in temp) res.Add(SourceDto.Convert(item));
return res;
}
@ -51,10 +46,7 @@ public class SourcesController : ControllerBase
public SourceDto NewReddit(string name, string url)
{
var res = _sources.GetByNameAndType(name, SourceTypes.Reddit);
if (res.ID != Guid.Empty)
{
return SourceDto.Convert(res);
}
if (res.ID != Guid.Empty) return SourceDto.Convert(res);
var item = _sources.New(new SourceModel
{
@ -73,10 +65,7 @@ public class SourcesController : ControllerBase
public SourceDto NewRss(string name, string url)
{
var res = _sources.GetByNameAndType(name, SourceTypes.Rss);
if (res.ID != Guid.Empty)
{
return SourceDto.Convert(res);
}
if (res.ID != Guid.Empty) return SourceDto.Convert(res);
var m = new SourceModel
{
@ -96,10 +85,7 @@ public class SourcesController : ControllerBase
public SourceDto NewYoutube(string name, string url)
{
var res = _sources.GetByNameAndType(name, SourceTypes.YouTube);
if (res.ID != Guid.Empty)
{
return SourceDto.Convert(res);
}
if (res.ID != Guid.Empty) return SourceDto.Convert(res);
var item = _sources.New(new SourceModel
{
@ -119,10 +105,7 @@ public class SourcesController : ControllerBase
public SourceDto NewTwitch(string name)
{
var res = _sources.GetByNameAndType(name, SourceTypes.Twitch);
if (res.ID != Guid.Empty)
{
return SourceDto.Convert(res);
}
if (res.ID != Guid.Empty) return SourceDto.Convert(res);
var item = _sources.New(new SourceModel
{

View File

@ -86,7 +86,7 @@ public class SubscriptionsController : ControllerBase
{
var exists = _subscription.GetByWebhookAndSource(discordId, sourceId);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (exists is not null)
if (exists.ID != Guid.Empty)
{
return SubscriptionDto.Convert(exists);
}