Skip to content

Commit

Permalink
Merge pull request #53 from YAPP-Github/feature/PC-579-match-refuse
Browse files Browse the repository at this point in the history
[PC-579] 매칭 거절 기능 구현
  • Loading branch information
devchlee12 authored Feb 15, 2025
2 parents 5b779dd + 75f65b8 commit 0bc6e32
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.yapp.core.auth.AuthenticationService;
import org.yapp.core.domain.match.MatchInfo;
import org.yapp.core.domain.match.enums.MatchStatus;
import org.yapp.core.domain.match.enums.UserMatchStatus;
import org.yapp.core.domain.profile.ContactType;
import org.yapp.core.domain.profile.Profile;
import org.yapp.core.domain.profile.ProfileBasic;
Expand Down Expand Up @@ -125,35 +126,30 @@ private User getMatchedUser(Long userId, MatchInfo matchInfo) {
}

private String getMatchStatus(Long userId, MatchInfo matchInfo) {
if (userId.equals(matchInfo.getUser1().getId())) {
if (!matchInfo.getUser1PieceChecked()) {
return MatchStatus.BEFORE_OPEN.getStatus();
}
if (matchInfo.getUser1Accepted() && matchInfo.getUser2Accepted()) {
return MatchStatus.MATCHED.getStatus();
}
if (matchInfo.getUser1Accepted()) {
return MatchStatus.RESPONDED.getStatus();
}
if (matchInfo.getUser2Accepted()) {
return MatchStatus.GREEN_LIGHT.getStatus();
}
return MatchStatus.WAITING.getStatus();
} else {
if (!matchInfo.getUser2PieceChecked()) {
return MatchStatus.BEFORE_OPEN.getStatus();
}
if (matchInfo.getUser1Accepted() && matchInfo.getUser2Accepted()) {
return MatchStatus.MATCHED.getStatus();
}
if (matchInfo.getUser2Accepted()) {
return MatchStatus.RESPONDED.getStatus();
}
if (matchInfo.getUser1Accepted()) {
return MatchStatus.GREEN_LIGHT.getStatus();
}
return MatchStatus.WAITING.getStatus();
boolean isUser1 = userId.equals(matchInfo.getUser1().getId());

UserMatchStatus userMatchStatus =
isUser1 ? matchInfo.getUser1MatchStatus() : matchInfo.getUser2MatchStatus();
UserMatchStatus otherMatchStatus =
isUser1 ? matchInfo.getUser2MatchStatus() : matchInfo.getUser1MatchStatus();

if (userMatchStatus == UserMatchStatus.UNCHECKED) {
return MatchStatus.BEFORE_OPEN.getStatus();
}
if (userMatchStatus == UserMatchStatus.REFUSED) {
return MatchStatus.REFUSED.getStatus();
}
if (userMatchStatus == UserMatchStatus.ACCEPTED
&& otherMatchStatus == UserMatchStatus.ACCEPTED) {
return MatchStatus.MATCHED.getStatus();
}
if (userMatchStatus == UserMatchStatus.ACCEPTED) {
return MatchStatus.RESPONDED.getStatus();
}
if (otherMatchStatus == UserMatchStatus.ACCEPTED) {
return MatchStatus.GREEN_LIGHT.getStatus();
}
return MatchStatus.WAITING.getStatus();
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -266,10 +262,17 @@ public void acceptMatch() {
public Map<ContactType, String> getContacts() {
Long userId = authenticationService.getUserId();
MatchInfo matchInfo = getMatchInfo(userId);
if (!matchInfo.getUser1Accepted() || !matchInfo.getUser2Accepted()) {
if (matchInfo.getUser1MatchStatus() != UserMatchStatus.ACCEPTED
|| matchInfo.getUser2MatchStatus() != UserMatchStatus.ACCEPTED) {
throw new ApplicationException(MatchErrorCode.MATCH_NOT_ACCEPTED);
}
User matchedUser = getMatchedUser(userId, matchInfo);
return matchedUser.getProfile().getProfileBasic().getContacts();
}

@Transactional
public void refuseMatch(Long userId) {
MatchInfo matchInfo = getMatchInfo(userId);
matchInfo.refusePiece(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yapp.core.domain.profile.ContactType;
Expand All @@ -29,83 +31,91 @@
@RequestMapping("/api/matches")
public class MatchController {

private final MatchService matchService;
private final DirectBlockService directBlockService;
private final MatchService matchService;
private final DirectBlockService directBlockService;

@GetMapping("/infos")
@Operation(summary = "매칭 정보 조회", description = "이번 매칭의 정보를 조회합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchInfoResponse>> getMatchInfo() {
MatchInfoResponse matchInfoResponse = matchService.getMatchInfoResponse();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchInfoResponse));
}
@GetMapping("/infos")
@Operation(summary = "매칭 정보 조회", description = "이번 매칭의 정보를 조회합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchInfoResponse>> getMatchInfo() {
MatchInfoResponse matchInfoResponse = matchService.getMatchInfoResponse();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchInfoResponse));
}

@PatchMapping("/pieces/check")
@Operation(summary = "매칭 조각 확인 체크", description = "이번 매칭의 조각을 확인했음을 서버에 알립니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<Void>> checkMatchPiece() {
matchService.checkPiece();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccessWithNoContent());
}
@PatchMapping("/pieces/check")
@Operation(summary = "매칭 조각 확인 체크", description = "이번 매칭의 조각을 확인했음을 서버에 알립니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<Void>> checkMatchPiece() {
matchService.checkPiece();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccessWithNoContent());
}

@GetMapping("/profiles/basic")
@Operation(summary = "매칭 프로필 기본정보 확인", description = "매칭 상대의 프로필 기본정보를 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchProfileBasicResponse>> getBasicMatchProfile() {
MatchProfileBasicResponse matchProfileBasic = matchService.getMatchProfileBasic();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchProfileBasic));
}
@GetMapping("/profiles/basic")
@Operation(summary = "매칭 프로필 기본정보 확인", description = "매칭 상대의 프로필 기본정보를 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchProfileBasicResponse>> getBasicMatchProfile() {
MatchProfileBasicResponse matchProfileBasic = matchService.getMatchProfileBasic();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchProfileBasic));
}

@GetMapping("/values/talks")
@Operation(summary = "매칭 상대 가치관 톡 확인", description = "매칭 상대의 가치관 톡을 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchValueTalkResponse>> getMatchTalkValues() {
MatchValueTalkResponse matchValueTalk = matchService.getMatchValueTalk();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchValueTalk));
}
@GetMapping("/values/talks")
@Operation(summary = "매칭 상대 가치관 톡 확인", description = "매칭 상대의 가치관 톡을 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchValueTalkResponse>> getMatchTalkValues() {
MatchValueTalkResponse matchValueTalk = matchService.getMatchValueTalk();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchValueTalk));
}


@GetMapping("/values/picks")
@Operation(summary = "매칭 상대 가치관 픽 확인", description = "매칭 상대의 가치관 픽을 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchValuePickResponse>> getMatchValuePicks() {
MatchValuePickResponse matchValuePickResponse = matchService.getMatchedUserValuePicks();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchValuePickResponse));
}
@GetMapping("/values/picks")
@Operation(summary = "매칭 상대 가치관 픽 확인", description = "매칭 상대의 가치관 픽을 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<MatchValuePickResponse>> getMatchValuePicks() {
MatchValuePickResponse matchValuePickResponse = matchService.getMatchedUserValuePicks();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(matchValuePickResponse));
}

@GetMapping("/images")
@Operation(summary = "매칭 상대 프로필 이미지 확인", description = "매칭 상대의 프로필 이미지를 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<ImageUrlResponse>> getMatchedUserImages() {
String matchedUserImageUrl = matchService.getMatchedUserImageUrl();
ImageUrlResponse imageUrlResponse = new ImageUrlResponse(matchedUserImageUrl);
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(imageUrlResponse));
}
@GetMapping("/images")
@Operation(summary = "매칭 상대 프로필 이미지 확인", description = "매칭 상대의 프로필 이미지를 확인합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<ImageUrlResponse>> getMatchedUserImages() {
String matchedUserImageUrl = matchService.getMatchedUserImageUrl();
ImageUrlResponse imageUrlResponse = new ImageUrlResponse(matchedUserImageUrl);
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(imageUrlResponse));
}

@PostMapping("/accept")
@Operation(summary = "매칭 수락하기", description = "매칭을 수락합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<Void>> acceptMatch() {
matchService.acceptMatch();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccessWithNoContent());
}
@PostMapping("/accept")
@Operation(summary = "매칭 수락하기", description = "매칭을 수락합니다.", tags = {"매칭"})
public ResponseEntity<CommonResponse<Void>> acceptMatch() {
matchService.acceptMatch();
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccessWithNoContent());
}

@GetMapping("/contacts")
@Operation(summary = "매칭 상대 연락처 조회", description = "매칭 상대의 연락처를 조회합니다", tags = {"매칭"})
public ResponseEntity<CommonResponse<ContactResponses>> getContacts() {
Map<ContactType, String> contacts = matchService.getContacts();
List<ContactResponse> contactsList = ContactResponses.convert(contacts);
ContactResponses contactResponses = new ContactResponses(contactsList);
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(contactResponses));
}
@GetMapping("/contacts")
@Operation(summary = "매칭 상대 연락처 조회", description = "매칭 상대의 연락처를 조회합니다", tags = {"매칭"})
public ResponseEntity<CommonResponse<ContactResponses>> getContacts() {
Map<ContactType, String> contacts = matchService.getContacts();
List<ContactResponse> contactsList = ContactResponses.convert(contacts);
ContactResponses contactResponses = new ContactResponses(contactsList);
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccess(contactResponses));
}

@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());
}
@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());
}

@PutMapping("/refuse")
@Operation(summary = "매칭 거절", description = "매칭을 거절합니다", tags = {"매칭"})
public ResponseEntity<CommonResponse<Void>> refuseMatch(@AuthenticationPrincipal Long userId) {
matchService.refuseMatch(userId);
return ResponseEntity.status(HttpStatus.OK)
.body(CommonResponse.createSuccessWithNoContent());
}
}
2 changes: 2 additions & 0 deletions core/domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ repositories {
dependencies {
implementation('io.hypersistence:hypersistence-utils-hibernate-62:3.7.0')

implementation project(':core:exception')

testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'

Expand Down
93 changes: 54 additions & 39 deletions core/domain/src/main/java/org/yapp/core/domain/match/MatchInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -10,63 +12,76 @@
import java.time.LocalDate;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.yapp.core.domain.match.enums.UserMatchStatus;
import org.yapp.core.domain.user.User;
import org.yapp.core.exception.ApplicationException;
import org.yapp.core.exception.error.code.MatchErrorCode;

@Entity
@Getter
@NoArgsConstructor
public class MatchInfo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "date")
private LocalDate date;
@Column(name = "date")
private LocalDate date;

@ManyToOne
@JoinColumn(name = "user_1")
private User user1;
@ManyToOne
@JoinColumn(name = "user_1")
private User user1;

@Column(name = "user_1_piece_checked")
private Boolean user1PieceChecked = false;
@Column(name = "user_1_match_status")
@Enumerated(EnumType.STRING)
private UserMatchStatus user1MatchStatus = UserMatchStatus.UNCHECKED;

@Column(name = "user_1_accept")
private Boolean user1Accepted = false;
@ManyToOne
@JoinColumn(name = "user_2")
private User user2;

@ManyToOne
@JoinColumn(name = "user_2")
private User user2;
@Column(name = "user_2_match_status")
@Enumerated(EnumType.STRING)
private UserMatchStatus user2MatchStatus = UserMatchStatus.UNCHECKED;

@Column(name = "user_2_piece_checked")
private Boolean user2PieceChecked = false;
public MatchInfo(LocalDate date, User user1, User user2) {
this.date = date;
this.user1 = user1;
this.user2 = user2;
}

@Column(name = "user_2_accept")
private Boolean user2Accepted = false;
public static MatchInfo createMatchInfo(User user1, User user2) {
return new MatchInfo(LocalDate.now(), user1, user2);
}

public MatchInfo(LocalDate date, User user1, User user2) {
this.date = date;
this.user1 = user1;
this.user2 = user2;
public void checkPiece(Long userId) {
if (user1.getId().equals(userId)) {
user1MatchStatus = UserMatchStatus.CHECKED;
} else if (user2.getId().equals(userId)) {
user2MatchStatus = UserMatchStatus.CHECKED;
} else {
throw new ApplicationException(MatchErrorCode.INVALID_MATCH_ACCESS);
}
}

public static MatchInfo createMatchInfo(User user1, User user2) {
return new MatchInfo(LocalDate.now(), user1, user2);
public void acceptPiece(Long userId) {
if (user1.getId().equals(userId)) {
user1MatchStatus = UserMatchStatus.ACCEPTED;
} else if (user2.getId().equals(userId)) {
user2MatchStatus = UserMatchStatus.ACCEPTED;
} else {
throw new ApplicationException(MatchErrorCode.INVALID_MATCH_ACCESS);
}
}

public void checkPiece(Long userId) {
if (user1.getId().equals(userId)) {
user1PieceChecked = true;
} else {
user2PieceChecked = true;
}
}

public void acceptPiece(Long userId) {
if (user1.getId().equals(userId)) {
user1Accepted = true;
} else {
user2Accepted = true;
}
public void refusePiece(Long userId) {
if (user1.getId().equals(userId)) {
user1MatchStatus = UserMatchStatus.REFUSED;
} else if (user2.getId().equals(userId)) {
user2MatchStatus = UserMatchStatus.REFUSED;
} else {
throw new ApplicationException(MatchErrorCode.INVALID_MATCH_ACCESS);
}
}
}
Loading

0 comments on commit 0bc6e32

Please sign in to comment.