Skip to content

Commit

Permalink
Merge pull request #166 from swm-nodriversomabus/BUS-207-Pending-list…
Browse files Browse the repository at this point in the history
…-display-bug

hotfix(BE): 매칭 신청 수락/거절 시 반영 안됨 BUS-207-Pending-list-display-bug #165
  • Loading branch information
Lemonade255 authored Oct 30, 2023
2 parents e7569e0 + d557647 commit 3e7138f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ErrorCodeEnum {
CODE_IS_NOT_VALID(HttpStatus.BAD_REQUEST, "잘못된 인증번호입니다"),
MATCHING_NOT_FOUND(HttpStatus.BAD_REQUEST, "매칭 정보가 없습니다"),
PREFERENCE_NOT_FOUND(HttpStatus.BAD_REQUEST, "선호도 정보가 없습니다"),
APPLICATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "신청 정보가 없습니다"),
// 401 Unauthorized
LOGIN_IS_NOT_DONE(HttpStatus.UNAUTHORIZED, "로그인 정보가 없습니다"),
// 403 Forbidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,7 @@ public void toggleLike(@RequestBody LikeDto likeDto) {
@Operation(summary = "Process matching application", description = "매칭 신청을 처리한다.")
@PutMapping("/matching/application")
public void processMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
if (matchingApplicationDto.getState() == ApplicationStateEnum.Approved) {
matchingApplicationUsecase.approveMatchingApplication(matchingApplicationDto);
}
if (matchingApplicationDto.getState() == ApplicationStateEnum.Declined) {
matchingApplicationUsecase.declineMatchingApplication(matchingApplicationDto);
}
matchingApplicationUsecase.processMatchingApplication(matchingApplicationDto);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class MatchingApplicationPersistenceAdapter implements MatchingApplicatio
private final MatchingApplicationRepository matchingApplicationRepository;

@Override
public MatchingApplication createMatchingApplication(MatchingApplication matchingApplication) {
log.info(matchingMapper.toEntity(matchingApplication).toString());
public MatchingApplication saveMatchingApplication(MatchingApplication matchingApplication) {
MatchingApplicationEntity matchingApplicationData = matchingApplicationRepository.save(matchingMapper.toEntity(matchingApplication));
return matchingMapper.toDomain(matchingApplicationData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public interface MatchingApplicationUsecase {
List<FindMatchingDto> getByUserIdIsAndStateEquals(UUID userId, ApplicationStateEnum state);
List<FindUserInfoDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
String getUserStatus(UUID userId, Long matchingId);
void approveMatchingApplication(SaveMatchingApplicationDto matchingApplicationPK);
void declineMatchingApplication(SaveMatchingApplicationDto matchingApplicationPK);
void processMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.UUID;

public interface MatchingApplicationPort {
MatchingApplication createMatchingApplication(MatchingApplication matchingApplication);
MatchingApplication saveMatchingApplication(MatchingApplication matchingApplication);
Optional<MatchingApplicationEntity> getByMatchingApplicationPK(MatchingApplicationPK matchingApplicationPK);
List<MatchingApplicationEntity> getByUserIdIsAndStateEquals(UUID userId, ApplicationStateEnum state);
List<MatchingApplicationEntity> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.api.matching.service;

import com.example.api.common.exception.CustomException;
import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.common.type.ErrorCodeEnum;
import com.example.api.fcm.dto.FcmDto;
import com.example.api.fcm.service.FcmService;
import com.example.api.matching.adapter.out.persistence.MatchingApplicationEntity;
Expand Down Expand Up @@ -49,7 +51,7 @@ public MatchingApplication createMatchingApplicationData(UUID userId, SaveMatchi
if (matchingApplication.getUserId() == null) {
matchingApplication.setUserId(userId);
}
return matchingApplicationPort.createMatchingApplication(matchingApplication);
return matchingApplicationPort.saveMatchingApplication(matchingApplication);
}

@Override
Expand Down Expand Up @@ -93,41 +95,27 @@ public String getUserStatus(UUID userId, Long matchingId) {
return "None";
}
}

@Override
@Transactional
public void approveMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(matchingApplicationDto.getUserId())
.matchingId(matchingApplicationDto.getMatchingId())
.build();
MatchingApplicationEntity matchingApplicationEntity = matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK)
.orElseThrow(NoSuchElementException::new);
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationEntity);
matchingApplication.setState(ApplicationStateEnum.Approved);
FcmDto fcmDto = FcmDto.builder()
.userId(matchingApplication.getUserId())
.title("신청 수락")
.body("매칭 신청이 수락되었어요!")
.build();
fcmService.sendNotification(fcmDto);
}


@Override
@Transactional
public void declineMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
public void processMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
ApplicationStateEnum state = matchingApplicationDto.getState();
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(matchingApplicationDto.getUserId())
.matchingId(matchingApplicationDto.getMatchingId())
.build();
MatchingApplicationEntity matchingApplicationEntity = matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK)
.orElseThrow(NoSuchElementException::new);
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationEntity);
matchingApplication.setState(ApplicationStateEnum.Declined);
Optional<MatchingApplicationEntity> matchingApplicationEntity = matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK);
if (matchingApplicationEntity.isEmpty()) {
log.error("MatchingApplicationService::processMatchingApplication: Data not found");
throw new CustomException(ErrorCodeEnum.APPLICATION_NOT_FOUND);
}
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationEntity.get());
matchingApplication.setState(state);
matchingApplicationPort.saveMatchingApplication(matchingApplication);
FcmDto fcmDto = FcmDto.builder()
.userId(matchingApplication.getUserId())
.title("신청 거절")
.body("매칭 신청이 거절되었어요.")
.title(state.equals(ApplicationStateEnum.Approved) ? "신청 수락" : "신청 거절")
.body(state.equals(ApplicationStateEnum.Approved) ? "매칭 신청이 수락되었어요!" : "매칭 신청이 거절되었어요.")
.build();
fcmService.sendNotification(fcmDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public FindPreferenceDto updatePreference(Long preferenceId, SavePreferenceDto p
public ComparePreferenceDto getUserPreference(UUID userId) {
Long preferenceId = comparePreferencePort.getUserPreferenceId(userId);
if (preferenceId == 0L) {
log.error("PreferenceService::getUserPreference: User preference data not found");
log.warn("PreferenceService::getUserPreference: User preference data not found");
return this.getDefaultPreference();
//throw new CustomException(ErrorCodeEnum.PREFERENCE_NOT_FOUND);
}
Optional<ComparePreferenceDto> preferenceDto = this.getByPreferenceId(preferenceId);
if (preferenceDto.isEmpty()) {
log.error("PreferenceService::getUserPreference: User preference data not found");
log.warn("PreferenceService::getUserPreference: User preference data not found");
return this.getDefaultPreference();
//throw new CustomException(ErrorCodeEnum.PREFERENCE_NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void beforeEach() {

@Test
void createMatchingApplicationTest() {
matchingApplicationPersistenceAdapter.createMatchingApplication(matchingApplication);
matchingApplicationPersistenceAdapter.saveMatchingApplication(matchingApplication);
verify(matchingApplicationRepository, times(1)).save(matchingMapper.toEntity(matchingApplication));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void beforeEach() {
}

@Test
void createMatchingApplicationTest() {
void saveMatchingApplicationTest() {
matchingApplicationService.createMatchingApplicationData(userId, matchingApplication);
verify(matchingApplicationPort, times(1)).createMatchingApplication(matchingMapper.toDomain(matchingApplication));
verify(matchingApplicationPort, times(1)).saveMatchingApplication(matchingMapper.toDomain(matchingApplication));
}

@Test
Expand Down

0 comments on commit 3e7138f

Please sign in to comment.