Skip to content

Commit

Permalink
Merge pull request #85 from Leets-Official/refactor/#84프론트엔드-요구사항반영
Browse files Browse the repository at this point in the history
Refactor/#84프론트엔드 요구사항반영
  • Loading branch information
soyesenna authored Feb 4, 2025
2 parents 2f93bd9 + 023caae commit d8a0878
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -21,6 +22,9 @@ public class MatchingAlgorithmServiceImpl implements MatchingAlgorithmService {
private final MemberService memberService;
private final BlacklistService blacklistService;

@Value("${gachtaxi.matching.auto-matching-description}")
private String autoMatchingDescription;

private static final double SEARCH_RADIUS = 300.0;

@Override
Expand All @@ -32,9 +36,13 @@ public Optional<FindRoomResult> findRoom(Long userId, double startLongitude, dou
*/
Members user = memberService.findById(userId);

if (matchingRoomRepository.existsByMemberInMatchingRoom(user)) {
throw new AlreadyInMatchingRoomException(); // * 추후 논의 후 리팩토링 필요 * 똑같은 조건으로 방 생성시 예외 던져주기
}
matchingRoomRepository.findByMemberInMatchingRoom(user)
.forEach(room -> {
if (room.getDescription().equals(autoMatchingDescription)) {
throw new AlreadyInMatchingRoomException(room.getChattingRoomId());
}
});

/*
위치 정보를 이용한 방 검색(300M 이내)ø
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import static org.springframework.http.HttpStatus.CONFLICT;

import com.gachtaxi.global.common.exception.BaseException;
import java.util.Map;

public class AlreadyInMatchingRoomException extends BaseException {
public AlreadyInMatchingRoomException(Long chattingRoomId) {
super(CONFLICT, Map.of("chattingRoomId", chattingRoomId, "message", ALREADY_IN_MATCHING_ROOM.getMessage()).toString());
}

public AlreadyInMatchingRoomException() {
super(CONFLICT, ALREADY_IN_MATCHING_ROOM.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.gachtaxi.domain.matching.common.entity.enums.MatchingRoomType;
import com.gachtaxi.domain.members.entity.Members;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -25,11 +26,18 @@ List<MatchingRoom> findRoomsByStartAndDestination(
@Param("destinationLatitude") double destinationLatitude,
@Param("radius") double radius
);
@Query("SELECT CASE WHEN COUNT(m) > 0 THEN true ELSE false END " +
@Query("SELECT r " +
"FROM MatchingRoom r JOIN r.memberMatchingRoomChargingInfo m " +
"WHERE m.members = :user "+
"AND r.matchingRoomStatus = 'ACTIVE' "+
"AND m.paymentStatus != 'LEFT'")
List<MatchingRoom> findByMemberInMatchingRoom(@Param("user") Members user);

@Query("SELECT CASE WHEN COUNT(m) > 0 THEN true ELSE false END " +
"FROM MatchingRoom r JOIN r.memberMatchingRoomChargingInfo m " +
"WHERE m.members = :user "+
"AND r.matchingRoomStatus = 'ACTIVE' "+
"AND m.paymentStatus != 'LEFT'")
boolean existsByMemberInMatchingRoom(@Param("user") Members user);

Page<MatchingRoom> findByMatchingRoomTypeAndMatchingRoomStatus(MatchingRoomType type, MatchingRoomStatus status, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
@Builder
public record BlacklistGetResponse(
List<BlacklistInfo> blacklists,
Integer pageNumber,
Integer pageSize,
Integer numberOfElements,
Boolean last
BlacklistPageable pageable
) {
public static BlacklistGetResponse of(Slice<Blacklists> blacklistsPage) {
List<BlacklistInfo> responseList = blacklistsPage.stream()
Expand All @@ -21,23 +18,39 @@ public static BlacklistGetResponse of(Slice<Blacklists> blacklistsPage) {

return BlacklistGetResponse.builder()
.blacklists(responseList)
.pageNumber(blacklistsPage.getNumber())
.pageSize(blacklistsPage.getSize())
.numberOfElements(blacklistsPage.getNumberOfElements())
.last(blacklistsPage.isLast())
.pageable(BlacklistPageable.of(blacklistsPage))
.build();
}

record BlacklistInfo(
Long receiverId,
String receiverNickname,
String receiverProfilePicture,
String gender
) {
public static BlacklistInfo of(Blacklists blacklists) {
return new BlacklistInfo(
blacklists.getReceiver().getId(),
blacklists.getReceiver().getNickname(),
blacklists.getReceiver().getGender().name()
blacklists.getReceiver().getGender().name(),
blacklists.getReceiverProfilePicture()
);
}
}

record BlacklistPageable(
Integer pageNumber,
Integer pageSize,
Integer numberOfElements,
Boolean last
) {

public static BlacklistPageable of (Slice<Blacklists> blacklistsPage) {
return new BlacklistPageable(
blacklistsPage.getNumber(),
blacklistsPage.getSize(),
blacklistsPage.getNumberOfElements(),
blacklistsPage.isLast()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class Blacklists extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Members receiver;

public String getReceiverProfilePicture() {
return receiver.getProfilePicture();
}

public static Blacklists create(Members requester, Members receiver) {
return Blacklists.builder()
.requester(requester)
Expand Down

0 comments on commit d8a0878

Please sign in to comment.