Skip to content

Commit

Permalink
Merge pull request #36 from JNU-econovation/feature-#35
Browse files Browse the repository at this point in the history
feat: h2 의존성 추가
  • Loading branch information
LJH098 authored Nov 8, 2024
2 parents fac7abd + 79a90d1 commit 3827cf6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.12'
runtimeOnly 'com.h2database:h2'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -23,23 +22,29 @@ public class ParticipantService {
public void changeMatching(Long id, Long workspaceId) {
// 상태 변경
Participant participantOptional =
participantRepository.findByUserIdAndWorkspaceId(id, workspaceId)
.orElseThrow(()-> new NoSuchElementException("Participant not found"));
participantRepository
.findByUserIdAndWorkspaceId(id, workspaceId)
.orElseThrow(() -> new NoSuchElementException("Participant not found"));

participantOptional.accept();

// participant테이블에서 roomNumber로 들어온 숫자를 통해 누가 있는지 파악
List<Long> participantIds = participantRepository.findParticipantIdByWorkspaceId(workspaceId);
List<Long> participantIds =
participantRepository.findParticipantIdByWorkspaceId(workspaceId);

// 방안에 모든 참가자가 "확정"버튼을 눌렀는지 확인
for (Long participant : participantIds) {
boolean mathingCheck = participantRepository.existsByIdAndParticipantMatchTrue(participant);
boolean mathingCheck =
participantRepository.existsByIdAndParticipantMatchTrue(participant);
if (!mathingCheck) {
return;
}
}
// 게임방 테이블 속 매칭 결과를 true로 바꿈
Workspace workspace1 = workspaceRepository.findById(workspaceId).orElseThrow(()-> new NoSuchElementException("Workspace not found"));
Workspace workspace1 =
workspaceRepository
.findById(workspaceId)
.orElseThrow(() -> new NoSuchElementException("Workspace not found"));
workspace1.acceptFinal();
}
}
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
@@ -1,6 +1,7 @@
package com.hyunsolution.dangu.workspace.domain;

import com.hyunsolution.dangu.user.domain.User;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -9,8 +10,6 @@
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.annotation.CreatedDate;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,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;

Expand All @@ -30,8 +27,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();
}
}

0 comments on commit 3827cf6

Please sign in to comment.