From a3085bb27fcaffebb4f12b299a3c79bbdbe00342 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Fri, 4 Aug 2023 23:07:04 -0700 Subject: [PATCH] Article controller was updated and tests updated --- .../Controllers/v1/ArticlesController.cs | 9 +++++++-- .../Jobs/DiscordNotificationJobTest.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs b/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs index b8ed6d5..81f1c59 100644 --- a/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newsbot.Collector.Domain.Dto; +using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Results; @@ -15,11 +16,13 @@ public class ArticlesController : ControllerBase //private readonly ILogger _logger; private readonly IArticlesRepository _articles; private readonly ISourcesRepository _sources; + private readonly IAuthorTable _author; - public ArticlesController(IArticlesRepository articles, ISourcesRepository sources) + public ArticlesController(IArticlesRepository articles, ISourcesRepository sources, IAuthorTable author) { _articles = articles; _sources = sources; + _author = author; } [HttpGet(Name = "GetArticles")] @@ -59,11 +62,13 @@ public class ArticlesController : ControllerBase { var item = _articles.GetById(id); var sourceItem = _sources.GetById(item.SourceId); + var author = _author.GetBySourceIdAndNameAsync(sourceItem.Id, sourceItem.Name); + author.Wait(); return new OkObjectResult(new ArticleDetailsResult { IsSuccessful = true, - Item = ArticleDetailsDto.Convert(item, sourceItem) + Item = ArticleDetailsDto.Convert(item, sourceItem, author.Result) }); } diff --git a/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs b/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs index ed50aae..01c1597 100644 --- a/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs +++ b/Newsbot.Collector.Tests/Jobs/DiscordNotificationJobTest.cs @@ -32,12 +32,15 @@ public class DiscordNotificationJobTest PubDate = DateTime.Now, Thumbnail = "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg", Description = "Please work", - AuthorName = "No one knows" }, new IconEntity() { Id = Guid.NewGuid(), FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png" + }, new AuthorEntity + { + Id = Guid.NewGuid(), + Name = "test" }); webhookClient.SendMessage(msg); } @@ -59,7 +62,6 @@ public class DiscordNotificationJobTest Thumbnail = "https://cdn.arstechnica.net/wp-content/uploads/2023/03/GettyImages-944827400-800x534.jpg", Description = "Please work", - AuthorName = "No one knows", CodeIsCommit = true }, new SourceEntity @@ -82,6 +84,9 @@ public class DiscordNotificationJobTest { CodeAllowCommits = false, CodeAllowReleases = true + }, new AuthorEntity + { + Name = "a" }); Assert.Fail("Expected a error to come back."); }