-
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.
- Loading branch information
1 parent
12cdf61
commit 380f0d8
Showing
11 changed files
with
238 additions
and
153 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
package com.photo.domain.image; | ||
|
||
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; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ImageRepository extends JpaRepository<Image, Integer> { | ||
|
||
@Query(value = "SELECT * FROM image WHERE userId IN (SELECT toUserId FROM follow WHERE fromUserId = :sessionId)", nativeQuery = true) | ||
Page<Image> cFeed (@Param(value = "sessionId") int sessionId, @Param(value = "pageable") Pageable pageable); | ||
|
||
|
||
} |
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,33 @@ | ||
package com.photo.web.api; | ||
|
||
import com.photo.config.auth.CustomUserDetails; | ||
import com.photo.domain.image.Image; | ||
import com.photo.service.ImageService; | ||
import com.photo.web.dto.ResDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class ImageApiController { | ||
|
||
private final ImageService imageService; | ||
|
||
@GetMapping("/api/feed") | ||
public ResponseEntity<?> Feed(@AuthenticationPrincipal CustomUserDetails customUserDetails, | ||
@PageableDefault(size=4, sort="id", direction = Sort.Direction.DESC) Pageable pageable){ | ||
Page<Image> images = imageService.Feed(customUserDetails.getUser().getId(), pageable); | ||
return new ResponseEntity<>(new ResDto<>(1,"피드 성공", images), HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
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,159 @@ | ||
/** | ||
2. 스토리 페이지 | ||
(1) 스토리 로드하기 | ||
(2) 스토리 스크롤 페이징하기 | ||
(3) 좋아요, 안좋아요 | ||
(4) 댓글쓰기 | ||
(5) 댓글삭제 | ||
*/ | ||
|
||
// (1) 스토리 로드하기 | ||
let page = 0; | ||
|
||
function storyLoad() { | ||
$.ajax({ | ||
type: "get", | ||
url: `/api/feed?page=${page}`, | ||
dataType: "json", | ||
success: function(res) { | ||
console.log(res.data) | ||
|
||
res.data.content.forEach((image) => { | ||
let storyItem = getStoryItem(image); | ||
|
||
$("#storyList").append(storyItem); | ||
}); | ||
}, | ||
error: function(error) { | ||
console.log("스토리 렌더링 오류", error); | ||
} | ||
}); | ||
} | ||
|
||
storyLoad(); | ||
|
||
function getStoryItem(image) { | ||
let item =`<div class="story-list__item"> | ||
<div class="sl__item__header"> | ||
<div> | ||
<img class="profile-image" src="/upload/${image.user.profileImageUrl}" onerror="this.src='/images/defaultStory.png'" /> | ||
</div> | ||
<div>${image.user.username}</div> | ||
</div> | ||
<div class="sl__item__img"> | ||
<img src="/upload/${image.imageUrl}" /> | ||
</div> | ||
<div class="sl__item__contents"> | ||
<div class="sl__item__contents__icon"> | ||
<button> | ||
<i class="fas fa-heart active" id="storyLikeIcon-1" onclick="toggleLike()"></i> | ||
</button> | ||
</div> | ||
<span class="like"><b id="storyLikeCount-1">3 </b>likes</span> | ||
<div class="sl__item__contents__content"> | ||
<p>${image.caption}</p> | ||
</div> | ||
<div id="storyCommentList-1"> | ||
<div class="sl__item__contents__comment" id="storyCommentItem-1"> | ||
<p> | ||
<b>blueberry :</b> 저도 꼭 볼게요! | ||
</p> | ||
<button> | ||
<i class="fas fa-times"></i> | ||
</button> | ||
</div> | ||
</div> | ||
<div class="sl__item__input"> | ||
<input type="text" placeholder="댓글 달기" id="storyCommentInput-1" /> | ||
<button type="button" onClick="addComment()">게시</button> | ||
</div> | ||
</div> | ||
</div>`; | ||
return item; | ||
|
||
} | ||
|
||
// (2) 스토리 스크롤 페이징하기 | ||
$(window).scroll(() => { | ||
/* | ||
console.log("윈도우 현재 scroll 위치", $(window).scrollTop()); | ||
console.log("전체 문서의 높이(고정값)", $(document).height()); | ||
console.log("윈도우 높이(고정값, 보이는 컴퓨터 화면)", $(window).height()); | ||
결과 : 전체 문서의 높이 - 윈도우 높이 = 윈도우 현재 scroll 위치 | ||
*/ | ||
|
||
let checkNum = $(window).scrollTop() - ($(document).height() - $(window).height()); | ||
|
||
if(checkNum < 1 && checkNum > -1) { | ||
page++; | ||
storyLoad(); | ||
} | ||
|
||
}); | ||
|
||
|
||
// (3) 좋아요, 안좋아요 | ||
function toggleLike() { | ||
let likeIcon = $("#storyLikeIcon-1"); | ||
if (likeIcon.hasClass("far")) { | ||
likeIcon.addClass("fas"); | ||
likeIcon.addClass("active"); | ||
likeIcon.removeClass("far"); | ||
} else { | ||
likeIcon.removeClass("fas"); | ||
likeIcon.removeClass("active"); | ||
likeIcon.addClass("far"); | ||
} | ||
} | ||
|
||
// (4) 댓글쓰기 | ||
function addComment() { | ||
|
||
let commentInput = $("#storyCommentInput-1"); | ||
let commentList = $("#storyCommentList-1"); | ||
|
||
let data = { | ||
content: commentInput.val() | ||
} | ||
|
||
if (data.content === "") { | ||
alert("댓글을 작성해주세요!"); | ||
return; | ||
} | ||
|
||
let content = ` | ||
<div class="sl__item__contents__comment" id="storyCommentItem-2""> | ||
<p> | ||
<b>GilDong :</b> | ||
댓글 샘플입니다. | ||
</p> | ||
<button><i class="fas fa-times"></i></button> | ||
</div> | ||
`; | ||
commentList.prepend(content); | ||
commentInput.val(""); | ||
} | ||
|
||
// (5) 댓글 삭제 | ||
function deleteComment() { | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
|
||
<div th:replace="~{/layout/header :: header}"></div> | ||
|
||
<main class="main"> | ||
<section class="container" style="width: 35%"> | ||
<!--전체 리스트 시작--> | ||
<article class="story-list" id="storyList"> | ||
</article> | ||
</section> | ||
</main> | ||
<script th:src="@{/js/feed.js}"></script> | ||
|
||
</html> |
Oops, something went wrong.