Skip to content

Commit a27eb21

Browse files
update for UI for post.html
1 parent 76ff1cc commit a27eb21

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

src/main/java/com/mountblue/stackoverflow/controller/QuestionCommentController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.ui.Model;
1111
import org.springframework.web.bind.annotation.*;
1212

13+
import java.time.LocalDateTime;
1314
import java.util.List;
1415
@Controller
1516
@RequestMapping("/questionComment")
@@ -41,13 +42,19 @@ public String showFormForQuestionComment(@PathVariable("questionId") int questio
4142
}
4243

4344
@PostMapping("/saveQuestionComment")
44-
public String saveQuestionComment(@RequestParam("questionId") int questionId, @RequestParam("questionCommentId") int questionCommentId,
45-
@RequestParam("userEmail") String userEmail, Model model, @ModelAttribute("questionComments") QuestionComment questionComment) {
45+
public String saveQuestionComment(@RequestParam("questionId") int questionId,
46+
@RequestParam("questionCommentId") int questionCommentId,
47+
@RequestParam("createdAt") LocalDateTime createdAt,
48+
@RequestParam("userEmail") String userEmail, Model model,
49+
@ModelAttribute("questionComments") QuestionComment questionComment) {
4650
Question question = questionService.getQuestion(questionId);
4751
User user = userService.getUserByEmail(userEmail);
4852
questionComment.setQuestion(question);
4953
if (questionCommentId != 0)
54+
{
5055
questionComment.setId(questionCommentId);
56+
questionComment.setCreatedAt(createdAt);
57+
}
5158
questionComment.setUserName(user.getName());
5259
questionComment.setEmail(user.getEmail());
5360
questionCommentService.save(questionComment);

src/main/java/com/mountblue/stackoverflow/controller/QuestionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public String sortQuestionsByFilter(@RequestParam("userEmail") String userEmail,
179179
return "question/question-list2";
180180
}
181181

182-
@GetMapping("/showAllQuestionForNonLoggedInUser")
182+
@GetMapping("/showAll")
183183
public String viewPostsList(Model model) {
184184
List<Question> Questions = questionService.getAllQuestions();
185185
String userEmail = "[email protected]";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<meta http-equiv="refresh" content="0; URL='question/showAllQuestionForNonLoggedInUser'">
1+
<meta http-equiv="refresh" content="0; URL='question/showAll'">

src/main/resources/templates/fragments/navigation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h3>Stack Overflow</h3>
3737
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3838
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3939
<div class="col-3 float-lg-right">
40-
<a th:if="${user.name} != 'guest'" th:href="@{/question/showAllQuestionForNonLoggedInUser}" class="btn btn-primary">Log Out</a>
40+
<a th:if="${user.name} != 'guest'" th:href="@{/question/showAll}" class="btn btn-primary">Log Out</a>
4141
</div>
4242
</div>
4343
</nav>

src/main/resources/templates/layout/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div class="user-area">
2828
<a th:if="${user.name} == 'guest'" th:href="@{/user/showLoginForm}" class="btn btn-info mr-2 text-white">Log in</a>
2929
<a th:if="${user.name} == 'guest'" th:href="@{/user/showSignupForm}" class="btn btn-primary text-white">Sign up</a>
30-
<a th:if="${user.name} != 'guest'" th:href="@{/question/showAllQuestionForNonLoggedInUser}"
30+
<a th:if="${user.name} != 'guest'" th:href="@{/question/showAll}"
3131
class="btn btn-primary text-white">Log Out</a>
3232

3333
<a th:if="${user.email} == '[email protected]'" class="btn btn-info btn-sm-3 float-right text-white"

src/main/resources/templates/post.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ <h6> Asked <i>today</i> Active <i>today</i> Viewed <i th:text="${question.views
110110
</div><!--/q-meta-->
111111
<div class="q-alt-replies-area">
112112
<div class="q-alt-replies"><br>
113-
<div class="alt-item" th:each="comment : ${question.comments}">
114-
<div class="alt-text" th:text="${comment.content}">
113+
<div class="alt-item" th:each="questionComment : ${question.comments}">
114+
<div class="alt-text" th:text="${questionComment.content}">
115115
</div><!--/text-->
116-
<a href="#" ><p th:text="${comment.userName}"></p></a>
116+
<a href="#" ><p th:text="${questionComment.userName}"></p></a>
117117
<!-- <span th:text="${comment.userName}"></span>-->
118-
<small style="color:#808080" th:text="${#temporals.format(comment.createdAt,'dd-MM-yyyy')} +' at '+${#temporals.format(comment.createdAt,'HH:mm')}"></small><br><br>
118+
<small style="color:#808080" th:text="${#temporals.format(questionComment.createdAt,'dd-MM-yyyy')} +' at '+${#temporals.format(questionComment.createdAt,'HH:mm')}"></small><br><br>
119119
<a th:if="${user.email} == ${questionComment.email}"
120120
th:href="@{/questionComment/showFormForUpdateQuestionComment(questionCommentId=${questionComment.id},
121121
userEmail=${user.email}, questionId=${question.id})}">Edit</a>

src/main/resources/templates/question/update-comment-form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<div class="container">
1212
<h3>Update Comment</h3>
1313
<form action="#" th:action="@{/questionComment/saveQuestionComment(questionId=${questionId},
14-
questionCommentId=${questionComment.id}, userEmail=${userEmail})}"
14+
questionCommentId=${questionComment.id}, userEmail=${userEmail}, createdAt=${questionComment.createdAt})}"
1515
th:object="${questionComment}" method="POST">
16+
<!-- <input type="hidden" th:field="*{createdAt}" th:value="${questionComment.createdAt}">-->
1617
<textarea th:required="mendatory" type="text" th:field="*{content}"
1718
class="form-control mb-4 col-4" placeholder="Add Comment" width="100" height="50">
1819
</textarea>
1920
<button type="submit" class="btn btn-info col-2">Save edits</button>
2021
</form>
2122
<br> <br>
22-
<a href="/" th:href="@{/user/showHomePage}">Back to Home Page</a>
2323
</div>
2424
</body>
2525

0 commit comments

Comments
 (0)