Skip to content

Commit 61d514a

Browse files
committed
fix(post): solve errors
1 parent a61ef91 commit 61d514a

23 files changed

+84
-404
lines changed

src/main/java/controllers/admin/PostController.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import services.security.CurrentUser;
3535
import services.security.CurrentUserAttached;
3636
import 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);

src/main/java/repositories/PostRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public interface PostRepository extends JpaRepository<Post, Long> {
1212
PostDetail findByIdAndPublishedTrue(Long id);
13-
PostDetail findById(Long id);
13+
Post findById(Long id);
1414
List<PostSummary> findFirst5ByPublishedTrueOrderByDateDesc();
1515
List<PostByAuthor> findByAuthorId(Long id);
1616
}

src/main/java/services/PostService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface PostService {
2020
List<Post> findAll();
2121
List<PostSummary> findLatest5();
2222
List<PostByAuthor> findPostsByAuthor(Long id);
23-
PostDetail findById(Long id);
23+
Post findById(Long id);
2424
PostDetail findByIdAndPublishedTrue(Long id);
2525
Post create(Post post);
2626
Post edit(Post post);

src/main/java/services/PostServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public List<PostByAuthor> findPostsByAuthor(Long id) {
6464
}
6565

6666
@Override
67-
public PostDetail findById(Long id) {
67+
public Post findById(Long id) {
6868
return postRepository.findById(id);
6969
}
7070

src/main/webapp/WEB-INF/i18n/messages.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# To change this license header, choose License Headers in Project Properties.
22
# To change this template file, choose Tools | Templates
33
# and open the template in the editor.
4+
###### Titles #########
5+
admin.home.title = Adminstraci\u00f3n del Blog
6+
admin.login.title = Iniciar Sesi\u00f3n
7+
admin.signup.title = Registrarse
8+
admin.post.all.title = Todos los art\u00edculos
9+
admin.post.create.title = Crear nuevo art\u00edculo
10+
admin.post.delete.title = Eliminar Art\u00edculo
11+
admin.post.edit.title = Editar Art\u00edculo
12+
admin.user.all.title = Todos los usuarios
13+
frontend.post.show.title = OhMyBlog! | {0}
14+
frontend.post.about.title = Acerca de este blog
15+
frontend.post.home.title = ohMyBlog! | Blog para los amantes de la web
416
###### Navigation #######
517
frontend.navigation.home = Inicio
618
frontend.navigation.about = Acerca de

src/main/webapp/WEB-INF/templates/admin/fragment/post.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@
2626
</div>
2727
</div>
2828
<div class="row control-group">
29-
<div class="form-group col-xs-12">
29+
<div class="form-group">
3030
<label class="col-md-2 control-label" th:text="#{form.post.status}">Post status</label>
3131
<div class="col-md-10">
3232
<div class="radio">
33-
<label for="radio_published" th:text="#{form.post.published}">Published</label>
34-
<input th:field="*{published}" type="radio" id="radio_published" name="post_status" value="true" />
33+
<label>
34+
<input th:field="*{published}" type="radio" id="radio_published" name="post_status" value="true" />
35+
<span th:text="#{form.post.published}">Published</span>
36+
</label>
3537
</div>
3638
<div class="radio">
37-
<label for="radio_not_published" th:text="#{form.post.notpublished}">Not Published</label>
38-
<input th:field="*{published}" type="radio" id="radio_not_published" name="post_status" value="false" />
39+
<label>
40+
<input th:field="*{published}" type="radio" id="radio_not_published" name="post_status" value="false" />
41+
<span th:text="#{form.post.notpublished}">Not Published</span>
42+
</label>
3943
</div>
4044
</div>
4145
</div>
4246
</div>
4347
<div class="row control-group">
4448
<div class="form-group">
45-
<label class="col-md-2 control-label" th:text="#{form.post.image.label}">Image</label>
46-
<div class="col-md-10">
47-
<input type="file" accept="image/jpeg,image/png,image/gif" class="btn btn-default" id="image" name="postImage">
49+
<label class="col-md-1 control-label" th:text="#{form.post.image.label}">Image</label>
50+
<div class="col-md-11">
51+
<input type="file" accept="image/jpeg,image/jpg,image/png,image/gif" class="btn btn-default" id="image" name="postImage">
4852
<p class="help-block" th:text="#{form.post.image.help}">
4953
some help text here.
5054
</p>

src/main/webapp/WEB-INF/templates/admin/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html layout:decorator="admin/layout">
33
<head>
4-
<title>TODO supply a title</title>
4+
<title th:text="#{admin.home.title}">Admin</title>
55
</head>
66
<body>
77
<div layout:fragment="content">

src/main/webapp/WEB-INF/templates/admin/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html layout:decorator="admin/layout">
33
<head>
4-
<title>Login</title>
4+
<title th:text="#{admin.login.title}">Login</title>
55
</head>
66
<body>
77
<div layout:fragment="page-content">

src/main/webapp/WEB-INF/templates/admin/post/all.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
55
layout:decorator="admin/layout">
66
<head>
7-
<title>TODO supply a title</title>
7+
<title th:text="#{admin.post.all.title}">All Posts</title>
88
</head>
99
<body>
1010
<div layout:fragment="main-content">

src/main/webapp/WEB-INF/templates/admin/post/create.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
55
layout:decorator="admin/layout">
66
<head>
7-
<title>TODO supply a title</title>
8-
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap-wysihtml5-0.0.2.css}"></link>
7+
<title th:text="#{admin.post.create.title}">Create Post</title>
8+
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap3-wysihtml5.min.css}"></link>
99
</head>
1010
<body>
1111
<div layout:fragment="main-content">
@@ -17,11 +17,14 @@
1717
</div>
1818
</div>
1919
<th:block layout:fragment="scripts">
20-
<script th:src="@{/js/wysihtml5-0.3.0.min.js}"></script>
21-
<script th:src="@{/js/bootstrap-wysihtml5-0.0.2.min.js}"></script>
20+
<script th:src="@{/js/bootstrap3-wysihtml5.all.min.js}"></script>
2221
<script>
2322
$(function() {
24-
$('#bootstrap-editor').wysihtml5();
23+
$('#bootstrap-editor').wysihtml5({
24+
toolbar: {
25+
"fa": true
26+
}
27+
});
2528
});
2629
</script>
2730
</th:block>

0 commit comments

Comments
 (0)