-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PC-383] 어드민 차단 데이터 조회 기능 #28
Merged
Lujaec
merged 16 commits into
feature/PC-384-admin-read-report
from
feature/PC-383-admin-read-block
Jan 25, 2025
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0fc3306
[PC-383] fix: 연락처 기반 차단 네이밍 수정 (Block -> BlockContact)
Lujaec 3a500dc
[PC-383] feat: 차단 데이터 조회 기능
Lujaec 42cdd4f
[PC-383] feat: 차단 더미 데이터 추가
Lujaec c62fb0b
[PC-382] fix: RoleStatus 패키지 위치 변경
Lujaec bec3149
[PC-382] fix: ManyToOne 관계로 수정
Lujaec 986e182
[PC-382] fix: response 변수 이름 수정 (reason -> reject)
Lujaec ff5eb50
[PC-382] feat: 관리자 유저 프로필 상태 수정 기능
Lujaec 1ec6d93
[PC-382] feat: 관리자 유저 프로필 상태 수정 기능
Lujaec fadde4f
[PC-382] feat: 리젝 하는 경우 멤버 상태 PENDING으로 수정
Lujaec aee284c
[PC-379] fix: auth 모듈 분리
Lujaec af3bfa2
[PC-379] feat: admin 모듈 oauthId 기반 조회 기능
Lujaec 13edacc
[PC-379] feat: admin 모듈 jwt 필터 적용
Lujaec da942bc
[PC-379] feat: admin 모듈 로그인 기능
Lujaec d5decee
[PC-379] chore: 누락 파일
Lujaec 50629e7
Merge pull request #34 from YAPP-Github/feature/PC-379-admin-sign-in
Lujaec 04f7819
Merge pull request #33 from YAPP-Github/feature/PC-382-admin-update-m…
Lujaec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
admin/src/main/java/org/yapp/block/application/UserBlockService.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,53 @@ | ||
package org.yapp.block.application; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
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.Service; | ||
import org.yapp.block.dao.UserBlockRepository; | ||
import org.yapp.block.presentation.response.UserBlockResponse; | ||
import org.yapp.domain.block.UserBlock; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.util.PageResponse; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserBlockService { | ||
|
||
private final UserBlockRepository userBlockRepository; | ||
|
||
public PageResponse<UserBlockResponse> getUserBlockPageResponse(int page, int size) { | ||
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); | ||
|
||
Page<UserBlock> userBlockPage = userBlockRepository.findAll(pageable); | ||
|
||
List<UserBlockResponse> content = userBlockPage.getContent().stream() | ||
.map(userBlock -> { | ||
User blockingUser = userBlock.getBlockingUser(); | ||
User blockedUser = userBlock.getBlockedUser(); | ||
|
||
return new UserBlockResponse( | ||
blockedUser.getId(), | ||
blockedUser.getProfile().getProfileBasic().getNickname(), | ||
blockedUser.getName(), | ||
blockedUser.getProfile().getProfileBasic().getBirthdate(), | ||
blockingUser.getId(), | ||
blockingUser.getProfile().getProfileBasic().getNickname(), | ||
blockingUser.getName(), | ||
userBlock.getCreatedAt().toLocalDate()); | ||
}).toList(); | ||
|
||
return new PageResponse<>( | ||
content, | ||
userBlockPage.getNumber(), | ||
userBlockPage.getSize(), | ||
userBlockPage.getTotalPages(), | ||
userBlockPage.getTotalElements(), | ||
userBlockPage.isFirst(), | ||
userBlockPage.isLast() | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
admin/src/main/java/org/yapp/block/dao/UserBlockRepository.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,10 @@ | ||
package org.yapp.block.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.yapp.domain.block.UserBlock; | ||
|
||
@Repository | ||
public interface UserBlockRepository extends JpaRepository<UserBlock, Long> { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
admin/src/main/java/org/yapp/block/presentation/UserBlockController.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,31 @@ | ||
package org.yapp.block.presentation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.yapp.block.application.UserBlockService; | ||
import org.yapp.block.presentation.response.UserBlockResponse; | ||
import org.yapp.util.CommonResponse; | ||
import org.yapp.util.PageResponse; | ||
|
||
@RestController() | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/v1/blocks") | ||
public class UserBlockController { | ||
|
||
private final UserBlockService userBlockService; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<CommonResponse<PageResponse<UserBlockResponse>>> getUsers( | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "10") int size) { | ||
|
||
PageResponse<UserBlockResponse> userBlockPageResponse = userBlockService.getUserBlockPageResponse( | ||
page, size); | ||
|
||
return ResponseEntity.ok(CommonResponse.createSuccess(userBlockPageResponse)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
admin/src/main/java/org/yapp/block/presentation/response/UserBlockResponse.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,12 @@ | ||
package org.yapp.block.presentation.response; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record UserBlockResponse( | ||
Long blockedUserId, | ||
String BlockedUserNickname, String BlockedUserName, | ||
LocalDate blockedUserBirthdate, Long blockingUserId, | ||
String blockingUserNickname, | ||
String blockingUserName, LocalDate BlockedDate) { | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
api/src/main/java/org/yapp/domain/block/application/BlockContactService.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,49 @@ | ||
package org.yapp.domain.block.application; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.yapp.domain.block.BlockContact; | ||
import org.yapp.domain.block.application.dto.BlockContactCreateDto; | ||
import org.yapp.domain.block.dao.BlockContactRepository; | ||
import org.yapp.domain.user.User; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BlockContactService { | ||
|
||
private final BlockContactRepository blockContactRepository; | ||
|
||
@Transactional() | ||
public void blockPhoneNumbers(BlockContactCreateDto blockContactCreateDto) { | ||
Long userId = blockContactCreateDto.userId(); | ||
List<String> phoneNumbers = blockContactCreateDto.phoneNumbers(); | ||
List<BlockContact> newBlockContacts = new ArrayList<>(); | ||
|
||
Set<String> blockedPhoneNumbers = blockContactRepository.findBlocksByUserId(userId) | ||
.stream() | ||
.map(BlockContact::getPhoneNumber) | ||
.collect(Collectors.toSet()); | ||
|
||
phoneNumbers.stream() | ||
.filter(phoneNumber -> !blockedPhoneNumbers.contains(phoneNumber)) | ||
.forEach(phoneNumber -> { | ||
BlockContact blockContact = BlockContact.builder() | ||
.user(User.builder().id(userId).build()) | ||
.phoneNumber(phoneNumber) | ||
.build(); | ||
newBlockContacts.add(blockContact); | ||
}); | ||
|
||
blockContactRepository.saveAll(newBlockContacts); | ||
} | ||
|
||
@Transactional(readOnly = false) | ||
public List<BlockContact> findBlocksByUserId(Long userId) { | ||
return blockContactRepository.findBlocksByUserId(userId); | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
api/src/main/java/org/yapp/domain/block/application/BlockService.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
api/src/main/java/org/yapp/domain/block/application/dto/BlockContactCreateDto.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 org.yapp.domain.block.application.dto; | ||
|
||
import java.util.List; | ||
|
||
public record BlockContactCreateDto(Long userId, List<String> phoneNumbers) { | ||
|
||
public BlockContactCreateDto(Long userId, List<String> phoneNumbers) { | ||
this.userId = userId; | ||
this.phoneNumbers = phoneNumbers.stream() | ||
.map(phone -> phone.replaceAll("-", "")) | ||
.toList(); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
api/src/main/java/org/yapp/domain/block/application/dto/BlockCreateDto.java
This file was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
...app/domain/block/dao/BlockRepository.java → ...ain/block/dao/BlockContactRepository.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,12 +1,12 @@ | ||
package org.yapp.domain.block.dao; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.yapp.domain.block.Block; | ||
|
||
import java.util.List; | ||
import org.yapp.domain.block.BlockContact; | ||
|
||
@Repository | ||
public interface BlockRepository extends JpaRepository<Block, Long> { | ||
List<Block> findBlocksByUserId(Long userId); | ||
public interface BlockContactRepository extends JpaRepository<BlockContact, Long> { | ||
|
||
List<BlockContact> findBlocksByUserId(Long userId); | ||
} |
52 changes: 52 additions & 0 deletions
52
api/src/main/java/org/yapp/domain/block/presentation/BlockContactController.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,52 @@ | ||
package org.yapp.domain.block.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.yapp.domain.block.BlockContact; | ||
import org.yapp.domain.block.application.BlockContactService; | ||
import org.yapp.domain.block.application.dto.BlockContactCreateDto; | ||
import org.yapp.domain.block.presentation.dto.request.BlockPhoneNumbersRequest; | ||
import org.yapp.domain.block.presentation.dto.response.UserBlockContactResponses; | ||
import org.yapp.util.CommonResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/blockContacts") | ||
public class BlockContactController { | ||
|
||
private final BlockContactService blockContactService; | ||
|
||
@PostMapping("") | ||
@Operation(summary = "핸드폰 번호 차단", description = "핸드폰 번호 리스트를 전달받고, 전달받은 핸드폰 번호 차단을 수행합니다.", tags = { | ||
"차단"}) | ||
@ApiResponse(responseCode = "200", description = "핸드폰 차단 성공") | ||
public ResponseEntity<CommonResponse<Void>> blockPhoneNumbers( | ||
@AuthenticationPrincipal Long userId, @RequestBody BlockPhoneNumbersRequest request) { | ||
blockContactService.blockPhoneNumbers( | ||
new BlockContactCreateDto(userId, request.phoneNumbers())); | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(CommonResponse.createSuccessWithNoContent("핸드폰 번호 차단 성공")); | ||
} | ||
|
||
@GetMapping("") | ||
@Operation(summary = "핸드폰 번호 차단", description = "핸드폰 번호 리스트를 전달받고, 전달받은 핸드폰 번호 차단을 수행합니다.", tags = { | ||
"차단"}) | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 swagger 명세가 좀 이상한 것 같습니다. |
||
@ApiResponse(responseCode = "200", description = "핸드폰 차단 성공") | ||
public ResponseEntity<CommonResponse<UserBlockContactResponses>> blockPhoneNumbers( | ||
@AuthenticationPrincipal Long userId) { | ||
List<BlockContact> blockContacts = blockContactService.findBlocksByUserId(userId); | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(CommonResponse.createSuccess(UserBlockContactResponses.from(userId, | ||
blockContacts))); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
api/src/main/java/org/yapp/domain/block/presentation/BlockController.java
This file was deleted.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
.../main/java/org/yapp/domain/block/presentation/dto/response/UserBlockContactResponses.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,20 @@ | ||
package org.yapp.domain.block.presentation.dto.response; | ||
|
||
import java.util.List; | ||
import org.yapp.domain.block.BlockContact; | ||
|
||
public record UserBlockContactResponses(Long userId, | ||
List<BlockContactResponse> blockContactResponses) { | ||
|
||
public static UserBlockContactResponses from(Long userId, List<BlockContact> blockContacts) { | ||
List<BlockContactResponse> blockContactResponses = blockContacts.stream().map( | ||
blockContact -> new BlockContactResponse(blockContact.getPhoneNumber(), | ||
blockContact.getCreatedAt())).toList(); | ||
|
||
return new UserBlockContactResponses( | ||
userId, | ||
blockContactResponses | ||
); | ||
} | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
api/src/main/java/org/yapp/domain/block/presentation/dto/response/UserBlockResponses.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이름 명확해서 좋은 것 같습니다👍