Skip to content

Commit

Permalink
Merge pull request #219 from swm-nodriversomabus/BUS-209-MVP1-bugfix
Browse files Browse the repository at this point in the history
hotfix(BE): 추천 매칭 두번씩 뜨는 문제 BUS-209-MVP1-bugfix
  • Loading branch information
Lemonade255 authored Nov 16, 2023
2 parents 69d55d9 + fdde9c4 commit c0be306
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.example.api.blocklist.adapter.in.rest;


import com.example.api.auth.domain.SecurityUser;
import com.example.api.blocklist.application.port.in.AddBlockUseccase;
import com.example.api.blocklist.application.port.in.AddBlockUsecase;
import com.example.api.blocklist.application.port.in.ReleaseBlockUsecase;
import com.example.api.blocklist.application.port.in.GetListUsecase;
import com.example.api.blocklist.domain.BlockList;
import com.example.api.blocklist.dto.AddBlockDto;
import com.example.api.blocklist.dto.DeleteBlockDto;
import com.example.api.common.exception.CustomException;
Expand All @@ -29,24 +27,24 @@
@Slf4j
@Tag(name = "BlockList", description = "Blocklist API")
public class BlockListController {
private final AddBlockUseccase addBlockUseccase;
private final ReleaseBlockUsecase releaseBlockUsecase;
private final AddBlockUsecase addBlockUsecase;
private final GetListUsecase getListUsecase;
private final ReleaseBlockUsecase releaseBlockUsecase;

@Operation(summary = "add Block User", description = "차단할 유저 추가")
@PostMapping("/block")
public void addBlockUser(@Valid @RequestBody AddBlockDto addBlockDto){
public void addBlockUser(@Valid @RequestBody AddBlockDto addBlockDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("BlockListController::addBlockUser: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
addBlockUseccase.addBlockUser(addBlockDto, securityUser.getUserId());
addBlockUsecase.addBlockUser(addBlockDto, securityUser.getUserId());
}

@Operation(summary = "get List block User", description = "차단한 유저 리스트제공")
@GetMapping("/block")
public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC, size = 30) Pageable pageable){
public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC, size = 30) Pageable pageable) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("BlockListController::getBlockList: Login is needed");
Expand All @@ -57,15 +55,12 @@ public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", directi

@Operation(summary = "release block user", description = "차단한 유저 해제")
@DeleteMapping("/block")
public void releaseBlockUser(@Valid @RequestBody DeleteBlockDto deleteBlockDto){
public void releaseBlockUser(@Valid @RequestBody DeleteBlockDto deleteBlockDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("BlockListController::releaseBlockUser: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
releaseBlockUsecase.releaseBlockUser(deleteBlockDto, securityUser.getUserId());

}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.UUID;


@Entity
@EntityListeners(AuditingEntityListener.class)
@Getter
Expand All @@ -22,9 +21,10 @@
public class BlockListEntity extends BaseEntity {
@Id
private UUID userId;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(nullable = false, name="blocklist_userid", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
@Id
private UserEntity blocklistUserId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
public class BlockListPK implements Serializable {
private UUID userId;
private UserEntity blocklistUserId;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.api.blocklist.adapter.out.persistence;


import com.example.api.blocklist.domain.BlockList;
import com.example.api.blocklist.dto.AddBlockDto;
import com.example.api.user.domain.BlockUser;
Expand All @@ -26,4 +25,4 @@ public interface BlockMapperInterface {
List<BlockUser> toDomainBlockUserList(List<BlockList> blockLists);
// @Mapping(source = "blocklistUserId.userId", target = "userId")
// List<BlockUser> toDomainList(List<BlockListEntity> blockListEntities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import com.example.api.blocklist.application.port.out.ReleaseBlockPort;
import com.example.api.blocklist.domain.BlockList;
import com.example.api.blocklist.repositorty.BlockListRepository;
import com.example.api.chat.adapter.out.persistence.ChatEntity;
import com.example.api.user.domain.BlockUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.core.Block;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
Expand All @@ -18,8 +15,6 @@
import java.util.List;
import java.util.UUID;



@Repository
@RequiredArgsConstructor
@Slf4j
Expand All @@ -45,4 +40,4 @@ public List<BlockList> getBlockUserList(UUID userId, Pageable pageable) {
public void deleteBlockUser(UUID userId, UUID blockUserId) {
blockListRepository.deleteByUserIdAndBlocklistUserId_UserId(userId, blockUserId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import java.util.UUID;

public interface AddBlockUseccase {
public interface AddBlockUsecase {
void addBlockUser(AddBlockDto addBlockDto, UUID userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.api.blocklist.application.port.in;

import com.example.api.blocklist.domain.BlockList;
import com.example.api.user.domain.BlockUser;
import org.springframework.data.domain.Pageable;

Expand All @@ -9,4 +8,4 @@

public interface GetListUsecase {
List<BlockUser> getBlockList(Pageable pageable, UUID userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.example.api.blocklist.application.port.in;

import com.example.api.blocklist.dto.AddBlockDto;
import com.example.api.blocklist.dto.DeleteBlockDto;

import java.util.UUID;

public interface ReleaseBlockUsecase {
void releaseBlockUser(DeleteBlockDto addBlockDto, UUID userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.example.api.blocklist.domain.BlockList;

import java.util.UUID;

public interface AddBlockUserPort {
void addBlockUser(BlockList blockList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

public interface GetBlockListPort {
List<BlockList> getBlockUserList(UUID userId, Pageable pageable);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.example.api.blocklist.application.port.out;

import com.example.api.blocklist.domain.BlockList;

import java.util.UUID;

public interface ReleaseBlockPort {
void deleteBlockUser(UUID userId, UUID blockUserId);
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/example/api/blocklist/domain/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BlockList {
private UUID userId;
private BlockUser blocklistUserId;
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/example/api/blocklist/dto/AddBlockDto.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.api.blocklist.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Data;

import java.util.UUID;
Expand All @@ -14,4 +12,4 @@ public class AddBlockDto {
private UUID blocklistUserId;

private UUID userId;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.api.blocklist.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

Expand All @@ -10,4 +9,4 @@
public class DeleteBlockDto {
@NotNull
private UUID blocklistUserId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public interface BlockListRepository extends JpaRepository<BlockListEntity, Bloc

@EntityGraph(attributePaths = {"blocklistUserId"})
Page<BlockListEntity> findAllByUserId(@Param("userId") UUID userId, Pageable pageable);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.example.api.blocklist.service;


import com.example.api.blocklist.adapter.out.persistence.BlockMapperInterface;
import com.example.api.blocklist.application.port.in.AddBlockUseccase;
import com.example.api.blocklist.application.port.in.AddBlockUsecase;
import com.example.api.blocklist.application.port.in.GetListUsecase;
import com.example.api.blocklist.application.port.in.ReleaseBlockUsecase;
import com.example.api.blocklist.application.port.out.AddBlockUserPort;
Expand All @@ -20,13 +19,12 @@

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class BlockListService implements AddBlockUseccase, GetListUsecase, ReleaseBlockUsecase {
public class BlockListService implements AddBlockUsecase, GetListUsecase, ReleaseBlockUsecase {
private final AddBlockUserPort addBlockUserPort;
private final GetBlockListPort getBlockListPort;
private final ReleaseBlockPort releaseBlockPort;
Expand All @@ -51,4 +49,4 @@ public List<BlockUser> getBlockList(Pageable pageable, UUID userId) {
public void releaseBlockUser(DeleteBlockDto addBlockDto, UUID userId) {
releaseBlockPort.deleteBlockUser(userId, addBlockDto.getBlocklistUserId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,15 @@ public List<FindMatchingDto> getRecommendedMatchingList(UUID userId) {
for (Pair<Long, Integer> matchingData: matchingScoreList) { // 유사도가 높은 순서로 정렬한 후 반환
FindMatchingDto findMatchingDto = this.getMatchingById(matchingData.getFirst());
if (findMatchingDto != null) {
sortedMatchingList.add(findMatchingDto);
if (sortedMatchingList.size() == 10) {
break;
}
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(userId)
.matchingId(findMatchingDto.getMatchingId())
.build();
if (matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK).isEmpty()) { // 신청 상태가 None인 매칭만 보여줌
sortedMatchingList.add(findMatchingDto);
if (sortedMatchingList.size() == 10) {
break;
}
}
}
}
Expand Down

0 comments on commit c0be306

Please sign in to comment.