Skip to content

Commit

Permalink
refactor: requiredarg lombok 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
geneaky committed Sep 18, 2024
1 parent 69b942e commit cbb6b48
Show file tree
Hide file tree
Showing 38 changed files with 655 additions and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import static toy.bookchat.bookchat.db_module.agony.QAgonyEntity.agonyEntity;
import static toy.bookchat.bookchat.db_module.bookshelf.QBookShelfEntity.bookShelfEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.support.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.support.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.support.RepositorySupport.toSlice;

import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -18,74 +18,74 @@
@Repository
public class AgonyQueryRepositoryImpl implements AgonyQueryRepository {

private final JPAQueryFactory queryFactory;
private final JPAQueryFactory queryFactory;

public AgonyQueryRepositoryImpl(JPAQueryFactory queryFactory) {
this.queryFactory = queryFactory;
}
public AgonyQueryRepositoryImpl(JPAQueryFactory queryFactory) {
this.queryFactory = queryFactory;
}

@Override
public Optional<AgonyEntity> findUserBookShelfAgony(Long bookShelfId, Long agonyId, Long userId) {
return Optional.ofNullable(
queryFactory.select(agonyEntity)
.from(agonyEntity)
.join(bookShelfEntity)
.on(bookShelfEntity.id.eq(agonyEntity.bookShelfId)
.and(bookShelfEntity.userId.eq(userId)))
.where(agonyEntity.id.eq(agonyId)
.and(agonyEntity.bookShelfId.eq(bookShelfId)))
.fetchOne());
}

@Override
public Slice<AgonyEntity> findUserBookShelfSliceOfAgonies(Long bookShelfId, Long userId,
Pageable pageable,
Long postCursorId) {
List<AgonyEntity> contents = queryFactory.select(agonyEntity)
@Override
public Optional<AgonyEntity> findUserBookShelfAgony(Long bookShelfId, Long agonyId, Long userId) {
return Optional.ofNullable(
queryFactory.select(agonyEntity)
.from(agonyEntity)
.join(bookShelfEntity)
.on(
agonyEntity.bookShelfId.eq(bookShelfEntity.id)
.and(bookShelfEntity.id.eq(bookShelfId))
.and(bookShelfEntity.userId.eq(userId))
)
.where(numberBasedPagination(agonyEntity, agonyEntity.id, postCursorId, pageable))
.limit(pageable.getPageSize())
.orderBy(extractOrderSpecifierFrom(agonyEntity, pageable))
.fetch();
.on(bookShelfEntity.id.eq(agonyEntity.bookShelfId)
.and(bookShelfEntity.userId.eq(userId)))
.where(agonyEntity.id.eq(agonyId)
.and(agonyEntity.bookShelfId.eq(bookShelfId)))
.fetchOne());
}

return toSlice(contents, pageable);
}
@Override
public Slice<AgonyEntity> findUserBookShelfSliceOfAgonies(Long bookShelfId, Long userId,
Pageable pageable,
Long postCursorId) {
List<AgonyEntity> contents = queryFactory.select(agonyEntity)
.from(agonyEntity)
.join(bookShelfEntity)
.on(
agonyEntity.bookShelfId.eq(bookShelfEntity.id)
.and(bookShelfEntity.id.eq(bookShelfId))
.and(bookShelfEntity.userId.eq(userId))
)
.where(numberBasedPagination(agonyEntity, agonyEntity.id, postCursorId, pageable))
.limit(pageable.getPageSize())
.orderBy(extractOrderSpecifierFrom(agonyEntity, pageable))
.fetch();

@Override
public void deleteByAgoniesIds(Long bookShelfId, Long userId, List<Long> agoniesIds) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
JPAExpressions.select(bookShelfEntity.id)
.from(bookShelfEntity)
.where(bookShelfEntity.userId.eq(userId))),
agonyEntity.id.in(agoniesIds)
).execute();
}
return toSlice(contents, pageable);
}

@Override
public void deleteAllByUserId(Long userId) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
@Override
public void deleteByAgoniesIds(Long bookShelfId, Long userId, List<Long> agoniesIds) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
JPAExpressions.select(bookShelfEntity.id)
.from(bookShelfEntity)
.where(bookShelfEntity.userId.eq(userId))
)).execute();
}
.where(bookShelfEntity.userId.eq(userId))),
agonyEntity.id.in(agoniesIds)
).execute();
}

@Override
public void deleteByBookShelfIdAndUserId(Long bookShelfId, Long userId) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
JPAExpressions.select(bookShelfEntity.id)
.from(bookShelfEntity)
.where(bookShelfEntity.id.eq(bookShelfId)
.and(bookShelfEntity.userId.eq(userId)))
)).execute();
}
@Override
public void deleteAllByUserId(Long userId) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
JPAExpressions.select(bookShelfEntity.id)
.from(bookShelfEntity)
.where(bookShelfEntity.userId.eq(userId))
)).execute();
}

@Override
public void deleteByBookShelfIdAndUserId(Long bookShelfId, Long userId) {
queryFactory.delete(agonyEntity)
.where(agonyEntity.bookShelfId.in(
JPAExpressions.select(bookShelfEntity.id)
.from(bookShelfEntity)
.where(bookShelfEntity.id.eq(bookShelfId)
.and(bookShelfEntity.userId.eq(userId)))
)).execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import static toy.bookchat.bookchat.db_module.agony.QAgonyEntity.agonyEntity;
import static toy.bookchat.bookchat.db_module.agonyrecord.QAgonyRecordEntity.agonyRecordEntity;
import static toy.bookchat.bookchat.db_module.bookshelf.QBookShelfEntity.bookShelfEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.support.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.support.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.support.RepositorySupport.toSlice;

import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static toy.bookchat.bookchat.db_module.book.QBookEntity.bookEntity;
import static toy.bookchat.bookchat.db_module.bookshelf.QBookShelfEntity.bookShelfEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.support.RepositorySupport.extractOrderSpecifierFrom;

import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import static toy.bookchat.bookchat.db_module.chat.QChatEntity.chatEntity;
import static toy.bookchat.bookchat.db_module.participant.QParticipantEntity.participantEntity;
import static toy.bookchat.bookchat.db_module.user.QUserEntity.userEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.support.RepositorySupport.extractOrderSpecifierFrom;
import static toy.bookchat.bookchat.support.RepositorySupport.numberBasedPagination;
import static toy.bookchat.bookchat.support.RepositorySupport.toSlice;

import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -18,37 +18,37 @@
@Repository
public class ChatQueryRepositoryImpl implements ChatQueryRepository {

private final JPAQueryFactory queryFactory;
private final JPAQueryFactory queryFactory;

public ChatQueryRepositoryImpl(JPAQueryFactory queryFactory) {
this.queryFactory = queryFactory;
}
public ChatQueryRepositoryImpl(JPAQueryFactory queryFactory) {
this.queryFactory = queryFactory;
}

@Override
public Slice<ChatEntity> getChatRoomChats(Long roomId, Long postCursorId, Pageable pageable, Long userId) {
return toSlice(queryFactory.select(chatEntity)
.from(chatEntity)
.where(chatEntity.chatRoomId.eq(JPAExpressions.select(participantEntity.chatRoomId)
.from(participantEntity)
.where(participantEntity.userId.eq(userId)
.and(participantEntity.chatRoomId.eq(roomId)))),
numberBasedPagination(chatEntity, chatEntity.id, postCursorId, pageable)
)
.limit(pageable.getPageSize())
.orderBy(extractOrderSpecifierFrom(chatEntity, pageable)).fetch(), pageable);
}
@Override
public Slice<ChatEntity> getChatRoomChats(Long roomId, Long postCursorId, Pageable pageable, Long userId) {
return toSlice(queryFactory.select(chatEntity)
.from(chatEntity)
.where(chatEntity.chatRoomId.eq(JPAExpressions.select(participantEntity.chatRoomId)
.from(participantEntity)
.where(participantEntity.userId.eq(userId)
.and(participantEntity.chatRoomId.eq(roomId)))),
numberBasedPagination(chatEntity, chatEntity.id, postCursorId, pageable)
)
.limit(pageable.getPageSize())
.orderBy(extractOrderSpecifierFrom(chatEntity, pageable)).fetch(), pageable);
}

@Override
public Optional<ChatEntity> getUserChatRoomChat(Long chatId, Long userId) {
return Optional.ofNullable(queryFactory.select(chatEntity)
.from(chatEntity)
.join(userEntity).on(chatEntity.userId.eq(userEntity.id))
.where(chatEntity.id.eq(chatId)
.and(chatEntity.chatRoomId.in(
JPAExpressions.select(participantEntity.chatRoomId)
.from(participantEntity)
.where(participantEntity.userId.eq(userId)))
))
.fetchOne());
}
@Override
public Optional<ChatEntity> getUserChatRoomChat(Long chatId, Long userId) {
return Optional.ofNullable(queryFactory.select(chatEntity)
.from(chatEntity)
.join(userEntity).on(chatEntity.userId.eq(userEntity.id))
.where(chatEntity.id.eq(chatId)
.and(chatEntity.chatRoomId.in(
JPAExpressions.select(participantEntity.chatRoomId)
.from(participantEntity)
.where(participantEntity.userId.eq(userId)))
))
.fetchOne());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static toy.bookchat.bookchat.db_module.chatroom.QHashTagEntity.hashTagEntity;
import static toy.bookchat.bookchat.db_module.participant.QParticipantEntity.participantEntity;
import static toy.bookchat.bookchat.db_module.user.QUserEntity.userEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.support.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.domain.participant.ParticipantStatus.HOST;

import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.data.domain.Slice;
import toy.bookchat.bookchat.domain.common.CursorMeta;
import toy.bookchat.bookchat.support.CursorMeta;

@Getter
@EqualsAndHashCode(of = "chatRoomResponseList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import lombok.Getter;
import org.springframework.data.domain.Slice;
import toy.bookchat.bookchat.domain.common.CursorMeta;
import toy.bookchat.bookchat.support.CursorMeta;

@Getter
public class UserChatRoomsResponseSlice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static toy.bookchat.bookchat.db_module.bookshelf.QBookShelfEntity.bookShelfEntity;
import static toy.bookchat.bookchat.db_module.scrap.QScrapEntity.scrapEntity;
import static toy.bookchat.bookchat.domain.common.RepositorySupport.toSlice;
import static toy.bookchat.bookchat.support.RepositorySupport.toSlice;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package toy.bookchat.bookchat.db_module.user;

import static javax.persistence.EnumType.STRING;
import static toy.bookchat.bookchat.domain.common.Status.INACTIVE;
import static toy.bookchat.bookchat.support.Status.INACTIVE;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -19,7 +19,7 @@
import lombok.Getter;
import org.hibernate.annotations.DynamicInsert;
import toy.bookchat.bookchat.db_module.BaseEntity;
import toy.bookchat.bookchat.domain.common.Status;
import toy.bookchat.bookchat.support.Status;
import toy.bookchat.bookchat.domain.user.ROLE;
import toy.bookchat.bookchat.domain.user.ReadingTaste;
import toy.bookchat.bookchat.security.oauth.OAuth2Provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import toy.bookchat.bookchat.db_module.user.UserEntity;
import toy.bookchat.bookchat.domain.common.Status;
import toy.bookchat.bookchat.support.Status;
import toy.bookchat.bookchat.security.oauth.OAuth2Provider;

public interface UserRepository extends JpaRepository<UserEntity, Long> {

Optional<UserEntity> findByNameAndStatus(String name, Status status);
Optional<UserEntity> findByNameAndStatus(String name, Status status);

Optional<UserEntity> findByName(String name);
Optional<UserEntity> findByName(String name);

Optional<UserEntity> findByEmailAndProvider(String email, OAuth2Provider provider);
Optional<UserEntity> findByEmailAndProvider(String email, OAuth2Provider provider);

boolean existsByNickname(String nickname);
boolean existsByNickname(String nickname);

Optional<UserEntity> findByIdAndStatus(Long userId, Status status);
Optional<UserEntity> findByIdAndStatus(Long userId, Status status);

List<UserEntity> findByIdIn(List<Long> userIds);
List<UserEntity> findByIdIn(List<Long> userIds);
}
Loading

0 comments on commit cbb6b48

Please sign in to comment.