From 0ecef1a547b841ed761502d561dfc015b72d5aaf Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Fri, 11 Aug 2023 14:09:13 +0100 Subject: [PATCH] refactor: match db change from INT to UUID for pkeys --- OliverBooth/Areas/Blog/Pages/Article.cshtml | 4 ++-- OliverBooth/Areas/Blog/Pages/Index.cshtml.cs | 6 +++--- OliverBooth/Controllers/BlogApiController.cs | 4 ++-- OliverBooth/Data/Blog/Author.cs | 4 ++-- OliverBooth/Data/Blog/BlogPost.cs | 6 +++--- OliverBooth/Data/Blog/Configuration/AuthorConfiguration.cs | 2 +- .../Data/Blog/Configuration/BlogPostConfiguration.cs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/OliverBooth/Areas/Blog/Pages/Article.cshtml b/OliverBooth/Areas/Blog/Pages/Article.cshtml index 7db7936..6c2a044 100644 --- a/OliverBooth/Areas/Blog/Pages/Article.cshtml +++ b/OliverBooth/Areas/Blog/Pages/Article.cshtml @@ -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() { diff --git a/OliverBooth/Areas/Blog/Pages/Index.cshtml.cs b/OliverBooth/Areas/Blog/Pages/Index.cshtml.cs index 4866c4e..fde635e 100644 --- a/OliverBooth/Areas/Blog/Pages/Index.cshtml.cs +++ b/OliverBooth/Areas/Blog/Pages/Index.cshtml.cs @@ -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(); } diff --git a/OliverBooth/Controllers/BlogApiController.cs b/OliverBooth/Controllers/BlogApiController.cs index 198179f..f9f82f6 100644 --- a/OliverBooth/Controllers/BlogApiController.cs +++ b/OliverBooth/Controllers/BlogApiController.cs @@ -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(); diff --git a/OliverBooth/Data/Blog/Author.cs b/OliverBooth/Data/Blog/Author.cs index 9a5aa26..e7d5865 100644 --- a/OliverBooth/Data/Blog/Author.cs +++ b/OliverBooth/Data/Blog/Author.cs @@ -48,7 +48,7 @@ public sealed class Author : IEquatable /// Gets the ID of the author. /// /// The ID. - public int Id { get; private set; } + public Guid Id { get; private set; } /// /// Gets or sets the name of the author. @@ -70,6 +70,6 @@ public sealed class Author : IEquatable public override int GetHashCode() { - return Id; + return Id.GetHashCode(); } } diff --git a/OliverBooth/Data/Blog/BlogPost.cs b/OliverBooth/Data/Blog/BlogPost.cs index 0dabdc9..826934c 100644 --- a/OliverBooth/Data/Blog/BlogPost.cs +++ b/OliverBooth/Data/Blog/BlogPost.cs @@ -11,7 +11,7 @@ public sealed class BlogPost : IEquatable /// Gets the ID of the author. /// /// The author ID. - public int AuthorId { get; private set; } + public Guid AuthorId { get; private set; } /// /// Gets or sets the body of the blog post. @@ -47,7 +47,7 @@ public sealed class BlogPost : IEquatable /// Gets the ID of the blog post. /// /// The ID. - public int Id { get; private set; } + public Guid Id { get; private set; } /// /// Gets or sets a value indicating whether the blog post is a redirect. @@ -181,6 +181,6 @@ public sealed class BlogPost : IEquatable public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode - return Id; + return Id.GetHashCode(); } } diff --git a/OliverBooth/Data/Blog/Configuration/AuthorConfiguration.cs b/OliverBooth/Data/Blog/Configuration/AuthorConfiguration.cs index d7f9ca1..e8321af 100644 --- a/OliverBooth/Data/Blog/Configuration/AuthorConfiguration.cs +++ b/OliverBooth/Data/Blog/Configuration/AuthorConfiguration.cs @@ -14,7 +14,7 @@ internal sealed class AuthorConfiguration : IEntityTypeConfiguration 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); } diff --git a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs index 10ebe86..0ba9614 100644 --- a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs +++ b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs @@ -14,7 +14,7 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration 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();