#What's the approach to filter user related posts only via jwt token.
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
<@&1004656351647117403> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
To filter user related posts using a JWT token, you can implement a method in your JobPosts class that checks if the job poster id in the JWT matches the id of the JobPoster associated with each job post. Here's a basic example:
class JobPosts {
belongsTo JobPoster;
public List<JobPost> getPostsForUser(String jwtToken) {
String userId = getUserIdFromJwt(jwtToken);
List<JobPost> userPosts = new ArrayList<>();
for(JobPost post : allPosts) {
if(post.getJobPoster().getId().equals(userId)) {
userPosts.add(post);
}
}
return userPosts;
}
private String getUserIdFromJwt(String jwtToken) {
// Implement logic to extract user id from JWT token
}
}
Useful links:
yah I know this approach it's not beautiful
and also I know this approach
@Data
@MappedSuperclass
@EntityListeners(AuditListener.class)
@FilterDef(name = "tenantFilter", parameters = @ParamDef(name = "tenantId", type = Long.class))
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
public abstract class BaseEntity {
I belive this is too heavy.
@hybrid holly
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
I just did this for now.
@GetMapping("/created-by/job-poster")
public ResponseEntity<Page<JobPostDto>> getAllJobPosts(
@RequestHeader(
name = "Authorization",
required = false
) @Parameter(hidden = true) String authToken,
Pageable pageable
) {
String username = jwtService.getUsernameFromToken(authToken.substring(7));
Company company = jobPosterService.getCompanyOfJobPoster(username);
return ResponseEntity.ok(
jobPostService.listAllJobPostsByCompany(pageable, company.getId())
);
}
Detected code, here are some useful tools:
@GetMapping("/created-by/job-poster") public ResponseEntity<Page<JobPostDto>> getAllJobPosts(@RequestHeader(name = "Authorization", required = false) @Parameter(hidden = true) String authToken, Pageable pageable) {
String username = jwtService.getUsernameFromToken(authToken.substring(7));
Company company = jobPosterService.getCompanyOfJobPoster(username);
return ResponseEntity.ok(jobPostService.listAllJobPostsByCompany(pageable, company.getId()));
}