Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: inject trainee ID in to controllers #492

Merged
merged 3 commits into from
Nov 11, 2024
Merged

Conversation

Judge40
Copy link
Contributor

@Judge40 Judge40 commented Nov 6, 2024

feat: create interceptor to inject trainee ID

Create a TraineeIdentityInterceptor to inject trainee identity details
(traineeTisId) in to the request scope.

The interceptor will run on each request and provides a single place
where the JWT token needs to be handled to extract the trainee ID. The
TraineeIdentity can be autowired in to any existing controllers and will
be auto-populated with the trainee ID.


refactor: controllers to use TraineeIdentity

Refactor the existing controllers which are currently handling
extracting the trainee ID from the auth token themselves. Autowire a
TraineeIdentity to the controllers and get the trainee ID from it.

Create a TraineeIdentityInterceptor to inject trainee identity details
(traineeTisId) in to the request scope.

The interceptor will run on each request and provides a single place
where the JWT token needs to be handled to extract the trainee ID. The
TraineeIdentity can be autowired in to any existing controllers and will
be auto-populated with the trainee ID.

NO-TICKET
Refactor the existing controllers which are currently handling
extracting the trainee ID from the auth token themselves. Autowire a
TraineeIdentity to the controllers and get the trainee ID from it.

NO-TICKET
@Judge40 Judge40 requested a review from a team November 6, 2024 16:48
String token = TestJwtUtil.generateToken("{}");

this.mockMvc.perform(get("/api/trainee-profile")
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, token))
.andExpect(status().isNotFound());
.andExpect(status().isBadRequest());
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose the new response for this and other requests without the token is not enough to comprise a breaking change.

Copy link
Contributor Author

@Judge40 Judge40 Nov 11, 2024

Choose a reason for hiding this comment

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

I don't believe so no, one of the benefits of this not being a documented API (yet) 😉

The previous 404 feels like an oversight anyway, we only get it because we previously passed traineeId = null from API -> service -> repo. Which is just a waste of processing.

At some point it will change again to return 403 Forbidden when there is no trainee ID, which is what the new CCT endpoints will return. But the external (trainee facing) and internal (sync facing) endpoints need untangling first to make that easier to achieve (likely by replacing the internal calls with event listeners).

Copy link

sonarcloud bot commented Nov 11, 2024

@Judge40 Judge40 requested review from ReubenRobertsHEE and a team November 11, 2024 16:55
@Judge40 Judge40 merged commit f774300 into main Nov 11, 2024
3 checks passed
@Judge40 Judge40 deleted the refactor/traineeTisId branch November 11, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants