From 0d2d4160afdee5250fee195f7c2585934017cf72 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 6 Jul 2026 20:58:58 +0100 Subject: [PATCH 1/3] PostIt: fix blog API double-prefix; drop redundant New BlogApiClient's "api/blog" path combined with the BaseAddress's "api/v1/" prefix to produce 404s on every call. Drop the redundant "api/" segment, let Save handle the create case (no selection) and remove the now-redundant New button + command. --- src/PostIt/PostIt/Services/BlogApiClient.cs | 2 +- .../PostIt/ViewModels/MainPageViewModel.cs | 35 +++++++++++-------- src/PostIt/PostIt/Views/MainPage.axaml | 1 - .../Controllers/BlogApiController.cs | 1 - 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/PostIt/PostIt/Services/BlogApiClient.cs b/src/PostIt/PostIt/Services/BlogApiClient.cs index dbe86ca3..5ebfe264 100644 --- a/src/PostIt/PostIt/Services/BlogApiClient.cs +++ b/src/PostIt/PostIt/Services/BlogApiClient.cs @@ -22,7 +22,7 @@ namespace PostIt.Services; /// public sealed class BlogApiClient { - private const string DefaultPathPrefix = "api/blog"; + private const string DefaultPathPrefix = "blog"; private readonly YavscApiClient _api; private readonly string _pathPrefix; diff --git a/src/PostIt/PostIt/ViewModels/MainPageViewModel.cs b/src/PostIt/PostIt/ViewModels/MainPageViewModel.cs index 21b8b22b..073ebf7a 100644 --- a/src/PostIt/PostIt/ViewModels/MainPageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/MainPageViewModel.cs @@ -128,9 +128,28 @@ public partial class MainPageViewModel : ViewModelBase [RelayCommand] internal async Task Save() { + // No selection means "create a new post from the editor". + // The server is the source of truth, so we POST without an id + // and let BlogApiController assign one. The local view-model + // is then rebound to the server-issued record. if (SelectedPost is null) { - StatusMessage = "A post must be selected before saving."; + var draft = new BlogPost + { + Title = string.Empty, + Article = string.Empty, + DateCreated = DateTime.UtcNow, + DateModified = DateTime.UtcNow + }; + await ExecuteAsync(async () => + { + var created = await BlogClient.CreatePostAsync(draft); + if (created is not null) + { + SelectedPost = created; + StatusMessage = $"Created post {created.Id}."; + } + }); return; } @@ -176,19 +195,6 @@ public partial class MainPageViewModel : ViewModelBase }); } - [RelayCommand] - internal void New() - { - SelectedPost = new BlogPost - { - Title = string.Empty, - Article = string.Empty, - DateCreated = DateTime.UtcNow, - DateModified = DateTime.UtcNow - }; - StatusMessage = "New blog post ready."; - } - [RelayCommand] internal void OpenSettings() { @@ -253,7 +259,6 @@ public partial class MainPageViewModel : ViewModelBase LoadPostsCommand.NotifyCanExecuteChanged(); SaveCommand.NotifyCanExecuteChanged(); DeleteCommand.NotifyCanExecuteChanged(); - NewCommand.NotifyCanExecuteChanged(); } private bool CanSave() => SelectedPost is not null && !IsBusy; diff --git a/src/PostIt/PostIt/Views/MainPage.axaml b/src/PostIt/PostIt/Views/MainPage.axaml index c09c2f7a..247bf28e 100644 --- a/src/PostIt/PostIt/Views/MainPage.axaml +++ b/src/PostIt/PostIt/Views/MainPage.axaml @@ -32,7 +32,6 @@