Skip to content

Implemented User GET, PATCH, DELETE API routes - #48

Merged
Solian21 merged 6 commits into
mainfrom
annabelle/user_routes
Oct 19, 2026
Merged

Solian21 merged 6 commits into
mainfrom
annabelle/user_routes

Conversation

@annabelleb20

Copy link
Copy Markdown
Collaborator

Closes #41

What changed

  • Created UserRepository to call in UserService
  • Created UserService to call in UserController
  • UserService controls what actions are made when API routes are called in UserController
  • Updated User slightly so that the ROLE can be updated for PATCH
  • Added security to prevent a non-admin from accessing admin only API routes (please let me know if we're supposed to use a different kind of security, I just wanted to have something to test)

How I tested it

  • Unit tests pass locally
  • docs/openapi.yaml has not been updated

Reviewers

2 approving teammates who are not the author (1 for a team of 3).

.orElseThrow(() -> new UsernameNotFoundException("No user named " + username));
return org.springframework.security.core.userdetails.User
.withUsername(user.getDisplayName())
.password(user.getEmail())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just wondering why this password has user.getEmail() ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I actually don't really remember why I did that but users don't have a password in the db so I wasnt really sure what to put there

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

actually I think it might supposed to be implemented differently since we will be using oauth, but im not sure what to do ATM cuz we dont have oauth set up yet...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That makes sense. Since we're planning to use Google OAuth, we don't need to put anything in a local password field. The API should verify the Google token and use that identity to find the user in our database.

For now, we can keep using @WithMockUser to test the USER/ADMIN access rules without setting up a real password login. I'd remove the email-as-password implementation and coordinate the SecurityConfig changes with the OAuth work before merging. Those mock tests cover permissions, but we'll still need to test real authentication once OAuth is connected.

@leslyVillanueva1020 leslyVillanueva1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just had a quick comment on the UserService.java file just need some clarification on that. maybe i'm missunderstanding, but other than that looks good

@Yooze0x4c8

Copy link
Copy Markdown
Collaborator

Could we configure the 401/403 responses in SecurityConfig to use RFC 9457 Problem Details? Our API contract and issue #45 require application/problem+json with title and status, but Spring Security handles these errors before MVC, so @RestControllerAdvice alone will not cover them.

Please add an AuthenticationEntryPoint for 401 and an AccessDeniedHandler for 403 that write a ProblemDetail response. The 401 handler should preserve the appropriate WWW-Authenticate header and be configured in both exceptionHandling() and httpBasic(), since failed Basic authentication uses the filter's own entry point. We should carry this configuration over to oauth2ResourceServer() when #20 is integrated.

It would also help to test unauthenticated requests and USER access to admin routes, checking the status, content type, and required body fields.

This would also cover the meal plan routes in #45, so I’ll avoid duplicating the handling on my side.

@Yooze0x4c8 Yooze0x4c8 mentioned this pull request Oct 15, 2026
2 tasks done
So sorry for the wait :(
@annabelleb20

Copy link
Copy Markdown
Collaborator Author

Could we configure the 401/403 responses in SecurityConfig to use RFC 9457 Problem Details? Our API contract and issue #45 require application/problem+json with title and status, but Spring Security handles these errors before MVC, so @RestControllerAdvice alone will not cover them.

Please add an AuthenticationEntryPoint for 401 and an AccessDeniedHandler for 403 that write a ProblemDetail response. The 401 handler should preserve the appropriate WWW-Authenticate header and be configured in both exceptionHandling() and httpBasic(), since failed Basic authentication uses the filter's own entry point. We should carry this configuration over to oauth2ResourceServer() when #20 is integrated.

It would also help to test unauthenticated requests and USER access to admin routes, checking the status, content type, and required body fields.

This would also cover the meal plan routes in #45, so I’ll avoid duplicating the handling on my side.

Changes have been made, I think I made changes regarding everything you brought up but please let me know if there's anything I need to correct.

@leslyVillanueva1020 leslyVillanueva1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

great thank you for correcting the comments 👍

Hopefully most problems are fixed

@leslyVillanueva1020 leslyVillanueva1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good to me 👍

@Yooze0x4c8 Yooze0x4c8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good

@Solian21 Solian21 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This all looks good to me

@Solian21
Solian21 merged commit 9662978 into main Oct 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

As a developer, I want to set up the API routes for users so that we can handle data regarding user information

4 participants