3434import services .security .CurrentUser ;
3535import services .security .CurrentUserAttached ;
3636import projection .PostByAuthor ;
37- import projection .PostDetail ;
3837/**
3938 *
4039 * @author sergio
@@ -60,7 +59,7 @@ public String all(@CurrentUser User activeUser, Model model){
6059
6160 @ GetMapping ("/edit/{postId}" )
6261 public String showUpdatePostForm (@ PathVariable Long postId , Model model ) {
63- PostDetail post = postService .findById (postId );
62+ Post post = postService .findById (postId );
6463 if (post == null ) {
6564 throw new PostNotFoundException ();
6665 }
@@ -70,7 +69,7 @@ public String showUpdatePostForm(@PathVariable Long postId, Model model) {
7069
7170 @ GetMapping ("/delete/{postId}" )
7271 public String showDeletePostForm (@ PathVariable Long postId , Model model ) {
73- PostDetail post = postService .findById (postId );
72+ Post post = postService .findById (postId );
7473 if (post == null ) {
7574 throw new PostNotFoundException ();
7675 }
@@ -101,16 +100,25 @@ public String processPost(@RequestPart("postImage") MultipartFile postImage, @Mo
101100 return "admin/post/create" ;
102101 }
103102
104- if (postImage != null ){
103+ if (postImage != null && !postImage .isEmpty ()){
104+ logger .info ("Añadiendo información de la imagen" );
105105 FileImage image = new FileImage ();
106106 image .setName (postImage .getName ());
107107 image .setContentType (postImage .getContentType ());
108108 image .setSize (postImage .getSize ());
109109 image .setContent (postImage .getBytes ());
110110 post .setImage (image );
111111 }
112+
112113 post .setAuthor (activeUser );
113- postService .create (post );
114+ if (post .getId () == null ){
115+ logger .info ("Creando Nuevo Post" );
116+ postService .create (post );
117+ }else {
118+ logger .info ("Editando Post" );
119+ postService .edit (post );
120+ }
121+
114122 List <String > successMessages = new ArrayList ();
115123 successMessages .add (messageSource .getMessage ("message.post.save.success" , new Object [] {post .getId ()}, Locale .getDefault ()));
116124 model .addFlashAttribute ("successFlashMessages" , successMessages );
0 commit comments