Skip to content

Commit

Permalink
Refactor : 좋아요 및 싫어요 테이블 추가에 따른 CommentRepository 코드 수정
Browse files Browse the repository at this point in the history
검색한 사용자에 따라 좋아요 또는 싫어요를 한 기록을 보여준다.

Related:#57
Ref:#58
  • Loading branch information
hgh1472 committed Oct 2, 2024
1 parent b51e8d8 commit bffc30f
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,90 +1,98 @@
package core.application.movies.repositories;


import core.application.movies.models.entities.CommentEntity;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import core.application.movies.models.dto.CommentRespDTO;
import core.application.movies.models.entities.CommentEntity;

/**
* {@code COMMENT_TABLE} 과 관련된 {@code Repository}
*/
public interface CommentRepository {

// CREATE

/**
* 특정 영화에 주어진 유저 ID 로 새로운 한줄평 댓글을 DB 에 등록
*
* @param movieId 한줄평 댓글을 등록할 영화 ID
* @param userId 댓글을 등록하는 유저 ID
* @param comment 새로운 한줄평 댓글
* @return {@link CommentEntity} 등록된 정보
*/
CommentEntity saveNewComment(String movieId, UUID userId, CommentEntity comment);


//<editor-fold desc="READ">

/**
* 한줄평 댓글 ID 로 검색
*
* @param commentId 댓글 ID
* @return {@link Optional}{@code <}{@link CommentEntity}{@code >}
*/
Optional<CommentEntity> findByCommentId(Long commentId);

/**
* 특정 영화에 달린 한줄평 댓글들을 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
* @see #findByMovieIdOnDateDescend(String)
* @see #findByMovieIdOnLikeDescend(String)
* @see #findByMovieIdOnDislikeDescend(String)
*/
List<CommentEntity> findByMovieId(String movieId);

/**
* 특정 영화에 달린 한줄평 댓글을 최신순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentEntity> findByMovieIdOnDateDescend(String movieId);

/**
* 특정 영화에 달린 한줄평 댓글을 좋아요 순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentEntity> findByMovieIdOnLikeDescend(String movieId);

/**
* 특정 영화에 달린 한줄평 댓글을 싫어요 순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentEntity> findByMovieIdOnDislikeDescend(String movieId);

/**
* DB 의 모든 한줄평 댓글을 검색
*
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentEntity> selectAll();
//</editor-fold>


// DELETE

/**
* 특정 한줄평 댓글을 삭제
*
* @param commentId 삭제할 한줄평 댓글의 ID
*/
void deleteComment(Long commentId);
// CREATE

/**
* 특정 영화에 주어진 유저 ID 로 새로운 한줄평 댓글을 DB 에 등록
*
* @param movieId 한줄평 댓글을 등록할 영화 ID
* @param userId 댓글을 등록하는 유저 ID
* @param comment 새로운 한줄평 댓글
* @return {@link CommentEntity} 등록된 정보
*/
CommentEntity saveNewComment(String movieId, UUID userId, CommentEntity comment);

//<editor-fold desc="READ">

/**
* 한줄평 댓글 ID 로 검색
*
* @param commentId 댓글 ID
* @return {@link Optional}{@code <}{@link CommentEntity}{@code >}
*/
Optional<CommentEntity> findByCommentId(Long commentId);

Boolean existsByMovieIdAndUserId(String movieId, UUID userId);

/**
* 특정 영화에 달린 한줄평 댓글들을 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
* @see #findByMovieIdOnDateDescend(String, UUID, int)
* @see #findByMovieIdOnLikeDescend(String, UUID, int)
* @see #findByMovieIdOnDislikeDescend(String, UUID, int)
*/
List<CommentRespDTO> findByMovieId(String movieId, UUID userId, int offset);

/**
* 특정 영화에 달린 한줄평 댓글을 최신순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int offset);

/**
* 특정 영화에 달린 한줄평 댓글을 좋아요 순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int offset);

/**
* 특정 영화에 달린 한줄평 댓글을 싫어요 순으로 검색
*
* @param movieId 검색할 영화 ID
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int offset);

/**
* DB 의 모든 한줄평 댓글을 검색
*
* @return {@link List}{@code <}{@link CommentEntity}{@code >}
*/
List<CommentEntity> selectAll();
//</editor-fold>

// UPDATE

/**
* 한줄평 내용 수정
* @param comment 수정할 한줄평
*/
public void update(CommentEntity comment);

// DELETE

/**
* 특정 한줄평 댓글을 삭제
*
* @param commentId 삭제할 한줄평 댓글의 ID
*/
void deleteComment(Long commentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.springframework.stereotype.Repository;

import core.application.movies.models.dto.CommentRespDTO;
import core.application.movies.models.entities.CommentEntity;
import core.application.movies.repositories.mapper.CommentMapper;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,30 +29,40 @@ public Optional<CommentEntity> findByCommentId(Long commentId) {
}

@Override
public List<CommentEntity> findByMovieId(String movieId) {
return commentMapper.findByMovieId(movieId);
public Boolean existsByMovieIdAndUserId(String movieId, UUID userId) {
return commentMapper.findByMovieIdAndUserId(movieId, userId).isPresent();
}

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

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

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

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

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

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

@Override
public void deleteComment(Long commentId) {
commentMapper.delete(commentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.apache.ibatis.annotations.Mapper;

import core.application.movies.models.dto.CommentRespDTO;
import core.application.movies.models.entities.CommentEntity;

@Mapper
Expand All @@ -14,15 +15,19 @@ public interface CommentMapper {

Optional<CommentEntity> findByCommentId(Long commentId);

List<CommentEntity> findByMovieId(String movieId);
Optional<CommentEntity> findByMovieIdAndUserId(String movieId, UUID userId);

List<CommentEntity> findByMovieIdOnDateDescend(String movieId);
List<CommentRespDTO> findByMovieId(String movieId, UUID userId, int offset);

List<CommentEntity> findByMovieIdOnLikeDescend(String movieId);
List<CommentRespDTO> findByMovieIdOnDateDescend(String movieId, UUID userId, int offset);

List<CommentEntity> findByMovieIdOnDislikeDescend(String movieId);
List<CommentRespDTO> findByMovieIdOnLikeDescend(String movieId, UUID userId, int offset);

List<CommentRespDTO> findByMovieIdOnDislikeDescend(String movieId, UUID userId, int offset);

List<CommentEntity> selectAll();

void update(CommentEntity comment);

void delete(Long commentId);
}
Loading

0 comments on commit bffc30f

Please sign in to comment.