Compare commits
No commits in common. "46a9a84fbc58d2321901bce1c8bc839c182085de" and "a5ccfde7e17ed239ff3f508ede9790d434f642be" have entirely different histories.
46a9a84fbc
...
a5ccfde7e1
4 changed files with 12 additions and 56 deletions
|
|
@ -67,7 +67,7 @@
|
||||||
|
|
||||||
<Border Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Padding="8">
|
<Border Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Padding="8">
|
||||||
<ListBox ItemsSource="{Binding FilteredPosts}" SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
<ListBox ItemsSource="{Binding FilteredPosts}" SelectedItem="{Binding SelectedPost, Mode=TwoWay}"
|
||||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40">
|
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate x:DataType="models:BlogPostDto">
|
<DataTemplate x:DataType="models:BlogPostDto">
|
||||||
<StackPanel Spacing="4">
|
<StackPanel Spacing="4">
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ public sealed class CircleMembersApiTests : IClassFixture<BlogsWebServerFixture>
|
||||||
}
|
}
|
||||||
|
|
||||||
private string MembersUrl(long circleId)
|
private string MembersUrl(long circleId)
|
||||||
=> $"{_fixture.Addresses.First(a => a.StartsWith("https://"))}/{Constants.APIPrefix}/circle/{circleId}/members";
|
=> $"{_fixture.Addresses.First(a => a.StartsWith("https://"))}/api/circle/{circleId}/members";
|
||||||
|
|
||||||
private HttpClient NewClient(string subject)
|
private HttpClient NewClient(string subject)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Yavsc.Blogspot;
|
using Yavsc.Blogspot;
|
||||||
|
using Yavsc.Models.Blog;
|
||||||
using Yavsc.Server.Exceptions;
|
using Yavsc.Server.Exceptions;
|
||||||
using Yavsc.Server.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
using static Yavsc.Blogs.Constants;
|
using static Yavsc.Blogs.Constants;
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,11 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Relationship;
|
using Yavsc.Models.Relationship;
|
||||||
using Yavsc.Server.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
using static Yavsc.Blogs.Constants;
|
|
||||||
|
|
||||||
namespace Yavsc.Blogs.Controllers
|
namespace Yavsc.Blogs.Controllers
|
||||||
{
|
{
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route(APIPrefix +"/circle")]
|
[Route("api/circle")]
|
||||||
public class CircleApiController : Controller
|
public class CircleApiController : Controller
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _context;
|
private readonly ApplicationDbContext _context;
|
||||||
|
|
@ -57,25 +56,12 @@ namespace Yavsc.Blogs.Controllers
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces a circle. The caller must own it; the server
|
/// Replaces a circle. The caller must own it; the server
|
||||||
/// reasserts ownership regardless of any <c>OwnerId</c>
|
/// reasserts ownership regardless of any OwnerId the client
|
||||||
/// the client tries to put in the body.
|
/// tries to put in the body.
|
||||||
///
|
|
||||||
/// <para>The body shape is a <see cref="CircleDto"/> — a
|
|
||||||
/// flat, navigation-free projection — not the EF entity.
|
|
||||||
/// The EF entity carries <c>[JsonIgnore]</c>-decorated
|
|
||||||
/// navigation properties (<c>Owner</c>, <c>Members</c>)
|
|
||||||
/// that bind to server-only types (<c>ApplicationUser</c>,
|
|
||||||
/// <c>CircleMember</c>); keeping the wire shape as a
|
|
||||||
/// DTO avoids any future regression where the entity
|
|
||||||
/// grows a navigable property that System.Text.Json
|
|
||||||
/// refuses to materialise. The client-side mirror lives
|
|
||||||
/// in <c>Yavsc.Api.Client.Dtos.CircleDto</c>.</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// PUT: api/circle/5
|
// PUT: api/circle/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public async Task<IActionResult> PutCircle(
|
public async Task<IActionResult> PutCircle([FromRoute] long id, [FromBody] Circle circle)
|
||||||
[FromRoute] long id,
|
|
||||||
[FromBody] CircleDto circle)
|
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
@ -95,14 +81,9 @@ namespace Yavsc.Blogs.Controllers
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the wire shape onto the entity. OwnerId is
|
// Force OwnerId to the caller; the body value is ignored.
|
||||||
// forced to the caller regardless of what the body
|
circle.OwnerId = uid;
|
||||||
// says; Name and Public come from the body.
|
_context.Entry(circle).State = EntityState.Modified;
|
||||||
existing.Name = circle.Name;
|
|
||||||
existing.Public = circle.Public;
|
|
||||||
existing.OwnerId = uid;
|
|
||||||
|
|
||||||
_context.Entry(existing).State = EntityState.Modified;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -129,7 +110,7 @@ namespace Yavsc.Blogs.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// POST: api/circle
|
// POST: api/circle
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> PostCircle([FromBody] CircleDto circle)
|
public async Task<IActionResult> PostCircle([FromBody] Circle circle)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
@ -138,14 +119,8 @@ namespace Yavsc.Blogs.Controllers
|
||||||
|
|
||||||
var uid = User.GetUserId();
|
var uid = User.GetUserId();
|
||||||
circle.OwnerId = uid;
|
circle.OwnerId = uid;
|
||||||
Circle newCircle = new Circle
|
|
||||||
{
|
|
||||||
OwnerId = User.GetUserId(),
|
|
||||||
Name = circle.Name,
|
|
||||||
Public = circle.Public
|
|
||||||
};
|
|
||||||
|
|
||||||
_context.Circle.Add(newCircle);
|
_context.Circle.Add(circle);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _context.SaveChangesAsync(User.GetUserId());
|
await _context.SaveChangesAsync(User.GetUserId());
|
||||||
|
|
@ -346,26 +321,6 @@ namespace Yavsc.Blogs.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wire shape for <c>PUT /api/circle/{id}</c>. Flat by
|
|
||||||
/// design — navigation properties (<c>Owner</c>,
|
|
||||||
/// <c>Members</c>) live on the EF entity only and never
|
|
||||||
/// cross the wire.
|
|
||||||
///
|
|
||||||
/// <para>Field names match the JSON the server emits
|
|
||||||
/// (camelCase via ASP.NET Core's Web defaults), so no
|
|
||||||
/// <c>[JsonPropertyName]</c> attributes are required.
|
|
||||||
/// Mirrors the client-side <c>Yavsc.Api.Client.Dtos.CircleDto</c>
|
|
||||||
/// — keep them in sync.</para>
|
|
||||||
/// </summary>
|
|
||||||
public sealed class CircleDto
|
|
||||||
{
|
|
||||||
public long Id { get; set; }
|
|
||||||
public string Name { get; set; } = string.Empty;
|
|
||||||
public string OwnerId { get; set; } = string.Empty;
|
|
||||||
public bool Public { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wire shape for <c>GET /api/circle/{id}/members</c>.
|
/// Wire shape for <c>GET /api/circle/{id}/members</c>.
|
||||||
/// Mirrors <see cref="UserSearchResultDto"/> but stops
|
/// Mirrors <see cref="UserSearchResultDto"/> but stops
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue