Skip to content

Fix Lab 7 feedback: enforce PLAYER role default, proper 404s, admin-only role assignment, expanded TDD#41

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/feedback-lab-7-team-2
Draft

Fix Lab 7 feedback: enforce PLAYER role default, proper 404s, admin-only role assignment, expanded TDD#41
Copilot wants to merge 3 commits into
mainfrom
copilot/feedback-lab-7-team-2

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 10, 2026

Addresses graded feedback (Lab 7) identifying partial compliance in controller business rules, HTTP status codes, and TDD coverage. The critical finding was missing @Service (already present in current HEAD); remaining items required actual code changes.

Changes

User role enforcement

  • Added role field to UserEntity (default "PLAYER") and UserRoleModel; updated UserMapper to map it bidirectionally
  • UserService.createUser now explicitly sets role = "PLAYER" regardless of request payload

Admin-only role assignment

  • Added assignRole(Long targetUserId, String newRole, Long adminUserId) to IUserService and UserService
    • Validates newRole against allowlist: PLAYER, ADMIN, ORGANIZER, REFEREE
    • Checks admin.getRole() directly on UserEntity — no entity→model→entity roundtrip
  • Exposed as PUT /api/users/{id}/role?role=X&adminUserId=Y in UserController

Proper HTTP status codes

  • Created NotFoundException in new exception package
  • Services throw NotFoundException for all not-found cases; generic RuntimeException remains for validation/business-rule failures
  • Controllers now catch both separately: NotFoundException → 404, RuntimeException → 400/401
} catch (NotFoundException e) {
    return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
} catch (RuntimeException e) {
    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

Applies to UserController (updateUser, deactivateUser) and all TournamentController operations.

TDD coverage (59 → 80 tests)

  • authenticate: 6 new tests covering all failure paths (null/blank email, null password, user not found, wrong password, inactive account)
  • createUser: asserts PLAYER role is set by default
  • NotFoundException propagation: covered for all service methods that do lookups
  • assignRole: admin not found, non-admin caller, target user not found, invalid role value

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 10, 2026 04:03
…gnRole endpoint, more TDD tests

Agent-Logs-Url: https://github.com/CodeForge-DOSW/TECHCUP-FUTBOL-BackEnd-SpringBoot/sessions/0f3198d8-0a9a-4b05-abe5-821e2cf046c9

Co-authored-by: JuanGuayazanC <162055263+JuanGuayazanC@users.noreply.github.com>
Copilot AI changed the title [WIP] Resolve feedback for Lab 7 - Team 2 Fix Lab 7 feedback: enforce PLAYER role default, proper 404s, admin-only role assignment, expanded TDD Apr 10, 2026
Copilot AI requested a review from JuanGuayazanC April 10, 2026 04:08
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

Feedback Lab 7 - Team 2

2 participants