1818import  org .springframework .data .domain .Sort .Direction ;
1919import  org .springframework .data .web .PageableDefault ;
2020import  org .springframework .http .HttpStatus ;
21- import  org .springframework .security .oauth2 .server .resource .authentication .JwtAuthenticationToken ;
2221import  org .springframework .web .bind .annotation .DeleteMapping ;
2322import  org .springframework .web .bind .annotation .GetMapping ;
2423import  org .springframework .web .bind .annotation .PathVariable ;
3029import  org .springframework .web .bind .annotation .ResponseStatus ;
3130import  org .springframework .web .bind .annotation .RestController ;
3231
32+ import  java .security .Principal ;
3333import  java .util .List ;
3434import  java .util .stream .Collectors ;
3535
@@ -50,9 +50,9 @@ public class JobController {
5050 @ GetMapping 
5151 public  Page <JobResponse > getJobs (
5252 @ ParameterObject  @ PageableDefault (sort  = {"createDate" }, direction  = Direction .DESC ) Pageable  pageable ,
53-  JwtAuthenticationToken   token ) {
53+  Principal   principal ) {
5454 log .info ("Request to get a page of jobs (offset = {}, pageSize = {}) made by {}" ,
55-  pageable .getOffset (), pageable .getPageSize (), token .getName ());
55+  pageable .getOffset (), pageable .getPageSize (), principal .getName ());
5656 return  jobService .getJobsByPage (pageable ).map (jobMapper ::toJobResponse );
5757 }
5858
@@ -73,8 +73,8 @@ public List<JobResponse> getNewestJobs(@RequestParam(value = "number", required
7373 summary  = "Get a job by id" ,
7474 security  = {@ SecurityRequirement (name  = BEARER_KEY_SECURITY_SCHEME )})
7575 @ GetMapping ("/{id}" )
76-  public  JobResponse  getJobById (@ PathVariable  String  id , JwtAuthenticationToken   token ) {
77-  log .info ("Request to get a job with id {} made by {}" , id , token .getName ());
76+  public  JobResponse  getJobById (@ PathVariable  String  id , Principal   principal ) {
77+  log .info ("Request to get a job with id {} made by {}" , id , principal .getName ());
7878 Job  job  = jobService .validateAndGetJobById (id );
7979 return  jobMapper .toJobResponse (job );
8080 }
@@ -84,8 +84,8 @@ public JobResponse getJobById(@PathVariable String id, JwtAuthenticationToken to
8484 security  = {@ SecurityRequirement (name  = BEARER_KEY_SECURITY_SCHEME )})
8585 @ ResponseStatus (HttpStatus .CREATED )
8686 @ PostMapping 
87-  public  JobResponse  createJob (@ Valid  @ RequestBody  CreateJobRequest  createJobRequest , JwtAuthenticationToken   token ) {
88-  log .info ("Request to create a job made by {}" , token .getName ());
87+  public  JobResponse  createJob (@ Valid  @ RequestBody  CreateJobRequest  createJobRequest , Principal   principal ) {
88+  log .info ("Request to create a job made by {}" , principal .getName ());
8989 Job  job  = jobMapper .toJob (createJobRequest );
9090 job  = jobService .saveJob (job );
9191 return  jobMapper .toJobResponse (job );
@@ -95,8 +95,8 @@ public JobResponse createJob(@Valid @RequestBody CreateJobRequest createJobReque
9595 summary  = "Delete a job" ,
9696 security  = {@ SecurityRequirement (name  = BEARER_KEY_SECURITY_SCHEME )})
9797 @ DeleteMapping ("/{id}" )
98-  public  JobResponse  deleteJob (@ PathVariable  String  id , JwtAuthenticationToken   token ) {
99-  log .info ("Request to delete a job with id {} made by {}" , id , token .getName ());
98+  public  JobResponse  deleteJob (@ PathVariable  String  id , Principal   principal ) {
99+  log .info ("Request to delete a job with id {} made by {}" , id , principal .getName ());
100100 Job  job  = jobService .validateAndGetJobById (id );
101101 jobService .deleteJob (job );
102102 return  jobMapper .toJobResponse (job );
@@ -107,8 +107,8 @@ public JobResponse deleteJob(@PathVariable String id, JwtAuthenticationToken tok
107107 security  = {@ SecurityRequirement (name  = BEARER_KEY_SECURITY_SCHEME )})
108108 @ PutMapping ("/{id}" )
109109 public  JobResponse  updateJob (@ PathVariable  String  id ,
110-  @ Valid  @ RequestBody  UpdateJobRequest  updateJobRequest , JwtAuthenticationToken   token ) {
111-  log .info ("Request to update a job with id {} made by {}" , id , token .getName ());
110+  @ Valid  @ RequestBody  UpdateJobRequest  updateJobRequest , Principal   principal ) {
111+  log .info ("Request to update a job with id {} made by {}" , id , principal .getName ());
112112 Job  job  = jobService .validateAndGetJobById (id );
113113 jobMapper .updateJobFromRequest (updateJobRequest , job );
114114 jobService .saveJob (job );
@@ -121,8 +121,8 @@ public JobResponse updateJob(@PathVariable String id,
121121 @ PutMapping ("/search" )
122122 public  Page <Job > searchJobs (@ Valid  @ RequestBody  SearchRequest  searchRequest ,
123123 @ ParameterObject  @ PageableDefault (sort  = {"createDate" }, direction  = Direction .DESC ) Pageable  pageable ,
124-  JwtAuthenticationToken   token ) {
125-  log .info ("Request to search a job with text {} made by {}" , searchRequest .getText (), token .getName ());
124+  Principal   principal ) {
125+  log .info ("Request to search a job with text {} made by {}" , searchRequest .getText (), principal .getName ());
126126 return  jobService .search (searchRequest .getText (), pageable );
127127 }
128128}
0 commit comments