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); var exists = _webhooks.GetByUrl(url);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (exists is not null) if (exists.ID != Guid.Empty)
{ {
return DiscordWebHookDto.Convert(exists); return DiscordWebHookDto.Convert(exists);
} }

View File

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

View File

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