Le créateur vient de l'authentification, donc on ne le prend pas du post #10

Merged
notazof merged 1 commit from fix/OIDC-debugging into main 2026-08-02 23:04:10 +01:00
3 changed files with 23 additions and 13 deletions

27
.vscode/tasks.json vendored
View file

@ -13,16 +13,17 @@
"isBackground": true
},
{
"label": "build-web",
"label": "test blogs backend",
"type": "process",
"problemMatcher": ["$msCompile"],
"command": "dotnet",
"args": ["build"],
"args": ["test"],
"options": {
"cwd": "src/Yavsc.Org"
"cwd": "src/Yavsc.Blogs.Tests"
},
"group": {
"kind": "build"
"kind": "test",
"isDefault": false
}
},
{
@ -40,17 +41,23 @@
"isBackground": true
},
{
"label": "build-web",
"label": "test blogs",
"type": "process",
"problemMatcher": ["$msCompile"],
"command": "dotnet",
"args": ["build"],
"runOptions": {},
"args": ["test"],
"runOptions": {
"instanceLimit": 1
},
"options": {
"cwd": "src/Yavsc.Web"
"cwd": "src/Yavsc.Blogs",
"env": {
"DOTNET_CLI_UI_LANGUAGE": "en-US",
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"group": {
"kind": "build"
"kind": "test"
},
"isBackground": true,
"presentation": {
@ -82,7 +89,7 @@
],
"problemMatcher": "$msCompile",
"runOptions": {
}
}

View file

@ -114,7 +114,8 @@ namespace Yavsc.Blogs.Controllers
var files = Request.HasFormContentType
? Request.Form.Files
: (IFormFileCollection)new FormFileCollection();
var post = blogSpotService.Create(User.GetUserId(), blog, files);
var uid = User.GetUserId();
var post = blogSpotService.Create(uid, blog, files);
return CreatedAtRoute("GetBlog", new { id = post.Id }, post);
}

View file

@ -29,6 +29,8 @@ public class BlogSpotService
public BlogPost Create(string userId, BlogPost post, IFormFileCollection files)
{
// Sauvegarder le post d'abord pour obtenir son ID
// Le créateur vient de l'authentification, donc on ne le prend pas du post
post.AuthorId = userId;
_context.BlogSpot.Add(post);
_context.SaveChanges(userId);
@ -94,9 +96,9 @@ public class BlogSpotService
if (!auth.Succeeded)
{
throw new AuthorizationFailureException(auth);
}
}
var pub = await _context.blogSpotPublications.AnyAsync(x => x.BlogpostId == blog.Id);
return new BlogPostEditViewModel(blog, pub);
}