-
Notifications
You must be signed in to change notification settings - Fork 1
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
15 changed files
with
271 additions
and
48 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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/khumu/community/application/dto/BlockUserDto.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.khumu.community.application.dto; | ||
|
||
import lombok.*; | ||
import org.springframework.data.annotation.CreatedDate; | ||
|
||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class BlockUserDto { | ||
Long id; | ||
// 차단을 수행한 사람 | ||
String blocker; | ||
// 차단 당한 사람 | ||
SimpleUserDto blockee; | ||
// 차단 당한 사람의 정보를 익명으로 가려줄 것인지 | ||
Boolean isBlockeeAnonymous; | ||
// 차단한 이유 | ||
String reason; | ||
// 언제 차단한 것인지 | ||
LocalDateTime createdAt; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/khumu/community/application/dto/input/CreateBlockUserInput.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,15 @@ | ||
package com.khumu.community.application.dto.input; | ||
|
||
import lombok.*; | ||
|
||
// 게시글의 작성자를 차단한다. | ||
// 게시글이 익명 게시글이라면 차단 후 정보 제공 시 익명으로 정보를 제공하고 | ||
// 기명 게시글이라면 기명으로 정보 제공 | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class CreateBlockUserInput { | ||
Integer article; | ||
} |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/com/khumu/community/application/port/in/BlockService.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,4 +1,77 @@ | ||
package com.khumu.community.application.port.in; | ||
|
||
import com.khumu.community.application.dto.BlockUserDto; | ||
import com.khumu.community.application.dto.SimpleUserDto; | ||
import com.khumu.community.application.dto.input.CreateBlockUserInput; | ||
import com.khumu.community.application.entity.Article; | ||
import com.khumu.community.application.entity.BlockUser; | ||
import com.khumu.community.application.entity.User; | ||
import com.khumu.community.application.exception.ForbiddenException; | ||
import com.khumu.community.application.port.out.repository.ArticleRepository; | ||
import com.khumu.community.application.port.out.repository.BlockUserRepository; | ||
import com.khumu.community.application.port.out.repository.UserRepository; | ||
import com.khumu.community.common.mapper.BlockUserMapper; | ||
import com.khumu.community.common.mapper.UserMapper; | ||
import com.khumu.community.common.util.Util; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Slf4j | ||
public class BlockService { | ||
private final BlockUserRepository blockUserRepository; | ||
private final UserMapper userMapper; | ||
private final BlockUserMapper blockUserMapper; | ||
private final UserRepository userRepository; | ||
private final ArticleRepository articleRepository; | ||
|
||
public BlockUserDto blockUser(User requestUser, CreateBlockUserInput input) { | ||
Article article = articleRepository.findById(input.getArticle()).get(); | ||
if (requestUser.getUsername().equals(article.getAuthor().getUsername())) { | ||
throw new ForbiddenException("본인의 게시글을 바탕으로 작성자(본인)를 차단할 수 없습니다."); | ||
} | ||
|
||
BlockUser block = blockUserRepository.save(BlockUser.builder() | ||
.blocker(requestUser.getUsername()) | ||
.blockee(article.getAuthor().getUsername()) | ||
.isBlockeeAnonymous(article.getKind().equals("anonymous")) | ||
.reason("게시글 \"" + Util.getShortString(article.getTitle(), 16) + "\" 의 작성자를 차단했습니다.") | ||
.build()); | ||
|
||
|
||
return map(block); | ||
} | ||
|
||
public Page<BlockUserDto> listMyBlocks(User requestUser, Pageable pageable) { | ||
Page<BlockUser> blocks = blockUserRepository.findAllByBlocker(requestUser.getUsername(), pageable); | ||
return blocks.map(this::map); | ||
} | ||
|
||
public void unblockUser(User requestUser, Long blockId) { | ||
BlockUser block = blockUserRepository.findById(blockId).get(); | ||
// 본인이 신고자가 아닌 경우 | ||
if (!requestUser.getUsername().equals(block.getBlocker())) { | ||
throw new ForbiddenException("본인의 차단 내역만 해제할 수 있습니다."); | ||
} | ||
|
||
blockUserRepository.delete(block); | ||
} | ||
|
||
private BlockUserDto map(BlockUser block) { | ||
BlockUserDto dto = blockUserMapper.toDto(block); | ||
if (dto.getIsBlockeeAnonymous()) { | ||
dto.setBlockee(SimpleUserDto.builder().username("anonymous").nickname("익명").status("anonymous").build()); | ||
} else{ | ||
User user = userRepository.findById(block.getBlockee()).get(); | ||
userMapper.toSimpleDto(user); | ||
} | ||
|
||
return dto; | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.