Lab5
This commit is contained in:
parent
bb8cc89e78
commit
859f55cbde
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ build/
|
|||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
!**/src/test/**/build/
|
!**/src/test/**/build/
|
||||||
|
front/lab4_vue_front/node_modules
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -15,6 +15,9 @@ public class ProfileDto {
|
|||||||
private List<CommentDto> comments = new ArrayList<>();
|
private List<CommentDto> comments = new ArrayList<>();
|
||||||
|
|
||||||
private List<PostDto> posts = new ArrayList<>();
|
private List<PostDto> posts = new ArrayList<>();
|
||||||
|
|
||||||
|
public ProfileDto(){}
|
||||||
|
|
||||||
public ProfileDto(Profile profile){
|
public ProfileDto(Profile profile){
|
||||||
this.id = profile.getId();
|
this.id = profile.getId();
|
||||||
this.login = profile.getLogin();
|
this.login = profile.getLogin();
|
||||||
@ -32,7 +35,9 @@ public class ProfileDto {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
public String getLogin() {return login;}
|
public String getLogin() {return login;}
|
||||||
|
public void setLogin(String login) {this.login = login;}
|
||||||
public String getPassword() {return password;}
|
public String getPassword() {return password;}
|
||||||
|
public void setPassword(String password) {this.password = password;}
|
||||||
public List<CommentDto> getComments() {return comments;}
|
public List<CommentDto> getComments() {return comments;}
|
||||||
public List<PostDto> getPosts() {return posts;}
|
public List<PostDto> getPosts() {return posts;}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/{id}"})
|
@GetMapping(value = {"/{id}"})
|
||||||
public String getFeedPageAuthorized(@PathVariable(required = false) Long id, Model model) {
|
public String getFeedPageAuthorized(@PathVariable Long id, Model model) {
|
||||||
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
||||||
model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id)));
|
model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id)));
|
||||||
@ -40,7 +40,7 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value= {"/filter/{id}/"})
|
@GetMapping(value= {"/filter/{id}/"})
|
||||||
public String getFeedPageFiltered(@PathVariable(required = false) Long id, @RequestParam(value="searchField") String searchField, Model model) {
|
public String getFeedPageFiltered(@PathVariable Long id, @RequestParam(value="searchField") String searchField, Model model) {
|
||||||
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
model.addAttribute("posts", postService.findFilteredPosts(searchField).stream().map(PostDto::new).toList());
|
model.addAttribute("posts", postService.findFilteredPosts(searchField).stream().map(PostDto::new).toList());
|
||||||
model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id)));
|
model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id)));
|
||||||
@ -48,19 +48,19 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value={"/post/{id}/"})
|
@PostMapping(value={"/post/{id}/"})
|
||||||
public String createPost(@PathVariable(required = false) Long id, @RequestParam(value="postInputField") String postInputField) {
|
public String createPost(@PathVariable Long id, @RequestParam(value="postInputField") String postInputField) {
|
||||||
postService.addPost(postInputField, new ArrayList<>(), id);
|
postService.addPost(postInputField, new ArrayList<>(), id);
|
||||||
return "redirect:/feed/" + id.toString();
|
return "redirect:/feed/" + id.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"/deletePost/{id}/{authorId}"})
|
@PostMapping(value = {"/deletePost/{id}/{authorId}"})
|
||||||
public String deletePost(@PathVariable(required = false) Long id, @PathVariable(required = false) Long authorId) {
|
public String deletePost(@PathVariable Long id, @PathVariable Long authorId) {
|
||||||
postService.deletePost(id);
|
postService.deletePost(id);
|
||||||
return "redirect:/feed/" + authorId.toString();
|
return "redirect:/feed/" + authorId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"postModal/{id}/{authorId}"})
|
@GetMapping(value = {"postModal/{id}/{authorId}"})
|
||||||
public String getPostEditModal(@PathVariable(required = false) Long id,@PathVariable(required = false) Long authorId, Model model) {
|
public String getPostEditModal(@PathVariable Long id,@PathVariable Long authorId, Model model) {
|
||||||
model.addAttribute("selectedPost", new PostDto(postService.findPost(id)));
|
model.addAttribute("selectedPost", new PostDto(postService.findPost(id)));
|
||||||
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
||||||
@ -69,13 +69,13 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"editPost/{id}/{authorId}/"})
|
@PostMapping(value = {"editPost/{id}/{authorId}/"})
|
||||||
public String editPost(@PathVariable(required = false) Long id, @PathVariable(required = false) Long authorId, @RequestParam(value="postEditField") String postEditField) {
|
public String editPost(@PathVariable Long id, @PathVariable Long authorId, @RequestParam(value="postEditField") String postEditField) {
|
||||||
postService.updatePost(id, postEditField);
|
postService.updatePost(id, postEditField);
|
||||||
return "redirect:/feed/" + authorId.toString();
|
return "redirect:/feed/" + authorId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"commentModal/{authorId}/{postId}"})
|
@GetMapping(value = {"commentModal/{authorId}/{postId}"})
|
||||||
public String getCommentModal(@PathVariable(required = false) Long authorId,@PathVariable(required = false) Long postId, Model model) {
|
public String getCommentModal(@PathVariable Long authorId,@PathVariable Long postId, Model model) {
|
||||||
model.addAttribute("selectedPost", new PostDto(postService.findPost(postId)));
|
model.addAttribute("selectedPost", new PostDto(postService.findPost(postId)));
|
||||||
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
||||||
@ -84,19 +84,19 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"comment/{authorId}/{postId}/"})
|
@PostMapping(value = {"comment/{authorId}/{postId}/"})
|
||||||
public String createComment(@PathVariable(required = false) Long authorId,@PathVariable(required = false) Long postId, @RequestParam(value="commentInputField") String commentInputField) {
|
public String createComment(@PathVariable Long authorId,@PathVariable Long postId, @RequestParam(value="commentInputField") String commentInputField) {
|
||||||
commentService.addComment(commentInputField, authorId, postId);
|
commentService.addComment(commentInputField, authorId, postId);
|
||||||
return "redirect:/feed/" + authorId.toString();
|
return "redirect:/feed/" + authorId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"/deleteComment/{id}/{authorId}"})
|
@PostMapping(value = {"/deleteComment/{id}/{authorId}"})
|
||||||
public String deleteComment(@PathVariable(required = false) Long id, @PathVariable(required = false) Long authorId) {
|
public String deleteComment(@PathVariable Long id, @PathVariable Long authorId) {
|
||||||
commentService.deleteComment(id);
|
commentService.deleteComment(id);
|
||||||
return "redirect:/feed/" + authorId.toString();
|
return "redirect:/feed/" + authorId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"commentEditModal/{id}/{authorId}"})
|
@GetMapping(value = {"commentEditModal/{id}/{authorId}"})
|
||||||
public String getCommentEditModal(@PathVariable(required = false) Long id,@PathVariable(required = false) Long authorId, Model model) {
|
public String getCommentEditModal(@PathVariable Long id,@PathVariable Long authorId, Model model) {
|
||||||
model.addAttribute("selectedComment", new CommentDto(commentService.findComment(id)));
|
model.addAttribute("selectedComment", new CommentDto(commentService.findComment(id)));
|
||||||
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList());
|
||||||
@ -105,7 +105,7 @@ public class FeedMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = {"editComment/{authorId}/{commentId}/"})
|
@PostMapping(value = {"editComment/{authorId}/{commentId}/"})
|
||||||
public String editComment(@PathVariable(required = false) Long authorId,@PathVariable(required = false) Long commentId, @RequestParam(value="commentEditField") String commentEditField) {
|
public String editComment(@PathVariable Long authorId,@PathVariable Long commentId, @RequestParam(value="commentEditField") String commentEditField) {
|
||||||
commentService.updateComment(commentId, commentEditField);
|
commentService.updateComment(commentId, commentEditField);
|
||||||
return "redirect:/feed/" + authorId.toString();
|
return "redirect:/feed/" + authorId.toString();
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import com.webproglabs.lab1.lab34.controller.ProfileDto;
|
|||||||
import com.webproglabs.lab1.lab34.services.ProfileService;
|
import com.webproglabs.lab1.lab34.services.ProfileService;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
@ -22,9 +22,28 @@ public class ProfileMvcController {
|
|||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(value={"profiles"})
|
||||||
|
public String getProfiles(Model model) {
|
||||||
|
model.addAttribute("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList());
|
||||||
|
model.addAttribute("profileDto", new ProfileDto());
|
||||||
|
return "profiles";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"profile/{login}"})
|
@GetMapping(value = {"profile/{login}"})
|
||||||
public String getProfile(@PathVariable(required = false) String login, Model model) {
|
public String getProfile(@PathVariable String login, Model model) {
|
||||||
model.addAttribute("profile", new ProfileDto(profileService.findUserByLogin(login)));
|
model.addAttribute("profile", new ProfileDto(profileService.findUserByLogin(login)));
|
||||||
return "profilePage";
|
return "profilePage";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = {"profile/{id}"})
|
||||||
|
public String deleteProfile(@PathVariable Long id) {
|
||||||
|
profileService.deleteUser(id);
|
||||||
|
return "redirect:/profiles";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = {"profile/create/"})
|
||||||
|
public String createProfile(@ModelAttribute ProfileDto profileDto) {
|
||||||
|
profileService.addUser(profileDto.getLogin(), profileDto.getPassword(), new ArrayList<>(), new ArrayList<>());
|
||||||
|
return "redirect:/profiles";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class='h4 text-center'>
|
<p class='h4 text-center'>
|
||||||
<a href="/" class="text-decoration-none m-3">Профили</a>
|
<a href="/profiles" class="text-decoration-none m-3">Профили</a>
|
||||||
<a href="/feed" class="text-decoration-none m-3">Лента</a>
|
<a href="/feed" class="text-decoration-none m-3">Лента</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<form th:action="@{/feed/editComment/{id}/{commentId}/{text} (id=${selectedProfile.id}, commentId=${selectedComment.id}, text=${commentEditField}) }" method="post" class="modal-body text-center">
|
<form th:action="@{/feed/editComment/{id}/{commentId}/{text} (id=${selectedProfile.id}, commentId=${selectedComment.id}, text=${commentEditField}) }" method="post" class="modal-body text-center">
|
||||||
<p>Новый текст комментария:</p>
|
<p>Новый текст комментария:</p>
|
||||||
<input th:value="${commentEditField}" id="commentEditField" name="commentEditField" type="text" class="mb-2">
|
<input th:attr="value = ${selectedComment.text}" id="commentEditField" name="commentEditField" type="text" class="mb-2">
|
||||||
<br>
|
<br>
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||||
<button type="submit" class="btn btn-primary" >Изменить</button>
|
<button type="submit" class="btn btn-primary" >Изменить</button>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<form th:action="@{/feed/editPost/{id}/{authorId}/{text} (id=${selectedPost.id}, authorId=${selectedProfile.id}, text=${postEditField} ) }" method="post" class="modal-body text-center">
|
<form th:action="@{/feed/editPost/{id}/{authorId}/{text} (id=${selectedPost.id}, authorId=${selectedProfile.id}, text=${postEditField} ) }" method="post" class="modal-body text-center">
|
||||||
<p>Текст поста:</p>
|
<p>Текст поста:</p>
|
||||||
<input th:value="${postEditField}" id="postEditField" name="postEditField" type="text" class="mb-2">
|
<input th:attr="value = ${selectedPost.text}" id="postEditField" name="postEditField" type="text" class="mb-2">
|
||||||
<br>
|
<br>
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||||
<button type="submit" class="btn btn-primary" >Сохранить</button>
|
<button type="submit" class="btn btn-primary" >Сохранить</button>
|
||||||
|
60
src/main/resources/templates/profiles.html
Normal file
60
src/main/resources/templates/profiles.html
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div layout:fragment="content" class="text-center">
|
||||||
|
|
||||||
|
<button class="btn btn-info w-25 mb-3" data-bs-toggle="modal" data-bs-target="#profileCreate">
|
||||||
|
Регистрация профиля
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div th:each="profile: ${profiles}" class="mb-2">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="text-start mx-auto w-25 border p-3">
|
||||||
|
<p class='h5'>Профиль</p>
|
||||||
|
<p th:text="${'Логин: ' + profile.login}"></p>
|
||||||
|
<p class='h6 '>Список постов пользователя: </p>
|
||||||
|
|
||||||
|
<div th:if="${profile.posts.size()>0}">
|
||||||
|
<div th:each="post: ${profile.posts}">
|
||||||
|
<p th:text="${post.text}" class="mb-3 ms-2 border p-2"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p th:unless="${profile.posts.size()>0}">
|
||||||
|
Нет постов
|
||||||
|
</p>
|
||||||
|
<div class="text-end">
|
||||||
|
<form action="#" th:action="@{/profile/{id} (id=${profile.id})}" method="post" >
|
||||||
|
<button type="submit" class="btn btn-danger">Удалить</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="profileCreate" tabindex="-1" role="dialog" aria-labelledby="profileCreateLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="profileCreateLabel">Регистрация профиля</h5>
|
||||||
|
</div>
|
||||||
|
<form action="#" th:action="@{/profile/create/}" th:object="${profileDto}" method="post" class="modal-body text-center">
|
||||||
|
<p>Логин: </p>
|
||||||
|
<input th:field="${profileDto.login}" type="text" class="mb-2 form-control" required="true" />
|
||||||
|
<br>
|
||||||
|
<p>Пароль: </p>
|
||||||
|
<input th:field="${profileDto.password}" type="text" class="mb-2 form-control" required="true" />
|
||||||
|
<br>
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||||
|
<button type="submit" class="btn btn-primary" >Регистрация</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user