I am working on a feature to display a list of job postings made by HR in an Angular HTML page. The requirement is that when a HR logs in, they should only see the jobs they have posted, not all the jobs posted by all HRs. I plan to accomplish this by comparing the HR ID with the foreign key (HrId) in the jobPosting table. If there is a match, then the page should display all the jobs posted by that specific HR. The HR ID will be obtained when the HR logs in, using the access_token stored in Local Storage. Other information can be retrieved using a Get Method that fetches all the jobs.
Below is the code snippet for loading the current user using Local Storage. This will provide the ID of the current HR
loadCurrentUser(){
const token=localStorage.getItem("access_item");
const userInfo=token != null ? this.jwtHelperService.decodeToken(token):null;
const data=userInfo ? {
UserId:userInfo.UserId,
UserName:userInfo.UserName,
Email:userInfo.Email,
City:userInfo.Company
}:null;
this.currentUser.next(data);
return data;
}
Get Method using Angular and .NET
getAllJobPostings():Observable<JobPosting[]>{
return this.http.get<JobPosting[]>(this.basicURL+'Main/GetAllJobPostings');
}
Get method using .NET
[HttpGet("GetAllJobPostings")]
public IEnumerable<JobPosting> GetDetails(){
return Context.JobPosting.ToList();
}
Model Class for Job Posting
export class JobPosting{
jobid:number=0;
title:string='';
hrId:number=0;
experience:number=0;
position:string='';
company:string='';
ctc:number=0;
skills:string='';
description:string='';
}
Database Result Expected Result
If the HrId=2 matches, then only that particular record should be displayed.
Please advise me on how to achieve this and provide suggestions for the code implementation.