-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from CodeURJC-DAW-2022-23/feat/top-list-w/comm…
…ents feat: top list with comments
- Loading branch information
Showing
7 changed files
with
122 additions
and
103 deletions.
There are no files selected for viewing
46 changes: 44 additions & 2 deletions
46
back/src/main/java/net/daw/alist/controllers/TopListController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,66 @@ | ||
package net.daw.alist.controllers; | ||
|
||
import net.daw.alist.models.Comment; | ||
import net.daw.alist.models.Post; | ||
import net.daw.alist.models.User; | ||
import net.daw.alist.services.PostService; | ||
import net.daw.alist.services.UserService; | ||
import net.daw.alist.utils.Utils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.Authentication; | ||
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.RequestParam; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class TopListController { | ||
@Autowired | ||
private UserService userService; | ||
@Autowired | ||
private PostService postService; | ||
@GetMapping("/top-list") | ||
public String topList(Model model) { | ||
|
||
private User userProfile; | ||
private Post post; | ||
|
||
@GetMapping("/top-list/{id}") | ||
public String topList(Model model, Authentication authentication, @PathVariable long id){ | ||
Utils utils = new Utils(userService, postService); | ||
utils.searchBarInitializer(model); | ||
|
||
if(authentication == null){ | ||
model.addAttribute("isRegistered", false); | ||
} else{ | ||
userProfile = (User) authentication.getPrincipal(); | ||
model.addAttribute("isRegistered", true); | ||
model.addAttribute("loggedUserImagePath", userProfile.getImagePath()); | ||
} | ||
|
||
post = postService.findByID(id).orElseThrow(); | ||
|
||
model.addAttribute("id", id); | ||
model.addAttribute("posts", post); | ||
model.addAttribute("title", post.getTitle()); | ||
|
||
List<Comment> comments = post.getComments(); | ||
model.addAttribute("comments", comments); | ||
|
||
return "top-list"; | ||
} | ||
|
||
@RequestMapping("/top-list/{id}/addComment") | ||
public String addComment(@RequestParam String commentContent) throws SQLException, IOException { | ||
User author = userService.findByID(userProfile.getId()).orElseThrow(); | ||
Comment comment = new Comment(author, commentContent, null); | ||
post.addComment(comment); | ||
postService.save(post); | ||
return "redirect:/top-list/{id}"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters