I have a code block like below. For each method, I call action authentication. Is it possible to do with annotation or other thing effectively?
@GetMapping
public ResponseEntity getAction(@PrincipalUser user, Long actionId)
{
repository.checkUserForAction(user.getId(), actionId);
implement actions...
return service call;
}
@PostMapping
public ResponseEntity addAction(@PrincipalUser user)
{
repository.checkUserForAction(user.getId());
implement actions...
return service call;
}
@DeleteMapping
public ResponseEntity addAction(@PrincipalUser user, Long actionId)
{
repository.checkUserForAction(user.getId(), actionId);
implement actions...
return service call;
}
Actually, in here my other problem is that I call repository method each time and I know this is not an effective way.