diff --git a/layer-api/src/main/java/org/layer/domain/space/service/SpaceService.java b/layer-api/src/main/java/org/layer/domain/space/service/SpaceService.java index 91faea1b..cd8aee2a 100644 --- a/layer-api/src/main/java/org/layer/domain/space/service/SpaceService.java +++ b/layer-api/src/main/java/org/layer/domain/space/service/SpaceService.java @@ -1,18 +1,18 @@ package org.layer.domain.space.service; -import jakarta.transaction.Transactional; + import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + import org.layer.common.dto.Meta; +import org.layer.common.exception.BaseCustomException; import org.layer.domain.space.dto.SpaceRequest; import org.layer.domain.space.dto.SpaceResponse; -import org.layer.domain.space.dto.SpaceWithMemberCount; import org.layer.domain.space.entity.MemberSpaceRelation; -import org.layer.domain.space.entity.Space; import org.layer.domain.space.repository.MemberSpaceRelationRepository; import org.layer.domain.space.repository.SpaceRepository; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.stream.Collectors; @@ -46,7 +46,7 @@ public SpaceResponse.SpacePage getSpaceListFromMemberId(Long memberId, SpaceRequ @Transactional public void createSpace(Long memberId, SpaceRequest.CreateSpaceRequest mutateSpaceRequest) { var newSpace = spaceRepository.save(mutateSpaceRequest.toEntity(memberId)); - var memberSpaceRelation = MemberSpaceRelation.builder().memberId(memberId).spaceId(newSpace.getId()).build(); + var memberSpaceRelation = MemberSpaceRelation.builder().memberId(memberId).space(newSpace).build(); memberSpaceRelationRepository.save(memberSpaceRelation); } diff --git a/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepository.java b/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepository.java index 7c28c57b..953d294c 100644 --- a/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepository.java +++ b/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepository.java @@ -1,15 +1,14 @@ package org.layer.domain.space.repository; -import org.layer.domain.space.dto.SpaceWithMemberCount; +import static org.layer.common.exception.SpaceExceptionType.*; + import org.layer.domain.space.entity.Space; -import org.layer.domain.space.entity.SpaceCategory; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import org.layer.domain.space.exception.SpaceException; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -public interface SpaceRepository extends JpaRepository { + +public interface SpaceRepository extends JpaRepository, SpaceCustomRepository { default Space findByIdOrThrow(Long spaceId){ return findById(spaceId) .orElseThrow(() -> new SpaceException(NOT_FOUND_SPACE)); diff --git a/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepositoryImpl.java b/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepositoryImpl.java index 71ef64fb..5a231600 100644 --- a/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepositoryImpl.java +++ b/layer-domain/src/main/java/org/layer/domain/space/repository/SpaceRepositoryImpl.java @@ -49,11 +49,11 @@ public List findAllSpacesByMemberIdAndCategoryAndCursor(Lo memberSpaceRelation.id.count() ) .from(memberSpaceRelation) - .where(memberSpaceRelation.spaceId.eq(space.id)) + .where(memberSpaceRelation.space.id.eq(space.id)) , "userCount") )) .from(space) - .join(memberSpaceRelation).on(space.id.eq(memberSpaceRelation.spaceId)) + .join(memberSpaceRelation).on(space.id.eq(memberSpaceRelation.space.id)) .where(predicate) .groupBy(space.id) .orderBy(space.id.asc()) @@ -77,13 +77,13 @@ public Optional findByIdAndJoinedMemberId(Long spaceId, Lo memberSpaceRelation.id.count() ) .from(memberSpaceRelation) - .where(memberSpaceRelation.spaceId.eq(space.id)) + .where(memberSpaceRelation.space.id.eq(space.id)) , "userCount") ) ) .from(memberSpaceRelation) .join(space) - .on(space.id.eq(memberSpaceRelation.spaceId)) + .on(space.id.eq(memberSpaceRelation.space.id)) .where(space.id.eq(spaceId) .and(memberSpaceRelation.memberId.eq(memberId))) .limit(1)