Skip to content

Fix/petcontroller api endpoint#206

Merged
annikaholmqvist94 merged 3 commits into
mainfrom
fix/petcontroller-api-endpoint
Apr 15, 2026
Merged

Fix/petcontroller api endpoint#206
annikaholmqvist94 merged 3 commits into
mainfrom
fix/petcontroller-api-endpoint

Conversation

@annikaholmqvist94

@annikaholmqvist94 annikaholmqvist94 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

closes #205

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated API documentation for pet endpoints.
  • Updates

    • Pet API endpoints now operate under the /api/pets path prefix instead of /pets.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR updates the PetController base request mapping from /pets to /api/pets, bringing it into alignment with other controllers in the application. Corresponding updates are made to API documentation and all related test paths, along with removal of redundant authentication headers in tests.

Changes

Cohort / File(s) Summary
Documentation
API.md
Updated all endpoint paths from /pets to /api/pets and corrected corresponding fetch example URLs to match the new routing convention.
Controller Routing
src/main/java/org/example/vet1177/controller/PetController.java
Updated @RequestMapping annotation from "/pets" to "/api/pets", affecting all derived endpoint paths (POST, GET, PUT, DELETE).
Test Updates
src/test/java/org/example/vet1177/controller/PetControllerTest.java
Updated all test endpoint paths from /pets to /api/pets, removed redundant .header("currentUserId", ...) calls, and removed related userService.getUserEntityById(...) stubbing while retaining .with(authenticatedAs(...)) authentication.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #196: Modifies both PetController endpoints and PetControllerTest paths with authentication header adjustments, directly overlapping the changes in this PR.
  • PR #130: Modifies PetController class and affects createPet's response handling, sharing the same controller implementation.
  • PR #150: Updates route prefix for GET/PUT/DELETE endpoints in PetController, directly impacted by this base mapping change.

Suggested labels

test

Suggested reviewers

  • lindaeskilsson
  • johanbriger
  • TatjanaTrajkovic

Poem

🐰 Hops along the /api path,
PetController finds its way back,
No more straying from the rest,
Unified routing passes the test!
CORS smiles, security's blessed. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 accurately describes the main change: updating PetController endpoints from /pets to /api/pets to align with other controllers.
Linked Issues check ✅ Passed All requirements from issue #205 are met: PetController base path changed to /api/pets, API.md updated with new URLs, and all test paths updated to /api/pets base path.
Out of Scope Changes check ✅ Passed All changes are in scope and directly address the linked issue #205 requirements without introducing unrelated modifications.

✏️ 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 fix/petcontroller-api-endpoint

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.

🧹 Nitpick comments (2)
src/main/java/org/example/vet1177/controller/PetController.java (1)

19-19: Base path update is correct; align route literals in logs/comments for consistency.

@RequestMapping("/api/pets") matches the PR objective. Consider updating the /pets strings used in method comments/log messages below so debugging/docs stay aligned with runtime routes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/vet1177/controller/PetController.java` at line 19,
The class-level route annotation `@RequestMapping`("/api/pets") in PetController
is updated but some method comments and log/messages still use the old "/pets"
literal; update all occurrences in comments and log statements (e.g., any use in
methods of PetController like getAllPets, getPetById, createPet, updatePet,
deletePet) to use "/api/pets" (or build messages from the `@RequestMapping` value)
so literals in logs/docs match the runtime base path.
src/test/java/org/example/vet1177/controller/PetControllerTest.java (1)

97-98: Extract a shared test constant for the pet base path.

"/api/pets" is repeated across many tests; centralizing it reduces churn for future route changes.

♻️ Proposed refactor
 public class PetControllerTest {
+    private static final String PETS_BASE = "/api/pets";
@@
-        mockMvc.perform(post("/api/pets")
+        mockMvc.perform(post(PETS_BASE)
@@
-        mockMvc.perform(get("/api/pets/{petId}", petId)
+        mockMvc.perform(get(PETS_BASE + "/{petId}", petId)
@@
-        mockMvc.perform(get("/api/pets/owner/{ownerId}", ownerId)
+        mockMvc.perform(get(PETS_BASE + "/owner/{ownerId}", ownerId)
@@
-        mockMvc.perform(put("/api/pets/{petId}", petId)
+        mockMvc.perform(put(PETS_BASE + "/{petId}", petId)
@@
-        mockMvc.perform(delete("/api/pets/{petId}", petId)
+        mockMvc.perform(delete(PETS_BASE + "/{petId}", petId)

Also applies to: 111-112, 124-125, 137-138, 150-151, 161-162, 171-172, 181-182, 192-193, 204-205, 218-219, 231-232, 246-247, 256-257, 266-267

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/vet1177/controller/PetControllerTest.java` around
lines 97 - 98, In PetControllerTest, extract the repeated literal "/api/pets"
into a single private static final String constant (e.g. PET_BASE_PATH) at the
top of the test class, then replace every occurrence of the literal in
mockMvc.perform(...) calls and any other assertions with that constant
(references include the mockMvc.perform(post("/api/pets")... usages and similar
post/get/delete requests) so future route changes only need one edit; ensure
imports remain and tests compile after replacing the string with PET_BASE_PATH.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/org/example/vet1177/controller/PetController.java`:
- Line 19: The class-level route annotation `@RequestMapping`("/api/pets") in
PetController is updated but some method comments and log/messages still use the
old "/pets" literal; update all occurrences in comments and log statements
(e.g., any use in methods of PetController like getAllPets, getPetById,
createPet, updatePet, deletePet) to use "/api/pets" (or build messages from the
`@RequestMapping` value) so literals in logs/docs match the runtime base path.

In `@src/test/java/org/example/vet1177/controller/PetControllerTest.java`:
- Around line 97-98: In PetControllerTest, extract the repeated literal
"/api/pets" into a single private static final String constant (e.g.
PET_BASE_PATH) at the top of the test class, then replace every occurrence of
the literal in mockMvc.perform(...) calls and any other assertions with that
constant (references include the mockMvc.perform(post("/api/pets")... usages and
similar post/get/delete requests) so future route changes only need one edit;
ensure imports remain and tests compile after replacing the string with
PET_BASE_PATH.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 129693be-983a-4b10-8853-327907edaa06

📥 Commits

Reviewing files that changed from the base of the PR and between 20e2b48 and aebc6cf.

📒 Files selected for processing (3)
  • API.md
  • src/main/java/org/example/vet1177/controller/PetController.java
  • src/test/java/org/example/vet1177/controller/PetControllerTest.java

@annikaholmqvist94
annikaholmqvist94 merged commit bce387b into main Apr 15, 2026
2 checks passed
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.

Fix: Petcontroller endpoints

1 participant