@@ -45,6 +45,9 @@ public String showPost(@PathVariable("postId") Long postId, ModelMap model) {
4545 if (post == null )
4646 throw new ResourceNotFoundException ();
4747
48+ if (post .isHidden () && !userService .isAdmin ())
49+ throw new ResourceNotFoundException ();
50+
4851 model .addAttribute ("post" , post );
4952
5053 if (userService .isAuthenticated ()) {
@@ -95,7 +98,7 @@ public String showEditPostForm(@PathVariable("postId") Long postId, ModelMap mod
9598
9699 @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
97100 @ RequestMapping (value = "/posts/{postId}/edit" , method = RequestMethod .POST )
98- public String showEditPostForm (ModelMap model , @ Valid @ ModelAttribute ("post" ) PostEditDto post , BindingResult result ,
101+ public String updatePost (ModelMap model , @ Valid @ ModelAttribute ("post" ) PostEditDto post , BindingResult result ,
99102 @ PathVariable ("postId" ) Long postId ) {
100103 post .setId (postId );
101104
@@ -109,4 +112,20 @@ public String showEditPostForm(ModelMap model, @Valid @ModelAttribute("post") Po
109112
110113 return "redirect:/posts/" + postId ;
111114 }
115+
116+ @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
117+ @ RequestMapping (value = "/posts/{postId}/hide" , method = RequestMethod .POST )
118+ public @ ResponseBody String hidePost (@ PathVariable ("postId" ) Long postId ) {
119+ postService .setPostVisibility (postId , true );
120+
121+ return "ok" ;
122+ }
123+
124+ @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
125+ @ RequestMapping (value = "/posts/{postId}/unhide" , method = RequestMethod .POST )
126+ public @ ResponseBody String unhidePost (@ PathVariable ("postId" ) Long postId ) {
127+ postService .setPostVisibility (postId , false );
128+
129+ return "ok" ;
130+ }
112131}
0 commit comments