Skip to content

fix(api): fix 404 error on successful profile update#83

Closed
EricN2907 wants to merge 1 commit into
mainfrom
feat/fix-404-error
Closed

fix(api): fix 404 error on successful profile update#83
EricN2907 wants to merge 1 commit into
mainfrom
feat/fix-404-error

Conversation

@EricN2907

@EricN2907 EricN2907 commented May 14, 2026

Copy link
Copy Markdown
Collaborator
  • Remove problematic logic in EndpointExtensions that returned 404 for successful responses with null data.
  • Update UpdateProfileHandler to return success message in the Data field.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced profile update responses to include additional success information.
    • Improved API response handling for null data in successful operations.
    • Strengthened null-safety in permission verification logic.

Review Change Stack

- Remove problematic logic in EndpointExtensions that returned 404 for successful responses with null data.
- Update UpdateProfileHandler to return success message in the Data field.
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Two presentation-layer changes address response handling: EndpointExtensions.ToActionResult now always returns Ok(result) for successful responses and guards against null Message before string containment checks. UpdateProfileHandler constructs profile update responses using a three-parameter ServiceResponse overload.

Changes

Service Response Handling Updates

Layer / File(s) Summary
Response conversion safety and success handling
backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs
ToActionResult<T> removes the conditional NotFound return for null Data in class types, always returning Ok(result) on success. Forbidden-branch message checks now guard against null Message before invoking Contains().
Profile update response adjustment
backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs
Successful profile updates now construct ServiceResponse<string> using an overload with two identical string parameters instead of the prior two-parameter form.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A response now always stands tall,
No silent NotFound for null at all,
Messages guarded with careful check,
Profile returns with newfound flair—
Safety and clarity, a well-matched pair. 🎭

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main objective of the pull request: fixing a 404 error that was being incorrectly returned on successful profile updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fix-404-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs`:
- Line 66: The ServiceResponse<string> returned in UpdateProfileHandler is using
the same message for both Message and Data; replace the redundant Data value
with a meaningful payload (preferably return the updated user DTO from your
updated model, e.g., UpdatedUserDto or UserProfileDto) or switch the response
type to ServiceResponse<bool> and return true as Data; update the return in
UpdateProfileHandler.Handle to construct ServiceResponse with the chosen Data
(e.g., the updated user DTO or a boolean) instead of the duplicate "Profile
updated successfully" string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 24c0d2b2-4a70-42e0-9746-ad68365ee9f5

📥 Commits

Reviewing files that changed from the base of the PR and between a9a89f5 and 92ef22b.

📒 Files selected for processing (2)
  • backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs
  • backend/Src/PIED_LMS.Presentation/Extensions/EndpointExtensions.cs

}

return new ServiceResponse<string>(true, "Profile updated successfully");
return new ServiceResponse<string>(true, "Profile updated successfully", "Profile updated successfully");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify ServiceResponse constructor signatures and usage patterns

# Find ServiceResponse class definition
echo "=== ServiceResponse class definition ==="
ast-grep --pattern 'class ServiceResponse<$_> {
  $$$
}'

# Find constructor definitions
echo -e "\n=== ServiceResponse constructors ==="
rg -n -A 5 'class ServiceResponse' --type cs

# Find other usages of 3-parameter ServiceResponse constructor
echo -e "\n=== Other usages of 3-parameter ServiceResponse<string> constructor ==="
rg -n 'new ServiceResponse<string>\([^,]+,[^,]+,[^)]+\)' --type cs -C 2

Repository: PiedTeam/pied-lms

Length of output: 9443


🏁 Script executed:

find . -name "*.cs" -type f | head -20

Repository: PiedTeam/pied-lms

Length of output: 1357


🏁 Script executed:

rg -l "class ServiceResponse" --type cs

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

fd -e cs -x grep -l "class ServiceResponse" {} \;

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

find ./backend -name "*.cs" -type f -exec grep -l "class ServiceResponse" {} \;

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

grep -r "class ServiceResponse" ./backend --include="*.cs" -n

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

grep -r "using.*ServiceResponse\|ServiceResponse.*namespace" ./backend --include="*.cs" -B 2 -A 2

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

grep -r "ServiceResponse<" ./backend --include="*.cs" | head -20

Repository: PiedTeam/pied-lms

Length of output: 3485


🏁 Script executed:

cat ./backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs | head -80

Repository: PiedTeam/pied-lms

Length of output: 3119


🏁 Script executed:

find ./backend -type d -name "*Contract*" -o -name "*Shared*" -o -name "*Common*" | head -20

Repository: PiedTeam/pied-lms

Length of output: 145


🏁 Script executed:

find ./backend -name "*.cs" -type f | xargs grep -l "class ServiceResponse" 2>/dev/null

Repository: PiedTeam/pied-lms

Length of output: 45


🏁 Script executed:

find . -path "*/Contract/*" -name "*.cs" -type f | head -30

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

find ./backend/Src/PIED_LMS.Contract -name "*.cs" -type f | xargs grep -l "ServiceResponse"

Repository: PiedTeam/pied-lms

Length of output: 1774


🏁 Script executed:

ls -la ./backend/Src/PIED_LMS.Contract/

Repository: PiedTeam/pied-lms

Length of output: 621


🏁 Script executed:

find ./backend/Src/PIED_LMS.Contract -name "*.cs" -type f -exec grep -l "class ServiceResponse" {} \;

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

find ./backend/Src/PIED_LMS.Contract/Abstractions -name "*.cs" -type f

Repository: PiedTeam/pied-lms

Length of output: 908


🏁 Script executed:

cat ./backend/Src/PIED_LMS.Contract/GlobalUsings.cs

Repository: PiedTeam/pied-lms

Length of output: 235


🏁 Script executed:

grep -r "ServiceResponse" ./backend/Src/PIED_LMS.Contract/Abstractions --include="*.cs" -n

Repository: PiedTeam/pied-lms

Length of output: 197


🏁 Script executed:

cat ./backend/Src/PIED_LMS.Contract/Abstractions/Shared/ResultT.cs

Repository: PiedTeam/pied-lms

Length of output: 706


🏁 Script executed:

cat ./backend/Src/PIED_LMS.Contract/Abstractions/Shared/Result.cs

Repository: PiedTeam/pied-lms

Length of output: 1165


🏁 Script executed:

grep -r "ServiceResponse\|using.*Result\|alias" ./backend/Src/PIED_LMS.Contract --include="*.cs" -n | head -30

Repository: PiedTeam/pied-lms

Length of output: 3680


🏁 Script executed:

grep -r "class ServiceResponse\|record ServiceResponse" ./backend --include="*.cs"

Repository: PiedTeam/pied-lms

Length of output: 157


🏁 Script executed:

find ./backend -name "*.csproj" -type f -exec cat {} \; | grep -i "serviceresponse\|package"

Repository: PiedTeam/pied-lms

Length of output: 2465


🏁 Script executed:

rg "class ServiceResponse|namespace.*ServiceResponse" ./backend --type cs -i

Repository: PiedTeam/pied-lms

Length of output: 43


🏁 Script executed:

cat ./backend/Src/PIED_LMS.Contract/Services/Identity/Response.cs

Repository: PiedTeam/pied-lms

Length of output: 1427


Remove the redundant duplicate string in the Data parameter.

The ServiceResponse<T> constructor accepts a Data field to carry meaningful information, yet you're passing "Profile updated successfully" as both the Message and Data parameters. This duplication is wasteful and defeats the purpose of the Data field.

Choose one approach:

  1. Return the updated user profile data as a DTO
  2. Return a specific success indicator (e.g., the user ID or updated timestamp)
  3. Use a simpler response type like ServiceResponse<bool> with true as the data value
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@backend/Src/PIED_LMS.Application/UserCases/Commands/Identity/UpdateProfileHandler.cs`
at line 66, The ServiceResponse<string> returned in UpdateProfileHandler is
using the same message for both Message and Data; replace the redundant Data
value with a meaningful payload (preferably return the updated user DTO from
your updated model, e.g., UpdatedUserDto or UserProfileDto) or switch the
response type to ServiceResponse<bool> and return true as Data; update the
return in UpdateProfileHandler.Handle to construct ServiceResponse with the
chosen Data (e.g., the updated user DTO or a boolean) instead of the duplicate
"Profile updated successfully" string.

@EricN2907 EricN2907 closed this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant