Skip to content
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-273] 매칭 상대 차단 기능 구현 #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<DirectBlock, Long> {

boolean existsDirectBlockByBlockingUserIdAndBlockedUserId(Long blockingUserId,
Long blockedUserId);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +27,7 @@
public class MatchController {

private final MatchService matchService;
private final DirectBlockService directBlockService;

@GetMapping("/infos")
@Operation(summary = "매칭 정보 조회", description = "이번 매칭의 정보를 조회합니다.", tags = {"매칭"})
Expand Down Expand Up @@ -82,9 +85,18 @@ public ResponseEntity<CommonResponse<Void>> acceptMatch() {
}

@GetMapping("/contacts")
@Operation(summary = "매칭 상대 연락처 조회", description = "매칭 상대의 연락처를 조회합니다", tags = {"매칭"})
public ResponseEntity<CommonResponse<ContactResponse>> getContacts() {
Map<String, String> 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<CommonResponse<Void>> blockUsers(
@PathVariable(name = "userId") Long userId) {
directBlockService.blockUser(userId);
return ResponseEntity.status(HttpStatus.OK).body(CommonResponse.createSuccessWithNoContent());
}
}
31 changes: 31 additions & 0 deletions common/src/main/java/org/yapp/domain/block/DirectBlock.java
Original file line number Diff line number Diff line change
@@ -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;
}
}