From 92ef22b249d71f045648c1b84d2a4bad02082c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ho=C3=A0ng=20Nam?= Date: Thu, 14 May 2026 21:19:57 +0700 Subject: [PATCH] fix(api): fix 404 error on successful profile update - Remove problematic logic in EndpointExtensions that returned 404 for successful responses with null data. - Update UpdateProfileHandler to return success message in the Data field. --- .../UserCases/Commands/Identity/UpdateProfileHandler.cs | 2 +- .../PIED_LMS.Presentation/Extensions/EndpointExtensions.cs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs b/backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs index f3510209..53596dec 100644 --- a/backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs +++ b/backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs @@ -63,7 +63,7 @@ public async Task> Handle(UpdateProfileCommand request, return new ServiceResponse(false, "Failed to update profile"); } - return new ServiceResponse(true, "Profile updated successfully"); + return new ServiceResponse(true, "Profile updated successfully", "Profile updated successfully"); } catch (Exception ex) { diff --git a/backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs b/backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs index 8cc73a52..79d9f3e8 100644 --- a/backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs +++ b/backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs @@ -8,9 +8,6 @@ public static IResult ToActionResult(this ServiceResponse result, HttpCont { if (result.Success) { - if (result.Data is null && typeof(T).IsClass) - return Results.NotFound(result); - return Results.Ok(result); } @@ -25,7 +22,7 @@ public static IResult ToActionResult(this ServiceResponse result, HttpCont return Results.Json(result, statusCode: StatusCodes.Status401Unauthorized); if (result.ErrorCode == "FORBIDDEN" || result.ErrorCode == "ACCESS_DENIED" || - (result.Message.Contains("authorized") || result.Message.Contains("permission"))) + (result.Message is not null && (result.Message.Contains("authorized") || result.Message.Contains("permission")))) return Results.Json(result, statusCode: StatusCodes.Status403Forbidden); return result.ErrorCode switch