Skip to content

Commit

Permalink
Merge pull request #110 from gothinkster/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
adamhathcock authored Apr 11, 2024
2 parents 5f76a4c + 1b7f1d7 commit e8396e4
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 528 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.27.3",
"version": "0.28.0",
"commands": [
"dotnet-csharpier"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.201
dotnet-version: 8.0.204
- run: dotnet run --project build/build.csproj
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="Bullseye" Version="5.0.0" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Serilog" Version="3.1.1" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
Expand Down
1 change: 0 additions & 1 deletion src/Conduit/Domain/Person.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

Expand Down
6 changes: 3 additions & 3 deletions src/Conduit/Features/Articles/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ CancellationToken cancellationToken
var t = await context.Tags.FindAsync(tag);
if (t == null)
{
t = new Tag() { TagId = tag };
t = new Tag { TagId = tag };
await context.Tags.AddAsync(t, cancellationToken);
//save immediately for reuse
await context.SaveChangesAsync(cancellationToken);
}
tags.Add(t);
}

var article = new Article()
var article = new Article
{
Author = author,
Body = message.Article.Body,
Expand All @@ -81,7 +81,7 @@ CancellationToken cancellationToken
await context.Articles.AddAsync(article, cancellationToken);

await context.ArticleTags.AddRangeAsync(
tags.Select(x => new ArticleTag() { Article = article, Tag = x }),
tags.Select(x => new ArticleTag { Article = article, Tag = x }),
cancellationToken
);

Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Articles/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ IEnumerable<string> articleTagList
var at = article.ArticleTags?.FirstOrDefault(t => t.TagId == tag);
if (at == null)
{
at = new ArticleTag()
at = new ArticleTag
{
Article = article,
ArticleId = article.ArticleId,
Tag = new Tag() { TagId = tag },
Tag = new Tag { TagId = tag },
TagId = tag
};
articleTagsToCreate.Add(at);
Expand Down
7 changes: 1 addition & 6 deletions src/Conduit/Features/Articles/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Conduit.Domain;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using MediatR;
Expand Down Expand Up @@ -111,11 +110,7 @@ CancellationToken cancellationToken
.AsNoTracking()
.ToListAsync(cancellationToken);

return new ArticlesEnvelope()
{
Articles = articles,
ArticlesCount = queryable.Count()
};
return new ArticlesEnvelope { Articles = articles, ArticlesCount = queryable.Count() };
}
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Features/Comments/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CancellationToken cancellationToken
cancellationToken
);

var comment = new Comment()
var comment = new Comment
{
Author = author,
Body = message.Model.Comment.Body ?? string.Empty,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Favorites/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CancellationToken cancellationToken

if (favorite == null)
{
favorite = new ArticleFavorite()
favorite = new ArticleFavorite
{
Article = article,
ArticleId = article.ArticleId,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Followers/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CancellationToken cancellationToken

if (followedPeople == null)
{
followedPeople = new FollowedPeople()
followedPeople = new FollowedPeople
{
Observer = observer,
ObserverId = observer.PersonId,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Tags/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<TagsEnvelope> Handle(Query message, CancellationToken cancella
.Tags.OrderBy(x => x.TagId)
.AsNoTracking()
.ToListAsync(cancellationToken);
return new TagsEnvelope()
return new TagsEnvelope
{
Tags = tags?.Select(x => x.TagId ?? string.Empty).ToList() ?? new List<string>()
};
Expand Down
1 change: 0 additions & 1 deletion src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;

namespace Conduit.Infrastructure.Security;
Expand Down
40 changes: 5 additions & 35 deletions src/Conduit/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Conduit;
using Conduit.Features.Profiles;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Conduit.Infrastructure.Security;
using FluentValidation;
using FluentValidation.AspNetCore;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
Expand All @@ -25,15 +17,6 @@

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())
);
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>));
builder.Services.AddScoped(
typeof(IPipelineBehavior<,>),
typeof(DBContextTransactionPipelineBehavior<,>)
);

// take the connection string from the environment variable or use hard-coded database name
var connectionString = defaultDatabaseConnectionSrting;

Expand Down Expand Up @@ -81,7 +64,7 @@
x.SupportNonNullableReferenceTypes();

x.AddSecurityRequirement(
new OpenApiSecurityRequirement()
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
Expand All @@ -98,11 +81,8 @@
);
x.SwaggerDoc("v1", new OpenApiInfo { Title = "RealWorld API", Version = "v1" });
x.CustomSchemaIds(y => y.FullName);
x.DocInclusionPredicate((version, apiDescription) => true);
x.TagActionsBy(y => new List<string>()
{
y.GroupName ?? throw new InvalidOperationException()
});
x.DocInclusionPredicate((_, _) => true);
x.TagActionsBy(y => new List<string> { y.GroupName ?? throw new InvalidOperationException() });
x.CustomSchemaIds(s => s.FullName?.Replace("+", "."));
});

Expand All @@ -123,17 +103,7 @@
.WhenWritingNull
);

builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Services.AddValidatorsFromAssemblyContaining<Startup>();

builder.Services.AddAutoMapper(typeof(Program));

builder.Services.AddScoped<IPasswordHasher, PasswordHasher>();
builder.Services.AddScoped<IJwtTokenGenerator, JwtTokenGenerator>();
builder.Services.AddScoped<ICurrentUserAccessor, CurrentUserAccessor>();
builder.Services.AddScoped<IProfileReader, ProfileReader>();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddConduit();

builder.Services.AddJwt();

Expand All @@ -143,7 +113,7 @@

app.UseMiddleware<ErrorHandlingMiddleware>();

app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

app.UseAuthentication();
app.UseMvc();
Expand Down

This file was deleted.

Loading

0 comments on commit e8396e4

Please sign in to comment.