refactor: match db change from INT to UUID for pkeys
This commit is contained in:
parent
c2deccafae
commit
0ecef1a547
@ -1,4 +1,4 @@
|
||||
@page "/blog/{year:int}/{month:int}/{day:int}/{slug}"
|
||||
@page "/blog/{year:int}/{month:int}/{day:int}/{slug}"
|
||||
@using Humanizer
|
||||
@using OliverBooth.Data.Blog
|
||||
@using OliverBooth.Services
|
||||
@ -64,7 +64,7 @@
|
||||
this.page.url = "@post.GetDisqusUrl()";
|
||||
this.page.identifier = "@post.GetDisqusIdentifier()";
|
||||
this.page.title = "@post.Title";
|
||||
this.page.postId = "@(post.WordPressId ?? post.Id)";
|
||||
this.page.postId = "@(post.WordPressId?.ToString() ?? post.Id.ToString())";
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using OliverBooth.Data.Blog;
|
||||
using OliverBooth.Services;
|
||||
@ -14,7 +14,7 @@ public class Index : PageModel
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
public IActionResult OnGet([FromQuery(Name = "pid")] int? postId = null,
|
||||
public IActionResult OnGet([FromQuery(Name = "pid")] Guid? postId = null,
|
||||
[FromQuery(Name = "p")] int? wpPostId = null)
|
||||
{
|
||||
if (postId.HasValue == wpPostId.HasValue)
|
||||
@ -25,7 +25,7 @@ public class Index : PageModel
|
||||
return postId.HasValue ? HandleNewRoute(postId.Value) : HandleWordPressRoute(wpPostId!.Value);
|
||||
}
|
||||
|
||||
private IActionResult HandleNewRoute(int postId)
|
||||
private IActionResult HandleNewRoute(Guid postId)
|
||||
{
|
||||
return _blogService.TryGetBlogPost(postId, out BlogPost? post) ? RedirectToPost(post) : NotFound();
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ public sealed class BlogApiController : ControllerBase
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpGet("author/{id:int}")]
|
||||
public IActionResult GetAuthor(int id)
|
||||
[HttpGet("author/{id:guid}")]
|
||||
public IActionResult GetAuthor(Guid id)
|
||||
{
|
||||
if (!ValidateReferer()) return NotFound();
|
||||
if (!_blogService.TryGetAuthor(id, out Author? author)) return NotFound();
|
||||
|
@ -48,7 +48,7 @@ public sealed class Author : IEquatable<Author>
|
||||
/// Gets the ID of the author.
|
||||
/// </summary>
|
||||
/// <value>The ID.</value>
|
||||
public int Id { get; private set; }
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the author.
|
||||
@ -70,6 +70,6 @@ public sealed class Author : IEquatable<Author>
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id;
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public sealed class BlogPost : IEquatable<BlogPost>
|
||||
/// Gets the ID of the author.
|
||||
/// </summary>
|
||||
/// <value>The author ID.</value>
|
||||
public int AuthorId { get; private set; }
|
||||
public Guid AuthorId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body of the blog post.
|
||||
@ -47,7 +47,7 @@ public sealed class BlogPost : IEquatable<BlogPost>
|
||||
/// Gets the ID of the blog post.
|
||||
/// </summary>
|
||||
/// <value>The ID.</value>
|
||||
public int Id { get; private set; }
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the blog post is a redirect.
|
||||
@ -181,6 +181,6 @@ public sealed class BlogPost : IEquatable<BlogPost>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// ReSharper disable once NonReadonlyMemberInGetHashCode
|
||||
return Id;
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ internal sealed class AuthorConfiguration : IEntityTypeConfiguration<Author>
|
||||
builder.ToTable("Author");
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
builder.Property(e => e.Id);
|
||||
builder.Property(e => e.Name).HasMaxLength(100).IsRequired();
|
||||
builder.Property(e => e.EmailAddress).HasMaxLength(255).IsRequired(false);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
||||
builder.ToTable("BlogPost");
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
builder.Property(e => e.Id);
|
||||
builder.Property(e => e.WordPressId).IsRequired(false);
|
||||
builder.Property(e => e.Slug).HasMaxLength(100).IsRequired();
|
||||
builder.Property(e => e.AuthorId).IsRequired();
|
||||
|
Loading…
Reference in New Issue
Block a user