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()
{
_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)
{
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo);
@ -206,18 +206,37 @@ namespace API.Controllers
}
}
[HttpPut("/user/{pseudo}/article")]
public async Task<IActionResult> UpdateArticleUser(ArticleUserEntity articleUser)
[HttpPut("/user/{pseudo}/{oldId}")]
public async Task<IActionResult> UpdateArticleUser(ArticleUserEntity articleUser, long oldId)
{
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser);
try
{
var result = (await _dataManager.UserService.UpdateArticleUser(articleUser));
if (!result)
// Retrieve the existing entity
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)
{
@ -225,7 +244,5 @@ namespace API.Controllers
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)
{
//await TestUser();
await TestFormulaire();
await TestUser();
//await TestFormulaire();
//await TestArticle();
}
private static async Task TestFormulaire()
{
await TestFormulaireGetAll();
//await TestFormulaireGetId();
//await TestFormulaireCreate();
//await TestFormulaireDelete();
//await TestFormulaireUpdate();
await TestFormulaireGetId();
await TestFormulaireCreate();
await TestFormulaireDelete();
await TestFormulaireUpdate();
}
private static async Task TestUser()
{
//await TestUserGetAll();
//await TestUserGetId();
await TestUserGetAll();
await TestUserGetId();
//await TestUserCreate();
//await TestUserDelete();
//await TestUserUpdate();
//await TestGetAllArticleUser();
//await TestGetArticleByUser();
await TestGetAllArticleUser();
await TestGetArticleByUser();
//await TestCreateArticleUser();
//await TestDeleteArticleUser();
//await TestUpdateArticleUser();
await TestUpdateArticleUser();
}
@ -109,7 +109,7 @@ class Tests_Console
{
try
{
var response = await client.DeleteAsync("http://localhost:5052/article/4");
var response = await client.DeleteAsync("http://localhost:5052/article/1");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
@ -339,7 +339,7 @@ class Tests_Console
{
try
{
var response = await client.GetAsync("http://localhost:5052/ArticleUsers");
var response = await client.GetAsync("http://localhost:5052/user/article/users");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
@ -354,7 +354,7 @@ class Tests_Console
{
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();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
@ -391,7 +391,7 @@ class Tests_Console
{
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();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
@ -408,12 +408,13 @@ class Tests_Console
{
var articleUser = new ArticleUserEntity()
{
ArticleEntityId = 1,
ArticleEntityId = 2,
UserEntityPseudo = "Sha"
};
long oldId = 3;
var json = JsonSerializer.Serialize(articleUser);
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();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);

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