fix bugs 🐛

deploiementJeanMarcillacWeb1
Tony Fages 1 year ago
parent 89c4de82c8
commit 610ccb8284

@ -125,7 +125,7 @@ namespace API.Controllers
} }
} }
[HttpGet("/articleUsers")] [HttpGet("/user/article/users")]
public async Task<IActionResult> GetAllArticleUsers() public async Task<IActionResult> GetAllArticleUsers()
{ {
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), ""); _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), "");
@ -145,7 +145,7 @@ namespace API.Controllers
} }
} }
[HttpGet("/user/{pseudo}/article")] [HttpGet("/user/{pseudo}/articles")]
public async Task<IActionResult> GetArticleUser(string pseudo) public async Task<IActionResult> GetArticleUser(string pseudo)
{ {
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo); _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo);
@ -206,18 +206,37 @@ namespace API.Controllers
} }
} }
[HttpPut("/user/{pseudo}/article")] [HttpPut("/user/{pseudo}/{oldId}")]
public async Task<IActionResult> UpdateArticleUser(ArticleUserEntity articleUser) public async Task<IActionResult> UpdateArticleUser(ArticleUserEntity articleUser, long oldId)
{ {
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser); _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser);
try try
{ {
var result = (await _dataManager.UserService.UpdateArticleUser(articleUser)); // Retrieve the existing entity
if (!result) var existingEntity = await _dataManager.UserService.GetArticleUser(articleUser.UserEntityPseudo);
if (existingEntity == null)
{ {
return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} does not exist"); return NotFound($"ArticleUser {articleUser.UserEntityPseudo} does not exist");
} }
return Ok(result);
// Delete the existing entity
var deleteResult = await _dataManager.UserService.DeleteArticleUser(articleUser.UserEntityPseudo, oldId);
if (!deleteResult)
{
return BadRequest($"Failed to delete ArticleUser {articleUser.UserEntityPseudo}");
}
// Create a new entity with the updated values
var createResult = await _dataManager.UserService.CreateArticleUser(articleUser);
if (createResult == null)
{
return BadRequest($"Failed to create ArticleUser {articleUser.UserEntityPseudo}");
}
return Ok(createResult);
} }
catch (Exception error) catch (Exception error)
{ {
@ -225,7 +244,5 @@ namespace API.Controllers
return BadRequest(error.Message); return BadRequest(error.Message);
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

@ -12,32 +12,32 @@ class Tests_Console
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
//await TestUser(); await TestUser();
await TestFormulaire(); //await TestFormulaire();
//await TestArticle(); //await TestArticle();
} }
private static async Task TestFormulaire() private static async Task TestFormulaire()
{ {
await TestFormulaireGetAll(); await TestFormulaireGetAll();
//await TestFormulaireGetId(); await TestFormulaireGetId();
//await TestFormulaireCreate(); await TestFormulaireCreate();
//await TestFormulaireDelete(); await TestFormulaireDelete();
//await TestFormulaireUpdate(); await TestFormulaireUpdate();
} }
private static async Task TestUser() private static async Task TestUser()
{ {
//await TestUserGetAll(); await TestUserGetAll();
//await TestUserGetId(); await TestUserGetId();
//await TestUserCreate(); //await TestUserCreate();
//await TestUserDelete(); //await TestUserDelete();
//await TestUserUpdate(); //await TestUserUpdate();
//await TestGetAllArticleUser(); await TestGetAllArticleUser();
//await TestGetArticleByUser(); await TestGetArticleByUser();
//await TestCreateArticleUser(); //await TestCreateArticleUser();
//await TestDeleteArticleUser(); //await TestDeleteArticleUser();
//await TestUpdateArticleUser(); await TestUpdateArticleUser();
} }
@ -109,7 +109,7 @@ class Tests_Console
{ {
try try
{ {
var response = await client.DeleteAsync("http://localhost:5052/article/4"); var response = await client.DeleteAsync("http://localhost:5052/article/1");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody); Console.WriteLine(responseBody);
@ -339,7 +339,7 @@ class Tests_Console
{ {
try try
{ {
var response = await client.GetAsync("http://localhost:5052/ArticleUsers"); var response = await client.GetAsync("http://localhost:5052/user/article/users");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody); Console.WriteLine(responseBody);
@ -354,7 +354,7 @@ class Tests_Console
{ {
try try
{ {
var response = await client.GetAsync("http://localhost:5052/user/Sha/article"); var response = await client.GetAsync("http://localhost:5052/user/Sha/articles");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody); Console.WriteLine(responseBody);
@ -391,7 +391,7 @@ class Tests_Console
{ {
try try
{ {
var response = await client.DeleteAsync("http://localhost:5052/user/Sha/article"); var response = await client.DeleteAsync("http://localhost:5052/user/Sha/3");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody); Console.WriteLine(responseBody);
@ -408,12 +408,13 @@ class Tests_Console
{ {
var articleUser = new ArticleUserEntity() var articleUser = new ArticleUserEntity()
{ {
ArticleEntityId = 1, ArticleEntityId = 2,
UserEntityPseudo = "Sha" UserEntityPseudo = "Sha"
}; };
long oldId = 3;
var json = JsonSerializer.Serialize(articleUser); var json = JsonSerializer.Serialize(articleUser);
var data = new StringContent(json, Encoding.UTF8, "application/json"); var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PutAsync("http://localhost:5052/user/Sha/article", data); var response = await client.PutAsync($"http://localhost:5052/user/Sha/{oldId}", data);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync(); var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody); Console.WriteLine(responseBody);

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DbContextLib.Migrations namespace DbContextLib.Migrations
{ {
[DbContext(typeof(LibraryContext))] [DbContext(typeof(LibraryContext))]
[Migration("20240316170807_mrg1")] [Migration("20240317095050_mrg1")]
partial class mrg1 partial class mrg1
{ {
/// <inheritdoc /> /// <inheritdoc />
Loading…
Cancel
Save