Skip to content

Commit

Permalink
Migrate Web - Step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Aug 31, 2024
1 parent ad1d1dd commit fc33177
Show file tree
Hide file tree
Showing 59 changed files with 310 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Domain/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public abstract class Entity
{
public string? Id { get; set; }
public string Id { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async Task DeleteBulkAsyncInBatchesAsync()
var currentBatchIds = idList.Skip(batch * batchSize).Take(batchSize).ToList();

await blogDbContext.Set<TEntity>()
.Where(s => currentBatchIds.Contains(s.Id!))
.Where(s => currentBatchIds.Contains(s.Id))
.ExecuteDeleteAsync();

LogDeleteBatch(batch + 1, (batch + 1) * batchSize);
Expand Down
16 changes: 9 additions & 7 deletions src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.ComponentModel.DataAnnotations;

namespace LinkDotNet.Blog.Web;

public sealed record ApplicationConfiguration
{
public string BlogName { get; init; }
public required string BlogName { get; init; }

public string BlogBrandUrl { get; init; }
public string? BlogBrandUrl { get; init; }

public string ConnectionString { get; init; }
public required string ConnectionString { get; init; }

public string DatabaseName { get; init; }
public required string DatabaseName { get; init; }

public int BlogPostsPerPage { get; init; } = 10;

Expand All @@ -20,17 +22,17 @@ public sealed record ApplicationConfiguration

public bool IsDisqusEnabled { get; set; }

public string KofiToken { get; init; }
public string? KofiToken { get; init; }

public bool IsKofiEnabled => !string.IsNullOrEmpty(KofiToken);

public string GithubSponsorName { get; init; }
public string? GithubSponsorName { get; init; }

public bool IsGithubSponsorAvailable => !string.IsNullOrEmpty(GithubSponsorName);

public bool ShowReadingIndicator { get; init; }

public string PatreonName { get; init; }
public string? PatreonName { get; init; }

public bool IsPatreonEnabled => !string.IsNullOrEmpty(PatreonName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public sealed record AuthInformation

public const string AuthInformationSection = "Authentication";

public string Provider { get; set; }
public required string Provider { get; set; }

public string Domain { get; init; }
public required string Domain { get; init; }

public string ClientId { get; init; }
public required string ClientId { get; init; }

public string ClientSecret { get; init; }
public required string ClientSecret { get; init; }

public string LogoutUri
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ OnYesPressed="DeleteItem"></ConfirmDialog>
[Parameter]
public bool ShowAdminActions { get; set; }

[Parameter]
public ProfileInformation ProfileInformation { get; set; }
[Parameter, EditorRequired]
public required ProfileInformation ProfileInformation { get; set; }

private List<ProfileInformationEntry> profileInformationEntries = [];
private ConfirmDialog Dialog { get; set; }
private string currentDeleteKey;
private ProfileInformationEntry currentDragItem;
private ConfirmDialog Dialog { get; set; } = default!;
private string? currentDeleteKey;
private ProfileInformationEntry? currentDragItem;

protected override async Task OnInitializedAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public EventCallback<Skill> SkillAdded { get; set; }

private AddSkillModel model = new();
private ModalDialog Dialog { get; set; }
private ModalDialog Dialog { get; set; } = default!;

public void Open()
{
Expand All @@ -46,9 +46,12 @@

private async Task CreateSkillItem()
{
ArgumentNullException.ThrowIfNull(model.Skill);
ArgumentNullException.ThrowIfNull(model.Capability);

var skill = Skill.Create(model.Skill, model.ImageUrl, model.Capability, model.Proficiency);
await SkillAdded.InvokeAsync(skill);
model = new AddSkillModel();
ToastService.ShowSuccess($"Created Skill {skill.Name} in capability {skill.Capability} with level {skill.ProficiencyLevel}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace LinkDotNet.Blog.Web.Features.AboutMe.Components.Skill;
public sealed class AddSkillModel
{
[Required]
public string Skill { get; set; }
public string? Skill { get; set; }

public string ImageUrl { get; set; }
public string? ImageUrl { get; set; }

[Required]
public string Proficiency { get; set; } = ProficiencyLevel.Familiar.Key;

[Required]
public string Capability { get; set; }
}
public string? Capability { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
[Parameter]
public bool ShowAdminActions { get; set; }

private AddSkillDialog AddSkillDialog { get; set; }
private AddSkillDialog AddSkillDialog { get; set; } = default!;

private List<Skill> skills = [];

private Skill currentDragItem;
private Skill? currentDragItem;

protected override async Task OnInitializedAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
</span>

@code {
[Parameter]
public Skill Skill { get; set; }
[Parameter, EditorRequired]
public required Skill Skill { get; set; }

[Parameter]
public bool ShowAdminActions { get; set; }

[Parameter]
public EventCallback DeleteSkill { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
[Parameter]
public EventCallback<Talk> TalkCreated { get; set; }

private ModalDialog Dialog { get; set; }
private ModalDialog Dialog { get; set; } = default!;

private AddTalkEntryModel model = new();

public void Open()
Expand All @@ -42,6 +43,10 @@

private async Task CreateTalk()
{
ArgumentNullException.ThrowIfNull(model.PresentationTitle);
ArgumentNullException.ThrowIfNull(model.Place);
ArgumentNullException.ThrowIfNull(model.Description);

var talk = Talk.Create(model.PresentationTitle, model.Place, model.Description, model.PublishedDate);
await TalkCreated.InvokeAsync(talk);
model = new AddTalkEntryModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public sealed class AddTalkEntryModel
{
[Required]
[MaxLength(256)]
public string PresentationTitle { get; set; }
public string? PresentationTitle { get; set; }

[Required]
[MaxLength(256)]
public string Place { get; set; }
public string? Place { get; set; }

[Required]
public string Description { get; set; }
public string? Description { get; set; }

[Required]
public DateTime PublishedDate { get; set; } = DateTime.Now;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
[Parameter]
public EventCallback TalkDeleted { get; set; }

[Parameter]
public Talk Talk { get; set; }
[Parameter, EditorRequired]
public required Talk Talk { get; set; }

public override Task SetParametersAsync(ParameterView parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

private List<Talk> talks = [];

private AddTalkEntryDialog AddTalkEntryDialog { get; set; }
private AddTalkEntryDialog AddTalkEntryDialog { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<DataAnnotationsValidator />
<div class="form-floating mb-3">
<input type="text" class="form-control" id="title" placeholder="Title"
@oninput="args => model.Title = args.Value.ToString()" value="@model.Title"/>
@oninput="args => model.Title = args.Value!.ToString()!" value="@model.Title"/>
<label for="title">Title</label>
<ValidationMessage For="() => model.Title"></ValidationMessage>
</div>
Expand Down Expand Up @@ -79,18 +79,18 @@
<NavigationLock ConfirmExternalNavigation="@model.IsDirty" OnBeforeInternalNavigation="PreventNavigationWhenDirty"></NavigationLock>
@code {
[Parameter]
public BlogPost BlogPost { get; set; }
public BlogPost? BlogPost { get; set; }

[Parameter]
public string Title { get; set; }
[Parameter, EditorRequired]
public required string Title { get; set; }

[Parameter]
public EventCallback<BlogPost> OnBlogPostCreated { get; set; }

[Parameter]
public bool ClearAfterCreated { get; set; } = true;

private FeatureInfoDialog FeatureDialog { get; set; }
private FeatureInfoDialog FeatureDialog { get; set; } = default!;

private CreateNewModel model = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Components;
public sealed class CreateNewModel
{
private DateTime originalUpdatedDate;
private string id;
private string title;
private string shortDescription;
private string content;
private string previewImageUrl;
private string id = string.Empty;
private string title = string.Empty;
private string shortDescription = string.Empty;
private string content = string.Empty;
private string previewImageUrl = string.Empty;
private bool isPublished = true;
private bool shouldUpdateDate;
private string tags;
private string previewImageUrlFallback;
private string tags = string.Empty;
private string previewImageUrlFallback = string.Empty;
private DateTime? scheduledPublishDate;

[Required]
Expand Down Expand Up @@ -100,7 +100,7 @@ public static CreateNewModel FromBlogPost(BlogPost blogPost)
IsPublished = blogPost.IsPublished,
PreviewImageUrl = blogPost.PreviewImageUrl,
originalUpdatedDate = blogPost.UpdatedDate,
PreviewImageUrlFallback = blogPost.PreviewImageUrlFallback,
PreviewImageUrlFallback = blogPost.PreviewImageUrlFallback ?? string.Empty,
ScheduledPublishDate = blogPost.ScheduledPublishDate,
IsDirty = false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Components;
[AttributeUsage(AttributeTargets.Property)]
public sealed class FallbackUrlValidationAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
ArgumentNullException.ThrowIfNull(validationContext);

var model = validationContext.ObjectInstance as CreateNewModel;
var model = (CreateNewModel)validationContext.ObjectInstance;

return model.PreviewImageUrl == model.PreviewImageUrlFallback
? new ValidationResult("Preview image url and the fallback preview image url should not be the same.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ModalDialog>

@code {
private ModalDialog FeatureDialog { get; set; }
private ModalDialog FeatureDialog { get; set; } = default!;

public void Open()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Components;
[AttributeUsage(AttributeTargets.Property)]
public sealed class FutureDateValidationAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
return value is not DateTime dt || dt > DateTime.UtcNow
? ValidationResult.Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Components;
[AttributeUsage(AttributeTargets.Property)]
public sealed class PublishedWithScheduledDateValidationAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
ArgumentNullException.ThrowIfNull(validationContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@inject IRepository<BlogPost> BlogPostRepository
@inject IToastService ToastService

<CreateNewBlogPost Title="Create New Blog Post" OnBlogPostCreated="@(StoreBlogPostAsync)" ></CreateNewBlogPost>
<CreateNewBlogPost Title="Create New Blog Post" OnBlogPostCreated="@(StoreBlogPostAsync)"></CreateNewBlogPost>

@code {
private async Task StoreBlogPostAsync(BlogPost blogPost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ else
}

@code {
[Parameter]
public string BlogPostId { get; set; }
[Parameter, EditorRequired]
public required string BlogPostId { get; set; }

private BlogPost blogPostFromDb;
private BlogPost? blogPostFromDb;

protected override async Task OnParametersSetAsync()
{
ArgumentException.ThrowIfNullOrEmpty(BlogPostId, nameof(BlogPostId));
ArgumentException.ThrowIfNullOrEmpty(BlogPostId);

blogPostFromDb = await BlogPostRepository.GetByIdAsync(BlogPostId);
}

private async Task StoreBlogPostAsync(BlogPost blogPost)
{
ArgumentNullException.ThrowIfNull(blogPostFromDb);

blogPostFromDb.Update(blogPost);
await BlogPostRepository.StoreAsync(blogPostFromDb);
ToastService.ShowInfo($"Updated BlogPost {blogPost.Title}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

@code {
private Filter filter = new();
private IReadOnlyCollection<VisitCountPageData> visitData;
private IReadOnlyCollection<VisitCountPageData> visitData = [];

protected override async Task OnInitializedAsync()
{
Expand All @@ -63,7 +63,7 @@
IRepository<BlogPost> blogPostRepository,
Filter filter)
{
Expression<Func<BlogPost, bool>> blogPostFilter = filter.EndDate.HasValue
Expression<Func<BlogPost, bool>>? blogPostFilter = filter.EndDate.HasValue
? bp => bp.UpdatedDate.Date <= filter.EndDate.Value.ToDateTime(default)
: null;

Expand Down
Loading

0 comments on commit fc33177

Please sign in to comment.