diff --git a/.gitignore b/.gitignore index c2065bc..b73c1e2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +front/lab4_vue_front/node_modules ### STS ### .apt_generated diff --git a/data.mv.db b/data.mv.db index 23341a7..04dc635 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/webproglabs/lab1/lab34/controller/ProfileDto.java b/src/main/java/com/webproglabs/lab1/lab34/controller/ProfileDto.java index 398331f..8b97a48 100644 --- a/src/main/java/com/webproglabs/lab1/lab34/controller/ProfileDto.java +++ b/src/main/java/com/webproglabs/lab1/lab34/controller/ProfileDto.java @@ -15,6 +15,9 @@ public class ProfileDto { private List comments = new ArrayList<>(); private List posts = new ArrayList<>(); + + public ProfileDto(){} + public ProfileDto(Profile profile){ this.id = profile.getId(); this.login = profile.getLogin(); @@ -32,7 +35,9 @@ public class ProfileDto { return id; } public String getLogin() {return login;} + public void setLogin(String login) {this.login = login;} public String getPassword() {return password;} + public void setPassword(String password) {this.password = password;} public List getComments() {return comments;} public List getPosts() {return posts;} } diff --git a/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/FeedMvcController.java b/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/FeedMvcController.java index 6ceecf8..a173e4c 100644 --- a/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/FeedMvcController.java +++ b/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/FeedMvcController.java @@ -31,7 +31,7 @@ public class FeedMvcController { } @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("posts", postService.findAllPosts().stream().map(PostDto::new).toList()); model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id))); @@ -40,7 +40,7 @@ public class FeedMvcController { } @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("posts", postService.findFilteredPosts(searchField).stream().map(PostDto::new).toList()); model.addAttribute("selectedProfile", new ProfileDto(profileService.findUser(id))); @@ -48,19 +48,19 @@ public class FeedMvcController { } @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); return "redirect:/feed/" + id.toString(); } @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); return "redirect:/feed/" + authorId.toString(); } @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("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList()); model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList()); @@ -69,13 +69,13 @@ public class FeedMvcController { } @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); return "redirect:/feed/" + authorId.toString(); } @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("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList()); model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList()); @@ -84,19 +84,19 @@ public class FeedMvcController { } @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); return "redirect:/feed/" + authorId.toString(); } @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); return "redirect:/feed/" + authorId.toString(); } @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("profiles", profileService.findAllUsers().stream().map(ProfileDto::new).toList()); model.addAttribute("posts", postService.findAllPosts().stream().map(PostDto::new).toList()); @@ -105,7 +105,7 @@ public class FeedMvcController { } @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); return "redirect:/feed/" + authorId.toString(); } diff --git a/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/ProfileMvcController.java b/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/ProfileMvcController.java index efd2e16..0621cff 100644 --- a/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/ProfileMvcController.java +++ b/src/main/java/com/webproglabs/lab1/lab34/controller/mvc_controllers/ProfileMvcController.java @@ -4,9 +4,9 @@ import com.webproglabs.lab1.lab34.controller.ProfileDto; import com.webproglabs.lab1.lab34.services.ProfileService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; @Controller @RequestMapping("/") @@ -22,9 +22,28 @@ public class ProfileMvcController { 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}"}) - 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))); 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"; + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 4d91ccf..706ec28 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -21,7 +21,7 @@

- Профили + Профили Лента

diff --git a/src/main/resources/templates/editCommentModal.html b/src/main/resources/templates/editCommentModal.html index 1a3ccb9..7b2bdba 100644 --- a/src/main/resources/templates/editCommentModal.html +++ b/src/main/resources/templates/editCommentModal.html @@ -15,7 +15,7 @@ + + \ No newline at end of file