Skip to content

Commit

Permalink
update and run csharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hathcock committed Mar 4, 2024
1 parent 1a46b75 commit b5ea3c7
Show file tree
Hide file tree
Showing 63 changed files with 227 additions and 280 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.25.0",
"version": "0.27.3",
"commands": [
"dotnet-csharpier"
]
}
}
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Domain/ArticleFavorite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class ArticleFavorite

public int PersonId { get; init; }
public Person? Person { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Domain/ArticleTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class ArticleTag

public string? TagId { get; init; }
public Tag? Tag { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Domain/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public class Comment
public DateTime CreatedAt { get; init; }

public DateTime UpdatedAt { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Domain/FollowedPeople.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class FollowedPeople

public int TargetId { get; init; }
public Person? Target { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Domain/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class Tag
public string? TagId { get; init; }

public List<ArticleTag> ArticleTags { get; init; } = new();
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Features/Articles/ArticleEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Conduit.Features.Articles;

public record ArticleEnvelope(Article Article);
public record ArticleEnvelope(Article Article);
22 changes: 10 additions & 12 deletions src/Conduit/Features/Articles/ArticlesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ public Task<ArticlesEnvelope> Get(
[FromQuery] int? limit,
[FromQuery] int? offset,
CancellationToken cancellationToken
) =>
mediator.Send(
new List.Query(tag, author, favorited, limit, offset),
cancellationToken
);
) => mediator.Send(new List.Query(tag, author, favorited, limit, offset), cancellationToken);

[HttpGet("feed")]
public Task<ArticlesEnvelope> GetFeed(
Expand All @@ -34,29 +30,31 @@ public Task<ArticlesEnvelope> GetFeed(
CancellationToken cancellationToken
) =>
mediator.Send(
new List.Query(tag, author, favorited, limit, offset) { IsFeed = true }, cancellationToken);
new List.Query(tag, author, favorited, limit, offset) { IsFeed = true },
cancellationToken
);

[HttpGet("{slug}")]
public Task<ArticleEnvelope> Get(string slug, CancellationToken cancellationToken) => mediator.Send(new Details.Query(slug), cancellationToken);
public Task<ArticleEnvelope> Get(string slug, CancellationToken cancellationToken) =>
mediator.Send(new Details.Query(slug), cancellationToken);

[HttpPost]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ArticleEnvelope> Create(
[FromBody] Create.Command command,
CancellationToken cancellationToken
) =>
mediator.Send(command, cancellationToken);
) => mediator.Send(command, cancellationToken);

[HttpPut("{slug}")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ArticleEnvelope> Edit(
string slug,
[FromBody] Edit.Model model,
CancellationToken cancellationToken
) =>
mediator.Send(new Edit.Command(model, slug), cancellationToken);
) => mediator.Send(new Edit.Command(model, slug), cancellationToken);

[HttpDelete("{slug}")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task Delete(string slug, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(slug), cancellationToken);
public Task Delete(string slug, CancellationToken cancellationToken) =>
mediator.Send(new Delete.Command(slug), cancellationToken);
}
2 changes: 1 addition & 1 deletion src/Conduit/Features/Articles/ArticlesEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class ArticlesEnvelope
public List<Article> Articles { get; set; } = new();

public int ArticlesCount { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Conduit/Features/Articles/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public record Command(ArticleData Article) : IRequest<ArticleEnvelope>;

public class CommandValidator : AbstractValidator<Command>
{
public CommandValidator() => RuleFor(x => x.Article).NotNull().SetValidator(new ArticleDataValidator());
public CommandValidator() =>
RuleFor(x => x.Article).NotNull().SetValidator(new ArticleDataValidator());
}

public class Handler(ConduitContext context, ICurrentUserAccessor currentUserAccessor)
Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Articles/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public async Task<ArticleEnvelope> Handle(
CancellationToken cancellationToken
)
{
var article = await context.Articles
.GetAllData()
var article = await context
.Articles.GetAllData()
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken);

if (article == null)
Expand Down
18 changes: 7 additions & 11 deletions src/Conduit/Features/Articles/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public async Task<ArticleEnvelope> Handle(
CancellationToken cancellationToken
)
{
var article = await context.Articles
.Include(x => x.ArticleTags) // include also the article tags since they also need to be updated
var article = await context
.Articles.Include(x => x.ArticleTags) // include also the article tags since they also need to be updated
.Where(x => x.Slug == message.Slug)
.FirstOrDefaultAsync(cancellationToken);

Expand All @@ -59,7 +59,7 @@ CancellationToken cancellationToken

if (
context.ChangeTracker.Entries().First(x => x.Entity == article).State
== EntityState.Modified
== EntityState.Modified
|| articleTagsToCreate.Count != 0
|| articleTagsToDelete.Count != 0
)
Expand All @@ -80,14 +80,10 @@ CancellationToken cancellationToken

await context.SaveChangesAsync(cancellationToken);

article =
await context.Articles
.GetAllData()
.Where(x => x.Slug == article.Slug)
.FirstOrDefaultAsync(
x => x.ArticleId == article.ArticleId,
cancellationToken
);
article = await context
.Articles.GetAllData()
.Where(x => x.Slug == article.Slug)
.FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken);
if (article is null)
{
throw new RestException(
Expand Down
19 changes: 8 additions & 11 deletions src/Conduit/Features/Articles/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ CancellationToken cancellationToken

if (message.IsFeed && currentUserAccessor.GetCurrentUsername() != null)
{
var currentUser = await context.Persons
.Include(x => x.Following)
var currentUser = await context
.Persons.Include(x => x.Following)
.FirstOrDefaultAsync(
x => x.Username == currentUserAccessor.GetCurrentUsername(),
cancellationToken
Expand All @@ -47,11 +47,8 @@ CancellationToken cancellationToken
new { User = Constants.NOT_FOUND }
);
}
queryable = queryable.Where(
x =>
currentUser.Following
.Select(y => y.TargetId)
.Contains(x.Author!.PersonId)
queryable = queryable.Where(x =>
currentUser.Following.Select(y => y.TargetId).Contains(x.Author!.PersonId)
);
}

Expand All @@ -63,8 +60,8 @@ CancellationToken cancellationToken
);
if (tag != null)
{
queryable = queryable.Where(
x => x.ArticleTags.Select(y => y.TagId).Contains(tag.TagId)
queryable = queryable.Where(x =>
x.ArticleTags.Select(y => y.TagId).Contains(tag.TagId)
);
}
else
Expand Down Expand Up @@ -97,8 +94,8 @@ CancellationToken cancellationToken
);
if (author != null)
{
queryable = queryable.Where(
x => x.ArticleFavorites.Any(y => y.PersonId == author.PersonId)
queryable = queryable.Where(x =>
x.ArticleFavorites.Any(y => y.PersonId == author.PersonId)
);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Comments/CommentEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Conduit.Features.Comments;

public record CommentEnvelope(Comment Comment);
public record CommentEnvelope(Comment Comment);
9 changes: 5 additions & 4 deletions src/Conduit/Features/Comments/CommentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public Task<CommentEnvelope> Create(
string slug,
[FromBody] Create.Model model,
CancellationToken cancellationToken
) =>
mediator.Send(new Create.Command(model, slug), cancellationToken);
) => mediator.Send(new Create.Command(model, slug), cancellationToken);

[HttpGet("{slug}/comments")]
public Task<CommentsEnvelope> Get(string slug, CancellationToken cancellationToken) => mediator.Send(new List.Query(slug), cancellationToken);
public Task<CommentsEnvelope> Get(string slug, CancellationToken cancellationToken) =>
mediator.Send(new List.Query(slug), cancellationToken);

[HttpDelete("{slug}/comments/{id}")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task Delete(string slug, int id, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(slug, id), cancellationToken);
public Task Delete(string slug, int id, CancellationToken cancellationToken) =>
mediator.Send(new Delete.Command(slug, id), cancellationToken);
}
2 changes: 1 addition & 1 deletion src/Conduit/Features/Comments/CommentsEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Conduit.Features.Comments;

public record CommentsEnvelope(List<Comment> Comments);
public record CommentsEnvelope(List<Comment> Comments);
4 changes: 2 additions & 2 deletions src/Conduit/Features/Comments/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public async Task<CommentEnvelope> Handle(
CancellationToken cancellationToken
)
{
var article = await context.Articles
.Include(x => x.Comments)
var article = await context
.Articles.Include(x => x.Comments)
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken);

if (article == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Comments/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class QueryHandler(ConduitContext context) : IRequestHandler<Command>
public async Task Handle(Command message, CancellationToken cancellationToken)
{
var article =
await context.Articles
.Include(x => x.Comments)
await context
.Articles.Include(x => x.Comments)
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken)
?? throw new RestException(
HttpStatusCode.NotFound,
Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Comments/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public async Task<CommentsEnvelope> Handle(
CancellationToken cancellationToken
)
{
var article = await context.Articles
.Include(x => x.Comments)
var article = await context
.Articles.Include(x => x.Comments)
.ThenInclude(x => x.Author)
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken);

Expand Down
12 changes: 3 additions & 9 deletions src/Conduit/Features/Favorites/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ CancellationToken cancellationToken
await context.SaveChangesAsync(cancellationToken);
}



article =
await context.Articles
.GetAllData()
.FirstOrDefaultAsync(
x => x.ArticleId == article.ArticleId,
cancellationToken
);
article = await context
.Articles.GetAllData()
.FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken);
if (article is null)
{
throw new RestException(
Expand Down
10 changes: 3 additions & 7 deletions src/Conduit/Features/Favorites/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ await context.Articles.FirstOrDefaultAsync(
await context.SaveChangesAsync(cancellationToken);
}

article =
await context.Articles
.GetAllData()
.FirstOrDefaultAsync(
x => x.ArticleId == article.ArticleId,
cancellationToken
);
article = await context
.Articles.GetAllData()
.FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken);
if (article is null)
{
throw new RestException(
Expand Down
8 changes: 3 additions & 5 deletions src/Conduit/Features/Favorites/FavoritesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ public class FavoritesController(IMediator mediator) : Controller
{
[HttpPost("{slug}/favorite")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ArticleEnvelope> FavoriteAdd(string slug, CancellationToken cancellationToken) => mediator.Send(new Add.Command(slug), cancellationToken);
public Task<ArticleEnvelope> FavoriteAdd(string slug, CancellationToken cancellationToken) =>
mediator.Send(new Add.Command(slug), cancellationToken);

[HttpDelete("{slug}/favorite")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ArticleEnvelope> FavoriteDelete(
string slug,
CancellationToken cancellationToken
) =>
public Task<ArticleEnvelope> FavoriteDelete(string slug, CancellationToken cancellationToken) =>
mediator.Send(new Delete.Command(slug), cancellationToken);
}
4 changes: 2 additions & 2 deletions src/Conduit/Features/Followers/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class CommandValidator : AbstractValidator<Command>
public class QueryHandler(
ConduitContext context,
ICurrentUserAccessor currentUserAccessor,
IProfileReader profileReader)
: IRequestHandler<Command, ProfileEnvelope>
IProfileReader profileReader
) : IRequestHandler<Command, ProfileEnvelope>
{
public async Task<ProfileEnvelope> Handle(
Command message,
Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Followers/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class CommandValidator : AbstractValidator<Command>
public class QueryHandler(
ConduitContext context,
ICurrentUserAccessor currentUserAccessor,
IProfileReader profileReader)
: IRequestHandler<Command, ProfileEnvelope>
IProfileReader profileReader
) : IRequestHandler<Command, ProfileEnvelope>
{
public async Task<ProfileEnvelope> Handle(
Command message,
Expand Down
6 changes: 4 additions & 2 deletions src/Conduit/Features/Followers/FollowersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class FollowersController(IMediator mediator) : Controller
{
[HttpPost("{username}/follow")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ProfileEnvelope> Follow(string username, CancellationToken cancellationToken) => mediator.Send(new Add.Command(username), cancellationToken);
public Task<ProfileEnvelope> Follow(string username, CancellationToken cancellationToken) =>
mediator.Send(new Add.Command(username), cancellationToken);

[HttpDelete("{username}/follow")]
[Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)]
public Task<ProfileEnvelope> Unfollow(string username, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(username), cancellationToken);
public Task<ProfileEnvelope> Unfollow(string username, CancellationToken cancellationToken) =>
mediator.Send(new Delete.Command(username), cancellationToken);
}
6 changes: 4 additions & 2 deletions src/Conduit/Features/Profiles/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class QueryValidator : AbstractValidator<Query>
public QueryValidator() => RuleFor(x => x.Username).NotEmpty();
}

public class QueryHandler(IProfileReader profileReader) : IRequestHandler<Query, ProfileEnvelope>
public class QueryHandler(IProfileReader profileReader)
: IRequestHandler<Query, ProfileEnvelope>
{
public Task<ProfileEnvelope> Handle(Query message, CancellationToken cancellationToken) => profileReader.ReadProfile(message.Username, cancellationToken);
public Task<ProfileEnvelope> Handle(Query message, CancellationToken cancellationToken) =>
profileReader.ReadProfile(message.Username, cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/Conduit/Features/Profiles/IProfileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ namespace Conduit.Features.Profiles;
public interface IProfileReader
{
Task<ProfileEnvelope> ReadProfile(string username, CancellationToken cancellationToken);
}
}
Loading

0 comments on commit b5ea3c7

Please sign in to comment.