From 3b21a12c20ff5a393cdcf9e59110c1e17cceb96d Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 2 Aug 2026 23:02:54 +0100 Subject: [PATCH] =?UTF-8?q?Le=20cr=C3=A9ateur=20vient=20de=20l'authentific?= =?UTF-8?q?ation,=20donc=20on=20ne=20le=20prend=20pas=20du=20post?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/tasks.json | 27 ++++++++++++------- .../Controllers/BlogApiController.cs | 3 ++- src/Yavsc.Server/Services/BlogSpotService.cs | 6 +++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c384ec79..e45a9921 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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": { - + } } diff --git a/src/Yavsc.Blogs/Controllers/BlogApiController.cs b/src/Yavsc.Blogs/Controllers/BlogApiController.cs index 6a41b4ee..69b37e60 100644 --- a/src/Yavsc.Blogs/Controllers/BlogApiController.cs +++ b/src/Yavsc.Blogs/Controllers/BlogApiController.cs @@ -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); } diff --git a/src/Yavsc.Server/Services/BlogSpotService.cs b/src/Yavsc.Server/Services/BlogSpotService.cs index 8dfa9e33..a8b52d0d 100644 --- a/src/Yavsc.Server/Services/BlogSpotService.cs +++ b/src/Yavsc.Server/Services/BlogSpotService.cs @@ -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); }