33import org .springframework .http .HttpStatus ;
44import org .springframework .http .MediaType ;
55import org .springframework .http .ResponseEntity ;
6+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
67import org .springframework .web .bind .annotation .*;
78import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
9+ import ru .javawebinar .topjava .AuthorizedUser ;
810import ru .javawebinar .topjava .model .User ;
911import ru .javawebinar .topjava .to .UserTo ;
1012
@@ -19,14 +21,14 @@ public class ProfileRestController extends AbstractUserController {
1921 static final String REST_URL = "/rest/profile" ;
2022
2123 @ GetMapping
22- public User get () {
23- return super .get (authUserId ());
24+ public User get (@ AuthenticationPrincipal AuthorizedUser authUser ) {
25+ return super .get (authUser . getId ());
2426 }
2527
2628 @ DeleteMapping
2729 @ ResponseStatus (HttpStatus .NO_CONTENT )
28- public void delete () {
29- super .delete (authUserId ());
30+ public void delete (@ AuthenticationPrincipal AuthorizedUser authUser ) {
31+ super .delete (authUser . getId ());
3032 }
3133
3234 @ PostMapping (consumes = MediaType .APPLICATION_JSON_VALUE )
@@ -40,8 +42,8 @@ public ResponseEntity<User> register(@Valid @RequestBody UserTo userTo) {
4042
4143 @ PutMapping (consumes = MediaType .APPLICATION_JSON_VALUE )
4244 @ ResponseStatus (HttpStatus .NO_CONTENT )
43- public void update (@ Valid @ RequestBody UserTo userTo ) {
44- super .update (userTo , authUserId ());
45+ public void update (@ Valid @ RequestBody UserTo userTo , @ AuthenticationPrincipal AuthorizedUser authUser ) {
46+ super .update (userTo , authUser . getId ());
4547 }
4648
4749 @ GetMapping ("/text" )
@@ -50,7 +52,7 @@ public String testUTF() {
5052 }
5153
5254 @ GetMapping ("/with-meals" )
53- public User getWithMeals () {
54- return super .getWithMeals (authUserId ());
55+ public User getWithMeals (@ AuthenticationPrincipal AuthorizedUser authUser ) {
56+ return super .getWithMeals (authUser . getId ());
5557 }
5658}
0 commit comments