-
Notifications
You must be signed in to change notification settings - Fork 4
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 #58 from sjmjys954646/feature/2-branch-watching
Feature/2 branch watching
- Loading branch information
Showing
6 changed files
with
187 additions
and
46 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/demo/video/VideoJPARepository.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,13 +1,32 @@ | ||
package com.example.demo.video; | ||
|
||
import com.example.demo.mentoring.MentorPost; | ||
import com.example.demo.user.userInterest.UserInterest; | ||
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; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface VideoJPARepository extends JpaRepository<Video, Integer> { | ||
Optional<Video> findById(int id); | ||
|
||
@Query(value = "SELECT * FROM videos v " + | ||
"INNER JOIN video_interests vi ON v.id = vi.video_id " + | ||
"INNER JOIN interest_tb i ON vi.interest_id = i.id " + | ||
"WHERE i.category IN :userInterests " + | ||
"ORDER BY RAND()", // MySQL에서 랜덤 정렬 | ||
countQuery = "SELECT COUNT(*) FROM videos v " + | ||
"INNER JOIN video_interests vi ON v.id = vi.video_id " + | ||
"INNER JOIN interest_tb i ON vi.interest_id = i.id " + | ||
"WHERE i.category IN :userInterests", // 페이징을 위한 count 쿼리 | ||
nativeQuery = true) | ||
Page<Video> findByVideoCategory(@Param("userInterests") List<String> userInterests, Pageable pageable); | ||
|
||
|
||
@Query(value = "select v from Video v inner join VideoInterest vi on v.id = vi.video.id where vi.interest.id = :categoryId") | ||
Page<Video> findByCategoryId(@Param("categoryId") int id, 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
Oops, something went wrong.