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

feature: 게임방 목록 조회 로직 수정 #27

Merged
merged 4 commits into from
Nov 6, 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 @@ -7,6 +7,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.annotation.CreatedDate;

import java.time.LocalDateTime;

@Entity
@Getter
Expand All @@ -32,14 +35,19 @@ public class Workspace {
@ColumnDefault("0")
private int totalCnt;

@Column(name = "created_at", nullable = false)
@CreatedDate
private LocalDateTime createdAt;

@Builder
private Workspace(User creator, boolean isMatched, int totalCnt) {
public Workspace(User creator, boolean isMatched, int totalCnt, LocalDateTime createdAt) {
this.creator = creator;
this.isMatched = isMatched;
this.totalCnt = totalCnt;
this.createdAt = createdAt;
}

public void finalAccept() {
public void acceptFinal() {
this.isMatched = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
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;

Expand All @@ -23,12 +27,11 @@ public void addWorkspace(Long id) {
}

public List<GetWorkspacesResponse> getWorkspaces() {
LocalDateTime dateFilter = LocalDateTime.now().minusDays(1);
return workSpaceRepository.findAll().stream()
.filter(workspace -> !workspace.isMatched())
.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