-
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 #25 from CodeURJC-DAW-2022-23/feat/home
feat: home
- Loading branch information
Showing
13 changed files
with
185 additions
and
23 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
back/src/main/java/net/daw/alist/controllers/HomeController.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
back/src/main/java/net/daw/alist/controllers/PostController.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.daw.alist.controllers; | ||
|
||
import net.daw.alist.models.Post; | ||
import net.daw.alist.models.User; | ||
import net.daw.alist.services.PostService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.security.core.Authentication; | ||
|
||
@Controller | ||
public class PostController { | ||
|
||
@Autowired | ||
private PostService postService; | ||
|
||
@GetMapping({"/","/followed-users/"}) | ||
public String home(Model model) { | ||
return "feed"; | ||
} | ||
|
||
@GetMapping("/posts") | ||
public String getNewPosts(Model model, @RequestParam int page) { | ||
|
||
Page<Post> newPage = postService.getPosts(page); | ||
|
||
model.addAttribute("posts", newPage); | ||
|
||
return "post"; | ||
} | ||
|
||
@GetMapping("/followed-users/posts") | ||
public String getFollowedUsersPosts(Model model, Authentication authentication, @RequestParam int page) { | ||
|
||
User currentUser = (User) authentication.getPrincipal(); | ||
|
||
Page<Post> starredPost = postService.getStarredPosts(page,currentUser.getId().intValue()); | ||
|
||
model.addAttribute("posts", starredPost); | ||
|
||
return "post"; | ||
} | ||
|
||
|
||
} |
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
7 changes: 7 additions & 0 deletions
7
back/src/main/java/net/daw/alist/repositories/PostRepository.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,7 +1,14 @@ | ||
package net.daw.alist.repositories; | ||
|
||
import net.daw.alist.models.Post; | ||
|
||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
@Query(value="select * from post where post.author_id in (select following_id from user_following where user_following.followers_id=?1) order by post.date desc", nativeQuery=true) | ||
Page<Post> findPostsByFollows(int user_id,Pageable page); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var page = 0; | ||
var url; | ||
|
||
$(document).ready(() => { | ||
// fetch 1st page | ||
|
||
url = window.location.href + 'posts'; | ||
getData(url, page); | ||
|
||
if ($('.post-container').length < 2) showBottomReached(); | ||
}); | ||
|
||
// fetch more posts when bottom is reached | ||
$(window).scroll(function () { | ||
if ($(window).scrollTop() + $(window).height() == $(document).height()) { | ||
page++; | ||
$('.spinner-border').removeClass('invisible').addClass('visible'); | ||
getData(url, page); | ||
} | ||
}); | ||
|
||
// fetch data | ||
const getData = (url, page) => { | ||
$.get(url, { page }, data => { | ||
if (data == '') showBottomReached(); | ||
|
||
$('.post-container').append(data); | ||
$('.spinner-border').removeClass('visible').addClass('invisible'); | ||
}); | ||
}; | ||
|
||
// show message: No more posts :( | ||
const showBottomReached = () => { | ||
$('.no-posts').removeClass('invisible').addClass('visible'); | ||
}; |
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,4 +1,3 @@ | ||
.feed-container { | ||
height: 100vh; | ||
margin: 0 25rem; | ||
margin: 0 1rem; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="commentSection mb-3"> | ||
<div class="writeComment p-3"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://github.com/twbs.png" alt="Profile Photo" width="40" height="40" | ||
class="own-comment-image rounded-circle flex-shrink-0"> | ||
<textarea class="commentBox form-control ml-1 shadow-none textarea"></textarea> | ||
</div> | ||
<div class="mt-2 d-flex justify-content-center"> | ||
<button class="btn btn-primary btn-sm shadow-none" type="button">Post comment</button> | ||
</div> | ||
</div> | ||
|
||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{#posts}} | ||
<div class="post mt-3 mb-3"> | ||
<div class="postInfo border bg-white d-flex gap-3 py-3"> | ||
<img src={{author.imagePath}} alt="Profile picture" width="75" height="75" | ||
class="profileImg rounded-circle flex-shrink-0"> | ||
<div class="d-flex gap-2 w-100 justify-content-between"> | ||
<div> | ||
<div class="d-flex"> | ||
{{#topics}} | ||
<h6 class="topics pe-1"> | ||
<a class="topic" href="#">@{{name}}</a> | ||
</h6> | ||
{{/topics}} | ||
</div> | ||
<a class="OP text-black text-decoration-none" href="#"> | ||
{{author.username}} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="list-group m-auto"> | ||
<div class="bg-white text-black d-flex gap-3 py-3 text-center justify-content-*-center align-items-center" | ||
aria-current="true"> | ||
<div class="top w-75 m-auto"> | ||
<h2 class="topName">{{title}}</h2> | ||
<ol class="m-auto p-0 w-100"> | ||
{{#items}} | ||
<li> | ||
{{description}} | ||
<img src={{imagePath}} alt="image" width="45" height="45" class="itemImage rounded-circle"> | ||
</li> | ||
{{/items}} | ||
</ol> | ||
</div> | ||
</div> | ||
<div class="list-group-item d-flex"> | ||
<div class="w-auto m-auto"> | ||
<img class="upvoteIcon" src="/images/upvoteIcon.svg" alt="" width="35" height="35"> | ||
<img class="downvoteIcon" src="/images/downvoteIcon.svg" alt="" width="35" height="35"> | ||
</div> | ||
<img class="shareIcon m-auto" src="/images/shareIcon.svg" alt="" width="35" height="35"> | ||
</div> | ||
</div> | ||
</div> | ||
{{/posts}} |