-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
73 changed files
with
1,489 additions
and
785 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
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
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/codezap/global/pagination/FixedPage.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,6 @@ | ||
package codezap.global.pagination; | ||
|
||
import java.util.List; | ||
|
||
public record FixedPage<T> (List<T> contents, int nextPages) { | ||
} |
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/codezap/global/pagination/FixedPageCounter.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,32 @@ | ||
package codezap.global.pagination; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.core.types.dsl.EntityPathBase; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
@Component | ||
public class FixedPageCounter { | ||
|
||
private static final int MAXIMUM_PAGE = 5; | ||
|
||
public int countNextFixedPage( | ||
JPAQueryFactory queryFactory, | ||
EntityPathBase<?> entityPath, | ||
Pageable pageable, | ||
BooleanExpression... conditions | ||
) { | ||
int maximumElementsCount = pageable.getPageSize() * MAXIMUM_PAGE; | ||
long nextFixedElementCounts = queryFactory | ||
.selectFrom(entityPath) | ||
.where(conditions) | ||
.offset(pageable.getOffset()) | ||
.limit(maximumElementsCount) | ||
.fetch() | ||
.size(); | ||
|
||
return (int) Math.ceil((double) nextFixedElementCounts / pageable.getPageSize()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/codezap/global/querydsl/QueryDSLConfig.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,21 @@ | ||
package codezap.global.querydsl; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
@Configuration | ||
public class QueryDSLConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
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
23 changes: 6 additions & 17 deletions
23
backend/src/main/java/codezap/likes/repository/LikesJpaRepository.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,27 +1,16 @@ | ||
package codezap.likes.repository; | ||
|
||
import java.util.List; | ||
|
||
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.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import codezap.likes.domain.Likes; | ||
import codezap.member.domain.Member; | ||
import codezap.template.domain.Template; | ||
|
||
public interface LikesJpaRepository extends LikesRepository, JpaRepository<Likes, Long> { | ||
public interface LikesJpaRepository extends JpaRepository<Likes, Long> { | ||
|
||
void deleteByMemberAndTemplate(Member member, Template template); | ||
|
||
@Modifying(clearAutomatically = true) | ||
@Query("DELETE FROM Likes l WHERE l.template.id in :templateIds") | ||
void deleteAllByTemplateIds(@Param(value = "templateIds") List<Long> templateIds); | ||
boolean existsByMemberAndTemplate(Member member, Template template); | ||
|
||
@Query(""" | ||
SELECT l.template | ||
FROM Likes l | ||
WHERE l.member.id = :memberId AND (l.template.member.id = :memberId OR l.template.visibility = 'PUBLIC') | ||
""") | ||
Page<Template> findAllByMemberId(@Param(value = "memberId") Long memberId, Pageable pageable); | ||
long countByTemplate(Template template); | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/codezap/likes/repository/LikesQueryDslRepository.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,25 @@ | ||
package codezap.likes.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import codezap.likes.domain.QLikes; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class LikesQueryDslRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Modifying(clearAutomatically = true) | ||
public void deleteAllByTemplateIds(List<Long> templateIds) { | ||
jpaQueryFactory.delete(QLikes.likes) | ||
.where(QLikes.likes.template.id.in(templateIds)) | ||
.execute(); | ||
} | ||
} |
Oops, something went wrong.