Skip to content

Commit

Permalink
refactor: 통합된 인터페이스의 기능 구현
Browse files Browse the repository at this point in the history
Related to: #139
Ref: #136
  • Loading branch information
hgh1472 committed Oct 21, 2024
1 parent 63fa9d2 commit fdbf2fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -35,27 +37,25 @@ public Boolean existsByMovieIdAndUserId(String movieId, UUID userId) {
}

@Override
public List<CommentRespDTO> findByMovieId(String movieId, UUID userId, int page) {
return List.of();
public Page<CommentRespDTO> findByMovieId(String movieId, UUID userId, int page) {
return jpaRepository.findByMovieId(movieId, userId, PageRequest.of(page, 10));
}

@Override
public List<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int page) {
return List.of();
}

@Override
public List<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int offset) {
return List.of();
public Page<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "createdAt"));
return jpaRepository.findByMovieIdOrderBy(movieId, userId, pageable);
}

@Override
public List<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int offset) {
return List.of();
public Page<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "like"));
return jpaRepository.findByMovieIdOrderBy(movieId, userId, pageable);
}

@Override
public Page<CommentRespDTO> findByMovieIdOrderBy(String movieId, UUID userId, Pageable pageable) {
public Page<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "dislike"));
return jpaRepository.findByMovieIdOrderBy(movieId, userId, pageable);
}

Expand All @@ -64,11 +64,6 @@ public List<CommentEntity> selectAll() {
return jpaRepository.findAll();
}

@Override
public long countByMovieId(String movieId) {
return 0;
}

@Override
public void update(CommentEntity comment) {
jpaRepository.save(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -39,40 +41,43 @@ public Boolean existsByMovieIdAndUserId(String movieId, UUID userId) {
}

@Override
public List<CommentRespDTO> findByMovieId(String movieId, UUID userId, int offset) {
return commentMapper.findByMovieId(movieId, userId, offset);
public Page<CommentRespDTO> findByMovieId(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10);
int total = commentMapper.countByMovieId(movieId);
List<CommentRespDTO> find = commentMapper.findByMovieId(movieId, userId, page * 10);
return new PageImpl<>(find, pageable, total);
}

@Override
public List<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int offset) {
return commentMapper.findByMovieIdOnDateDescend(movieId, userId, offset);
public Page<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10);
int total = commentMapper.countByMovieId(movieId);
List<CommentRespDTO> find = commentMapper.findByMovieIdOnDateDescend(movieId, userId, page * 10);
return new PageImpl<>(find, pageable, total);
}

@Override
public List<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int offset) {
return commentMapper.findByMovieIdOnLikeDescend(movieId, userId, offset);
public Page<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10);
int total = commentMapper.countByMovieId(movieId);
List<CommentRespDTO> find = commentMapper.findByMovieIdOnLikeDescend(movieId, userId, page * 10);
return new PageImpl<>(find, pageable, total);
}

@Override
public List<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int offset) {
return commentMapper.findByMovieIdOnDislikeDescend(movieId, userId, offset);
}

@Override
public Page<CommentRespDTO> findByMovieIdOrderBy(String movieId, UUID userId, Pageable pageable) {
return null;
public Page<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int page) {
Pageable pageable = PageRequest.of(page, 10);
int total = commentMapper.countByMovieId(movieId);
List<CommentRespDTO> find = commentMapper.findByMovieIdOnDislikeDescend(movieId, userId,
page * 10);
return new PageImpl<>(find, pageable, total);
}

@Override
public List<CommentEntity> selectAll() {
return commentMapper.selectAll();
}

@Override
public long countByMovieId(String movieId) {
return commentMapper.countByMovieId(movieId);
}

@Override
public void update(CommentEntity comment) {
commentMapper.update(comment);
Expand Down

0 comments on commit fdbf2fe

Please sign in to comment.