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.
This commit is contained in:
parent
f2ae01729a
commit
0d2d4160af
4 changed files with 21 additions and 18 deletions
|
|
@ -22,7 +22,7 @@ namespace PostIt.Services;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class BlogApiClient
|
public sealed class BlogApiClient
|
||||||
{
|
{
|
||||||
private const string DefaultPathPrefix = "api/blog";
|
private const string DefaultPathPrefix = "blog";
|
||||||
|
|
||||||
private readonly YavscApiClient _api;
|
private readonly YavscApiClient _api;
|
||||||
private readonly string _pathPrefix;
|
private readonly string _pathPrefix;
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,28 @@ public partial class MainPageViewModel : ViewModelBase
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
internal async Task Save()
|
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)
|
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;
|
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]
|
[RelayCommand]
|
||||||
internal void OpenSettings()
|
internal void OpenSettings()
|
||||||
{
|
{
|
||||||
|
|
@ -253,7 +259,6 @@ public partial class MainPageViewModel : ViewModelBase
|
||||||
LoadPostsCommand.NotifyCanExecuteChanged();
|
LoadPostsCommand.NotifyCanExecuteChanged();
|
||||||
SaveCommand.NotifyCanExecuteChanged();
|
SaveCommand.NotifyCanExecuteChanged();
|
||||||
DeleteCommand.NotifyCanExecuteChanged();
|
DeleteCommand.NotifyCanExecuteChanged();
|
||||||
NewCommand.NotifyCanExecuteChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanSave() => SelectedPost is not null && !IsBusy;
|
private bool CanSave() => SelectedPost is not null && !IsBusy;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
<Button Command="{Binding LoadPosts}" Content="Load posts" />
|
<Button Command="{Binding LoadPosts}" Content="Load posts" />
|
||||||
<Button Command="{Binding Search}" Content="Filter" />
|
<Button Command="{Binding Search}" Content="Filter" />
|
||||||
<Button Command="{Binding New}" Content="New post" />
|
|
||||||
<Button Command="{Binding Save}" Content="Save" />
|
<Button Command="{Binding Save}" Content="Save" />
|
||||||
<Button Command="{Binding Delete}" Content="Delete" />
|
<Button Command="{Binding Delete}" Content="Delete" />
|
||||||
<!--
|
<!--
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ namespace Yavsc.Blogs.Controllers
|
||||||
[Authorize("BlogScope")]
|
[Authorize("BlogScope")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route(APIPrefix + "/blog")]
|
[Route(APIPrefix + "/blog")]
|
||||||
|
|
||||||
public class BlogApiController : Controller
|
public class BlogApiController : Controller
|
||||||
{
|
{
|
||||||
private readonly BlogSpotService blogSpotService;
|
private readonly BlogSpotService blogSpotService;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue