-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ BoardBlock 엔티티 구현 * ✨ 차단한 사용자의 게시글 조회 시 안보이게 구현 * ✨ 차단 해제 기능 구현(#150) * ✨ 전체 게시물 조회 & 내 게시물 전체 조회에서 likeCount, commentCount 적용되게 수정(#150) * ✨ 코드 최종 검사(#150) * ✨ 댓글 생성 쪽 수정완료(#150) * ✨ Controller에 내가 차단한 사용자 조회 제목 및 설명 추가(#150) * ✨ 특정 사용자의 게시글 조회 기능 수정 및 merge 전 코드 최종점검(#150) * ✨ 특정 사용자의 게시글 조회 기능 수정 및 merge 전 코드 최종점검(#150) * ✨ 특정 사용자의 게시글 조회 기능 수정 및 merge 전 코드 최종점검(#150)
- Loading branch information
1 parent
a577b5c
commit 11aec2f
Showing
16 changed files
with
317 additions
and
31 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/capstone/BnagFer/domain/board/dto/request/BoardBlockRequestDto.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,13 @@ | ||
package com.capstone.BnagFer.domain.board.dto.request; | ||
|
||
import com.capstone.BnagFer.domain.accounts.entity.User; | ||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
|
||
public record BoardBlockRequestDto() { | ||
public BoardBlock toEntity(User blockUser, User isBlockedUser) { | ||
return BoardBlock.builder() | ||
.blockUser(blockUser) | ||
.isBlockedUser(isBlockedUser) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/capstone/BnagFer/domain/board/dto/response/BoardBlockResponseDto.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,22 @@ | ||
package com.capstone.BnagFer.domain.board.dto.response; | ||
|
||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDateTime; | ||
@Builder | ||
public record BoardBlockResponseDto( | ||
Long id, | ||
Long blockUser, | ||
Long isBlockedUser, | ||
LocalDateTime blockedAt | ||
) { | ||
public static BoardBlockResponseDto from(BoardBlock boardBlock) { | ||
return BoardBlockResponseDto.builder() | ||
.id(boardBlock.getId()) | ||
.blockUser(boardBlock.getBlockUser().getId()) | ||
.isBlockedUser(boardBlock.getIsBlockedUser().getId()) | ||
.blockedAt(boardBlock.getBlockedAt()) | ||
.build(); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/capstone/BnagFer/domain/board/dto/response/GetMyBoardBlockResponseDto.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,22 @@ | ||
package com.capstone.BnagFer.domain.board.dto.response; | ||
|
||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDateTime; | ||
@Builder | ||
public record GetMyBoardBlockResponseDto( | ||
Long id, | ||
Long isBlockedUser, | ||
String nickName, | ||
LocalDateTime blockedAt | ||
) { | ||
public static GetMyBoardBlockResponseDto from(BoardBlock boardBlock) { | ||
return GetMyBoardBlockResponseDto.builder() | ||
.id(boardBlock.getId()) | ||
.isBlockedUser(boardBlock.getIsBlockedUser().getId()) | ||
.nickName(boardBlock.getIsBlockedUser().getProfile().getNickname()) | ||
.blockedAt(boardBlock.getBlockedAt()) | ||
.build(); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/capstone/BnagFer/domain/board/entity/BoardBlock.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,30 @@ | ||
package com.capstone.BnagFer.domain.board.entity; | ||
|
||
import com.capstone.BnagFer.domain.accounts.entity.User; | ||
import com.capstone.BnagFer.global.common.BaseEntity; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import java.time.LocalDateTime; | ||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Table(name = "board_block") | ||
public class BoardBlock extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "board_block_id", nullable = false) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "block_user_id") | ||
private User blockUser; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "is_blocked_user_id") | ||
private User isBlockedUser; | ||
|
||
@Column(name = "blocked_at") | ||
private LocalDateTime blockedAt; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/capstone/BnagFer/domain/board/repository/BoardBlockRepository.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,19 @@ | ||
package com.capstone.BnagFer.domain.board.repository; | ||
|
||
import com.capstone.BnagFer.domain.accounts.entity.User; | ||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
public interface BoardBlockRepository extends JpaRepository<BoardBlock, Long> { | ||
boolean existsByBlockUserAndIsBlockedUser(User blockUser, User isBlockedUser); | ||
|
||
void deleteByBlockUserAndIsBlockedUser(User blockUser, User isBlockedUser); | ||
|
||
List<BoardBlock> findByBlockUser(User blockUser); | ||
|
||
@Query("SELECT b.isBlockedUser.id FROM BoardBlock b WHERE b.blockUser.id = :blockUserId") | ||
List<Long> findIsBlockUserIdsByBlockUserId(Long blockUserId); | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/capstone/BnagFer/domain/board/service/BoardBlockQueryService.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,26 @@ | ||
package com.capstone.BnagFer.domain.board.service; | ||
|
||
import com.capstone.BnagFer.domain.accounts.entity.User; | ||
import com.capstone.BnagFer.domain.board.dto.response.GetMyBoardBlockResponseDto; | ||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
import com.capstone.BnagFer.domain.board.repository.BoardBlockRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class BoardBlockQueryService { | ||
private final BoardBlockRepository boardBlockRepository; | ||
public List<GetMyBoardBlockResponseDto> getBlockedUsers(User user) { | ||
List<BoardBlock> blockedUsers = boardBlockRepository.findByBlockUser(user); | ||
return blockedUsers.stream() | ||
.map(GetMyBoardBlockResponseDto::from) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/capstone/BnagFer/domain/board/service/BoardBlockService.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,47 @@ | ||
package com.capstone.BnagFer.domain.board.service; | ||
|
||
import com.capstone.BnagFer.domain.accounts.entity.User; | ||
import com.capstone.BnagFer.domain.accounts.repository.UserJpaRepository; | ||
import com.capstone.BnagFer.domain.board.dto.request.BoardBlockRequestDto; | ||
import com.capstone.BnagFer.domain.board.dto.response.BoardBlockResponseDto; | ||
import com.capstone.BnagFer.domain.board.entity.BoardBlock; | ||
import com.capstone.BnagFer.domain.board.exception.BoardExceptionHandler; | ||
import com.capstone.BnagFer.domain.board.repository.BoardBlockRepository; | ||
import com.capstone.BnagFer.global.common.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class BoardBlockService { | ||
private final BoardBlockRepository boardBlockRepository; | ||
private final UserJpaRepository userRepository; | ||
|
||
public BoardBlockResponseDto blockUser(User blockUser, Long isBlockedUserId) { | ||
User blockedUser = userRepository.findById(isBlockedUserId) | ||
.orElseThrow(() -> new BoardExceptionHandler(ErrorCode.USER_NOT_FOUND)); | ||
if (blockUser.getId().equals(isBlockedUserId)) { | ||
throw new BoardExceptionHandler(ErrorCode.CANNOT_REPORT_YOURSELF); | ||
} | ||
if(boardBlockRepository.existsByBlockUserAndIsBlockedUser(blockUser, blockedUser)){ | ||
throw new BoardExceptionHandler(ErrorCode.ALREADY_BLOCKED); | ||
} | ||
BoardBlockRequestDto request = new BoardBlockRequestDto(); | ||
BoardBlock boardBlock = request.toEntity(blockUser, blockedUser); | ||
boardBlockRepository.save(boardBlock); | ||
return BoardBlockResponseDto.from(boardBlock); | ||
} | ||
|
||
public void unblockUser(User blockUser, Long isBlockedUserId) { | ||
User blockedUser = userRepository.findById(isBlockedUserId) | ||
.orElseThrow(() -> new BoardExceptionHandler(ErrorCode.USER_NOT_FOUND)); | ||
if (blockUser.getId().equals(isBlockedUserId)) { | ||
throw new BoardExceptionHandler(ErrorCode.CANNOT_UNBLOCK_YOURSELF); | ||
} | ||
boardBlockRepository.deleteByBlockUserAndIsBlockedUser(blockUser, blockedUser); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.