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

feat: 채팅 목록 조회 정렬기준 변경 #54

Merged
merged 4 commits into from
Nov 21, 2024
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
Expand Up @@ -15,6 +15,7 @@
import com.hyunsolution.dangu.user.exception.UserNotFoundException;
import com.hyunsolution.dangu.workspace.domain.Workspace;
import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -46,7 +47,7 @@ public List<GetChattingsResponse> getChattings(Long loginUserId, Long chatRoomId
public List<GetChatRoomsResponse> getChatRooms(Long userId) {
List<Workspace> chatRooms = workspaceRepository.findByParticipantUserId(userId);
return chatRooms.stream()
.filter(chatRoom -> chatRoom.getParticipants().size() > 1)
.sorted(Comparator.comparing(Workspace::getChatUpdateAt).reversed())
.map(
chatRoom ->
GetChatRoomsResponse.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ParticipantController {
private final WorkspaceRepository workspaceRepository;
private final ParticipantService participantService;

//사용자 매칭 버튼 클릭
// 사용자 매칭 버튼 클릭
@PostMapping("/participant/matching/{roomNumber}")
public ApiResponse<?> matching(
@Parameter(hidden = true) @RequestHeader("Authorization") Long id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public void changeMatching(Long id, Long workspaceId) {
}
}
// 게임방 테이블 속 매칭 결과를 true로 바꿈
Workspace workspace1 = workspaceRepository.findById(workspaceId).orElseThrow(()-> WorkspaceNotFoundException.EXCEPTION);
Workspace workspace1 =
workspaceRepository
.findById(workspaceId)
.orElseThrow(() -> WorkspaceNotFoundException.EXCEPTION);
workspace1.acceptFinal();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.hyunsolution.dangu.user.domain;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUid(String uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hyunsolution.dangu.participant.domain.Participant;
import com.hyunsolution.dangu.user.domain.User;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
Expand All @@ -13,8 +14,6 @@
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -40,6 +39,9 @@ public class Workspace {
@CreatedDate
private LocalDateTime createdAt;

@Column(name = "ch_update_at")
private LocalDateTime chatUpdateAt;

@OneToMany(mappedBy = "workspace", fetch = FetchType.LAZY)
private List<Participant> participants = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public interface WorkspaceRepository extends JpaRepository<Workspace, Long> {
@EntityGraph(attributePaths = {"participants"})
@Query(
"select w from Workspace w where exists (select 1 from Participant p where p.workspace = w and p.user.id = :userId)")
"select w from Workspace w where exists (select 1 from Participant p where p.workspace = w and p.user.id = :userId) and w.chatUpdateAt is not null")
List<Workspace> findByParticipantUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import com.hyunsolution.dangu.workspace.domain.Workspace;
import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository;
import com.hyunsolution.dangu.workspace.dto.response.GetWorkspacesResponse;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -37,8 +34,13 @@ public List<GetWorkspacesResponse> getWorkspaces() {
LocalDateTime dateFilter = LocalDateTime.now().minusDays(1);
return workSpaceRepository.findAll().stream()
.filter(workspace -> !workspace.isMatched())
.filter(workspace -> workspace.getCreatedAt().isAfter(dateFilter)) //게임방 조회: 유지 시간은 24h
.map(workspace ->GetWorkspacesResponse.of(workspace.getId(), workspace.getCreator().getUid()))
.filter(
workspace ->
workspace.getCreatedAt().isAfter(dateFilter)) // 게임방 조회: 유지 시간은 24h
.map(
workspace ->
GetWorkspacesResponse.of(
workspace.getId(), workspace.getCreator().getUid()))
.toList();
}
}
Loading