diff --git a/api/src/main/java/org/yapp/domain/block/application/DirectBlockService.java b/api/src/main/java/org/yapp/domain/block/application/DirectBlockService.java new file mode 100644 index 0000000..c017141 --- /dev/null +++ b/api/src/main/java/org/yapp/domain/block/application/DirectBlockService.java @@ -0,0 +1,26 @@ +package org.yapp.domain.block.application; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.yapp.application.AuthenticationService; +import org.yapp.domain.block.DirectBlock; +import org.yapp.domain.block.dao.DirectBlockRepository; + +@Service +@RequiredArgsConstructor +public class DirectBlockService { + + private final DirectBlockRepository directBlockRepository; + private final AuthenticationService authenticationService; + + public DirectBlock blockUser(Long blockId) { + Long userId = authenticationService.getUserId(); + return directBlockRepository.save(new DirectBlock(userId, blockId)); + } + + public boolean checkBlock(Long userId, Long partnerId) { + return directBlockRepository.existsDirectBlockByBlockingUserIdAndBlockedUserId(userId, + partnerId); + } + +} diff --git a/api/src/main/java/org/yapp/domain/block/dao/DirectBlockRepository.java b/api/src/main/java/org/yapp/domain/block/dao/DirectBlockRepository.java new file mode 100644 index 0000000..9935875 --- /dev/null +++ b/api/src/main/java/org/yapp/domain/block/dao/DirectBlockRepository.java @@ -0,0 +1,10 @@ +package org.yapp.domain.block.dao; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.yapp.domain.block.DirectBlock; + +public interface DirectBlockRepository extends JpaRepository { + + boolean existsDirectBlockByBlockingUserIdAndBlockedUserId(Long blockingUserId, + Long blockedUserId); +} diff --git a/api/src/main/java/org/yapp/domain/match/application/blocker/DirectBlockBasedBlocker.java b/api/src/main/java/org/yapp/domain/match/application/blocker/DirectBlockBasedBlocker.java index ccd8332..1e35930 100644 --- a/api/src/main/java/org/yapp/domain/match/application/blocker/DirectBlockBasedBlocker.java +++ b/api/src/main/java/org/yapp/domain/match/application/blocker/DirectBlockBasedBlocker.java @@ -1,8 +1,17 @@ package org.yapp.domain.match.application.blocker; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.yapp.domain.block.application.DirectBlockService; + +@Component +@RequiredArgsConstructor public class DirectBlockBasedBlocker implements Blocker { + + private final DirectBlockService directBlockService; + @Override public boolean blocked(Long blockingUserId, Long blockedUserId) { - return false; + return directBlockService.checkBlock(blockingUserId, blockedUserId); } } diff --git a/api/src/main/java/org/yapp/domain/match/presentation/MatchController.java b/api/src/main/java/org/yapp/domain/match/presentation/MatchController.java index 68bde73..27d9695 100644 --- a/api/src/main/java/org/yapp/domain/match/presentation/MatchController.java +++ b/api/src/main/java/org/yapp/domain/match/presentation/MatchController.java @@ -7,9 +7,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.yapp.domain.block.application.DirectBlockService; import org.yapp.domain.match.application.MatchService; import org.yapp.domain.match.presentation.dto.response.ContactResponse; import org.yapp.domain.match.presentation.dto.response.ImageUrlResponse; @@ -25,6 +27,7 @@ public class MatchController { private final MatchService matchService; + private final DirectBlockService directBlockService; @GetMapping("/infos") @Operation(summary = "매칭 정보 조회", description = "이번 매칭의 정보를 조회합니다.", tags = {"매칭"}) @@ -82,9 +85,18 @@ public ResponseEntity> acceptMatch() { } @GetMapping("/contacts") + @Operation(summary = "매칭 상대 연락처 조회", description = "매칭 상대의 연락처를 조회합니다", tags = {"매칭"}) public ResponseEntity> getContacts() { Map contacts = matchService.getContacts(); ContactResponse contactResponse = new ContactResponse(contacts); return ResponseEntity.status(HttpStatus.OK).body(CommonResponse.createSuccess(contactResponse)); } + + @PostMapping("/blocks/users/{userId}") + @Operation(summary = "매칭 상대 차단", description = "매칭 상대를 차단합니다", tags = {"매칭"}) + public ResponseEntity> blockUsers( + @PathVariable(name = "userId") Long userId) { + directBlockService.blockUser(userId); + return ResponseEntity.status(HttpStatus.OK).body(CommonResponse.createSuccessWithNoContent()); + } } diff --git a/common/src/main/java/org/yapp/domain/block/DirectBlock.java b/common/src/main/java/org/yapp/domain/block/DirectBlock.java new file mode 100644 index 0000000..34b4759 --- /dev/null +++ b/common/src/main/java/org/yapp/domain/block/DirectBlock.java @@ -0,0 +1,31 @@ +package org.yapp.domain.block; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor +@Getter +@Table(name = "direct_block") +public class DirectBlock { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + @Column(name = "blocking_user_id") + private Long blockingUserId; + @Column(name = "blocked_user_id") + private Long blockedUserId; + + public DirectBlock(Long blockingUserId, Long blockedUserId) { + this.blockingUserId = blockingUserId; + this.blockedUserId = blockedUserId; + } +}