Skip to content

Commit

Permalink
Merge d87d477 into 952a226
Browse files Browse the repository at this point in the history
  • Loading branch information
EunjiShin authored Jul 18, 2024
2 parents 952a226 + d87d477 commit 26cc5a6
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ public List<BlockInfoResponse> findAllBlockInfoBy(
}

@ResponseStatus(HttpStatus.OK)
@GetMapping("blocks/{blockId}/rows")
@GetMapping("/stadiums/{stadiumId}/blocks/{blockCode}/rows")
@Operation(summary = "특정 블록 내에 있는 열별 좌석 범위 정보를 조회한다.")
public BlockInfoResponse findBlockInfoBy(
@PathVariable("blockId")
@PathVariable("stadiumId")
@NotNull
@Positive
@Parameter(name = "stadiumId", description = "경기장 PK", required = true)
final Long stadiumId,
@PathVariable("blockCode")
@NotNull
@Positive
@Parameter(name = "blockId", description = "블록 PK", required = true)
final Long blockId) {
BlockInfo infos = blockReadUsecase.findBlockInfoBy(blockId);
@Parameter(name = "blockCode", description = "블록 Code", required = true)
final String blockCode) {
BlockInfo infos = blockReadUsecase.findBlockInfoBy(stadiumId, blockCode);
return BlockInfoResponse.from(infos);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.depromeet.spot.jpa.block.repository;

import java.util.List;
import java.util.Optional;

import org.depromeet.spot.jpa.block.entity.BlockEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BlockJpaRepository extends JpaRepository<BlockEntity, Long> {
Optional<BlockEntity> findByStadiumIdAndCode(Long stadiumId, String code);

List<BlockEntity> findAllBySectionId(Long sectionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public List<BlockRow> findAllByBlock(final Long blockId) {
return entities.stream().map(BlockRowEntity::toDomain).toList();
}

@Override
public List<BlockRow> findAllByStadiumAndBlock(Long stadiumId, String blockCode) {
List<BlockRowEntity> entities =
blockRowJpaRepository.findAllByStadiumAndBlock(stadiumId, blockCode);
return entities.stream().map(BlockRowEntity::toDomain).toList();
}

@Override
public boolean existsById(final Long blockId) {
return blockJpaRepository.existsById(blockId);
Expand All @@ -60,4 +67,13 @@ public Block findById(final Long blockId) {
blockJpaRepository.findById(blockId).orElseThrow(BlockNotFoundException::new);
return entity.toDomain();
}

@Override
public Block findByStadiumAndCode(final Long stadiumId, final String code) {
BlockEntity entity =
blockJpaRepository
.findByStadiumIdAndCode(stadiumId, code)
.orElseThrow(BlockNotFoundException::new);
return entity.toDomain();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@

import org.depromeet.spot.jpa.block.entity.BlockRowEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BlockRowJpaRepository extends JpaRepository<BlockRowEntity, Long> {

List<BlockRowEntity> findAllByBlockIdOrderByNumberAsc(Long blockId);

@Query(
"select r from BlockRowEntity r "
+ "where r.block.stadiumId = :stadiumId "
+ "and r.block.code = :code "
+ "order by r.number asc")
List<BlockRowEntity> findAllByStadiumAndBlock(
@Param("stadiumId") Long stadiumId, @Param("code") String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public interface BlockReadUsecase {

List<BlockInfo> findAllBlockInfoBy(final Long stadiumId, final Long sectionId);

BlockInfo findBlockInfoBy(final Long blockId);
BlockInfo findBlockInfoBy(final Long stadiumId, final String blockCode);

Block findById(Long blockId);

Block findByStadiumAndCode(Long stadiumId, String code);

boolean existsById(Long blockId);

void checkExistsById(Long blockId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public interface BlockRepository {

List<BlockRow> findAllByBlock(Long blockId);

List<BlockRow> findAllByStadiumAndBlock(Long stadiumId, String blockCode);

boolean existsById(Long blockId);

Block findById(Long blockId);

Block findByStadiumAndCode(Long stadiumId, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ public List<BlockInfo> findAllBlockInfoBy(final Long stadiumId, final Long secti
}

@Override
public BlockInfo findBlockInfoBy(final Long blockId) {
Block block = findById(blockId);
List<BlockRow> infos = blockRepository.findAllByBlock(blockId);
public BlockInfo findBlockInfoBy(final Long stadiumId, final String blockCode) {
stadiumReadUsecase.checkIsExistsBy(stadiumId);
Block block = findByStadiumAndCode(stadiumId, blockCode);
List<BlockRow> infos = blockRepository.findAllByStadiumAndBlock(stadiumId, blockCode);
List<RowInfo> rowInfos = getBlockRowInfos(infos);
return new BlockInfo(blockId, block.getCode(), rowInfos);
return new BlockInfo(block.getId(), block.getCode(), rowInfos);
}

@Override
public Block findById(final Long blockId) {
return blockRepository.findById(blockId);
}

@Override
public Block findByStadiumAndCode(final Long stadiumId, final String code) {
return blockRepository.findByStadiumAndCode(stadiumId, code);
}

@Override
public boolean existsById(final Long blockId) {
return blockRepository.existsById(blockId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public List<BlockRow> findAllByBlock(Long blockId) {
return rowData.stream().filter(row -> row.getBlock().getId().equals(blockId)).toList();
}

@Override
public List<BlockRow> findAllByStadiumAndBlock(Long stadiumId, String blockCode) {
return rowData.stream()
.filter(row -> row.getBlock().getStadiumId().equals(stadiumId))
.filter(row -> row.getBlock().getCode().equals(blockCode))
.toList();
}

@Override
public boolean existsById(Long blockId) {
return blockData.stream().anyMatch(block -> block.getId().equals(blockId));
Expand All @@ -44,7 +52,19 @@ public Block findById(Long blockId) {
return getById(blockId).orElseThrow(BlockNotFoundException::new);
}

@Override
public Block findByStadiumAndCode(Long stadiumId, String code) {
return getByStadiumAndCode(stadiumId, code).orElseThrow(BlockNotFoundException::new);
}

private Optional<Block> getById(Long id) {
return blockData.stream().filter(block -> block.getId().equals(id)).findAny();
}

private Optional<Block> getByStadiumAndCode(Long stadiumId, String code) {
return blockData.stream()
.filter(block -> block.getCode().equals(code))
.filter(block -> block.getStadiumId().equals(stadiumId))
.findAny();
}
}

0 comments on commit 26cc5a6

Please sign in to comment.