Skip to content

Commit c0f4836

Browse files
Quick fix #3
1 parent 50337c7 commit c0f4836

8 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/main/java/site/studybuddy/web/controllers/PostController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public String deletePost(@PathVariable Long id, Principal principal) {
186186
return "redirect:/posts/" + id;
187187
}
188188

189+
likeRepository.deleteAllByPostId(post.get().getId());
189190
postRepository.delete(post.get());
190191
return "redirect:/";
191192
}

src/main/java/site/studybuddy/web/controllers/ProfileController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public String profile(Principal principal, Model model) {
2727
}
2828

2929
model.addAttribute("username", student.get().getUsername());
30-
model.addAttribute("biography",student.get().getBiography());
30+
model.addAttribute("registeredOn",student.get().getRegistrationDate());
31+
model.addAttribute("verified",student.get().isVerified());
3132
return "profile";
3233
}
3334

src/main/java/site/studybuddy/web/model/Post.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Post {
2121
private String title;
2222

2323
@Column(nullable = false, length = 2000)
24-
@Size(max = 2000)
24+
@Size(max = 500)
2525
private String body;
2626

2727
@ManyToOne

src/main/java/site/studybuddy/web/repository/LikeRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public interface LikeRepository extends JpaRepository<PostLike, Long> {
1111
boolean existsByPostIdAndAddedById(Long postId, Long studentId);
1212
void deleteByPostIdAndAddedById(Long postId, Long studentId);
1313
Set<PostLike> findByPostId(Long postId);
14+
void deleteAllByPostId(Long postId);
1415
}

src/main/resources/static/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,7 @@ a {
166166
border: none;
167167
cursor: pointer;
168168
}
169+
170+
.delete-btn {
171+
float: right;
172+
}

src/main/resources/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h3><a th:href="@{/posts/{id}(id=${post.getId()})}" th:text="${post.getTitle()}"
2020

2121
<div sec:authorize="isAuthenticated()">
2222
<form th:action="@{/posts/{id}/like(id=${post.getId()})}" method="post">
23+
<input type="hidden" name="origin" th:value="@{/#post-{id}(id=${post.getId()})}">
2324
<span th:text="${post.likes.size()}"></span>
2425
<span th:if="${post.likes.size() == 1}">like</span>
2526
<span th:unless="${post.likes.size() == 1}">likes</span>

src/main/resources/templates/profile.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
<title>Study Buddy - Profile</title>
44
<main class="profile-container">
55
<section class="profile-card">
6-
<div class="profile-avatar">
7-
<div class="avatar-circle">Photo</div>
8-
</div>
9-
106
<h3 th:text="${username}"></h3>
11-
<p class="profile-bio" th:text="${biography}"></p>
7+
<p class="profile-box">
8+
With us since: <span th:text="${registeredOn}"></span>
9+
</p>
10+
<p class="profile-box" th:if="${verified}">
11+
Verified: ✅
12+
</p>
1213
</section>
1314

1415
</main>

src/main/resources/templates/view-post.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
<title>Study Buddy - View Post</title>
44

55
<main class="container">
6-
<h2 th:text="${post.title}"></h2>
7-
<p><i th:text="${post.category.name}"></i></p>
8-
<p th:text="${post.body}"></p>
6+
<div style="float: left">
7+
<h2 th:text="${post.title}"></h2>
8+
<p><i th:text="${post.category.name}"></i></p>
9+
</div>
910

10-
<form sec:authorize="isAuthenticated()" th:if="${showDelete}" th:action="@{/posts/{id}/delete(id=${post.id})}" method="post">
11+
<form class="delete-btn" sec:authorize="isAuthenticated()" th:if="${showDelete}" th:action="@{/posts/{id}/delete(id=${post.id})}" method="post">
1112
<button type="submit">Delete</button>
1213
</form>
14+
<div style="clear: both"></div>
15+
<p th:text="${post.body}"></p>
1316

1417
<div sec:authorize="isAuthenticated()">
1518
<form th:action="@{/posts/{id}/like(id=${post.getId()})}" method="post">

0 commit comments

Comments
 (0)