Skip to content

Commit

Permalink
#20 : Add article list (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver254 authored Jul 31, 2022
1 parent 24bba23 commit a267945
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 76 deletions.
8 changes: 5 additions & 3 deletions src/Services/Feeader.Api/Controllers/ArticlesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public ArticlesController(IMediator mediator)

// GET: articles
[HttpGet]
public async Task<IEnumerable<ArticleDto>> ListAsync(Guid? feedId, CancellationToken cancellationToken)
public async Task<IEnumerable<ArticleDto>> ListAsync(Guid? feedId, int? limit, CancellationToken cancellationToken)
{
var articles = await _mediator.Send(new ListArticlesQuery
{
FeedId = feedId
FeedId = feedId,
Limit = limit,

}, cancellationToken);
return articles.Select(a => new ArticleDto(a));
}
Expand Down Expand Up @@ -54,4 +56,4 @@ public void Delete(int id)
{
}
}
}
}
2 changes: 1 addition & 1 deletion src/Services/Feeader.Api/Feeader.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Services/Feeader.Api/Models/ArticleDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public ArticleDto(Article article)
Description = article.Description;
Date = article.Date;
Url = article.Url;
Picture = article.Picture;
}

public Guid Id { get; }
public string Title { get; }
public string Description { get; }
public DateTime Date { get; }
public string Url { get; }
public string Picture { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Monbsoft.Feeader.Application.UseCases.Articles;
public class ListArticlesQuery : IRequest<List<Article>>
{
public Guid? FeedId { get; set; }
public int? Limit { get; set; }
}

internal class ListArticlesHandler : IRequestHandler<ListArticlesQuery, List<Article>>
Expand All @@ -26,6 +27,8 @@ public async Task<List<Article>> Handle(ListArticlesQuery request, CancellationT
var articlesQuery = _dbContext.Articles.AsQueryable();
if (request.FeedId is not null)
articlesQuery = articlesQuery.Where(a => request.FeedId.Equals(a.FeedId));
if (request.Limit is not null)
articlesQuery = articlesQuery.Take(request.Limit.Value);
var articles = await articlesQuery.OrderByDescending(a => a.Date).ToListAsync(cancellationToken);
return articles;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Feeader.Domain/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ namespace Monbsoft.Feeader.Domain
public class Article : EntityBase
{

public Article(Guid id, string title, DateTime date, string description, string url)
public Article(Guid id, string title, DateTime date, string description, string url, string picture)
{
Id = id;
Date = date;
Description = description;
Title = title;
Url = url;
Picture = picture;
}

public DateTime Date { get; private set; }
public string Description { get; private set; }
public string Title { get; private set; }
public string Url { get; private set; }
public string Picture { get; private set; }
public Guid FeedId { get; private set; }
public Feed? Feed { get; private set; } = null;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monbsoft.Feeader.Infrastructure.Data.Migrations
{
public partial class AddPicture : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Picture",
table: "Articles",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("5660e7b9-7555-4d3f-b863-df658440820b"),
column: "Created",
value: new DateTime(2022, 7, 31, 9, 39, 3, 205, DateTimeKind.Local).AddTicks(9045));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("5ebb45a0-5fff-49ac-a5d5-691e6314ce71"),
column: "Created",
value: new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2546));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("71a2df8c-cb34-4203-b045-375695439b8b"),
column: "Created",
value: new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2550));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("bcb81fd8-ab1d-4874-af23-35513d3d673d"),
column: "Created",
value: new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2542));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("cbab58bb-fa24-46b9-b68d-ee25ddefb1a6"),
column: "Created",
value: new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2525));
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Picture",
table: "Articles");

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("5660e7b9-7555-4d3f-b863-df658440820b"),
column: "Created",
value: new DateTime(2022, 7, 22, 23, 23, 26, 31, DateTimeKind.Local).AddTicks(722));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("5ebb45a0-5fff-49ac-a5d5-691e6314ce71"),
column: "Created",
value: new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2489));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("71a2df8c-cb34-4203-b045-375695439b8b"),
column: "Created",
value: new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2493));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("bcb81fd8-ab1d-4874-af23-35513d3d673d"),
column: "Created",
value: new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2485));

migrationBuilder.UpdateData(
table: "Feeds",
keyColumn: "Id",
keyValue: new Guid("cbab58bb-fa24-46b9-b68d-ee25ddefb1a6"),
column: "Created",
value: new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2468));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<Guid>("FeedId")
.HasColumnType("uniqueidentifier");

b.Property<string>("Picture")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
Expand Down Expand Up @@ -84,41 +88,41 @@ protected override void BuildModel(ModelBuilder modelBuilder)
new
{
Id = new Guid("5660e7b9-7555-4d3f-b863-df658440820b"),
Created = new DateTime(2022, 7, 22, 23, 23, 26, 31, DateTimeKind.Local).AddTicks(722),
Created = new DateTime(2022, 7, 31, 9, 39, 3, 205, DateTimeKind.Local).AddTicks(9045),
Name = "BBC News",
Updated = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(541),
Updated = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(481),
Url = "http://feeds.bbci.co.uk/news/world/rss.xml"
},
new
{
Id = new Guid("cbab58bb-fa24-46b9-b68d-ee25ddefb1a6"),
Created = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2468),
Created = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2525),
Name = "The New York Times",
Updated = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2478),
Updated = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2534),
Url = "https://www.nytimes.com/svc/collections/v1/publish/https://www.nytimes.com/section/world/rss.xml"
},
new
{
Id = new Guid("bcb81fd8-ab1d-4874-af23-35513d3d673d"),
Created = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2485),
Created = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2542),
Name = "CNN",
Updated = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2486),
Updated = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2544),
Url = "http://rss.cnn.com/rss/edition_world.rss"
},
new
{
Id = new Guid("5ebb45a0-5fff-49ac-a5d5-691e6314ce71"),
Created = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2489),
Created = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2546),
Name = "CNBC",
Updated = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2491),
Updated = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2547),
Url = "https://www.cnbc.com/id/100727362/device/rss/rss.html"
},
new
{
Id = new Guid("71a2df8c-cb34-4203-b045-375695439b8b"),
Created = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2493),
Created = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2550),
Name = "The Washington Post",
Updated = new DateTime(2022, 7, 22, 23, 23, 26, 34, DateTimeKind.Local).AddTicks(2495),
Updated = new DateTime(2022, 7, 31, 9, 39, 3, 209, DateTimeKind.Local).AddTicks(2551),
Url = "https://feeds.washingtonpost.com/rss/world"
});
});
Expand Down
Loading

0 comments on commit a267945

Please sign in to comment.