-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BSVR-97] 특정 경기장 구역 내 블럭 리스트 조회 (#21)
* feat(Block): 특정 경기장의 블럭 조회 서비스 구현 * fix: 경기장 구역의 블럭을 조회하도록 예외처리 추가 * feat: 구역내 블록 리스트 조회 컨트롤러 추가 * fix: 코드 디폴트 구현 삭제 * feat(Block): data.sql 업데이트 * fix: data.sql 오타 수정
- Loading branch information
Showing
21 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
application/src/main/java/org/depromeet/spot/application/block/BlockReadController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.depromeet.spot.application.block; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
import org.depromeet.spot.application.block.dto.response.BlockCodeInfoResponse; | ||
import org.depromeet.spot.usecase.port.in.block.BlockReadUsecase; | ||
import org.depromeet.spot.usecase.port.in.block.BlockReadUsecase.BlockCodeInfo; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@Tag(name = "블록") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class BlockReadController { | ||
|
||
private final BlockReadUsecase blockReadUsecase; | ||
|
||
@ResponseStatus(HttpStatus.OK) | ||
@GetMapping("/stadiums/{stadiumId}/sections/{sectionId}/blocks") | ||
@Operation(summary = "특정 야구 경기장 특정 구역 내의 블록 리스트를 조회한다.") | ||
public List<BlockCodeInfoResponse> findCodeInfosByStadium( | ||
@PathVariable("stadiumId") | ||
@NotNull | ||
@Positive | ||
@Parameter(name = "stadiumId", description = "야구 경기장 PK", required = true) | ||
final Long stadiumId, | ||
@PathVariable("sectionId") | ||
@NotNull | ||
@Positive | ||
@Parameter(name = "sectionId", description = "구역 PK", required = true) | ||
final Long sectionId) { | ||
List<BlockCodeInfo> infos = blockReadUsecase.findCodeInfosByStadium(stadiumId, sectionId); | ||
return infos.stream().map(BlockCodeInfoResponse::from).toList(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rc/main/java/org/depromeet/spot/application/block/dto/response/BlockCodeInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.depromeet.spot.application.block.dto.response; | ||
|
||
import org.depromeet.spot.usecase.port.in.block.BlockReadUsecase.BlockCodeInfo; | ||
|
||
public record BlockCodeInfoResponse(Long id, String code) { | ||
|
||
public static BlockCodeInfoResponse from(BlockCodeInfo blockCodeInfo) { | ||
return new BlockCodeInfoResponse(blockCodeInfo.getId(), blockCodeInfo.getCode()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
common/src/main/java/org/depromeet/spot/common/exception/section/SectionErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.depromeet.spot.common.exception.section; | ||
|
||
import org.depromeet.spot.common.exception.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum SectionErrorCode implements ErrorCode { | ||
SECTION_NOT_FOUND(HttpStatus.NOT_FOUND, "SE001", "요청 구역이 존재하지 않습니다."), | ||
SECTION_NOT_BELONG_TO_STADIUM(HttpStatus.BAD_REQUEST, "SE002", "요청 경기장의 구역이 아닙니다."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String code; | ||
private String message; | ||
|
||
SectionErrorCode(HttpStatus status, String code, String message) { | ||
this.status = status; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public SectionErrorCode appended(Object o) { | ||
message = message + " {" + o.toString() + "}"; | ||
return this; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/main/java/org/depromeet/spot/common/exception/section/SectionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.depromeet.spot.common.exception.section; | ||
|
||
import org.depromeet.spot.common.exception.BusinessException; | ||
|
||
public abstract class SectionException extends BusinessException { | ||
|
||
protected SectionException(SectionErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
public static class SectionNotFoundException extends SectionException { | ||
public SectionNotFoundException() { | ||
super(SectionErrorCode.SECTION_NOT_FOUND); | ||
} | ||
} | ||
|
||
public static class SectionNotBelongStadiumException extends SectionException { | ||
public SectionNotBelongStadiumException() { | ||
super(SectionErrorCode.SECTION_NOT_BELONG_TO_STADIUM); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.depromeet.spot.jpa.block.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.jpa.block.entity.BlockEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface BlockJpaRepository extends JpaRepository<BlockEntity, Long> { | ||
|
||
List<BlockEntity> findAllBySectionId(Long sectionId); | ||
} |
23 changes: 23 additions & 0 deletions
23
...ucture/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.depromeet.spot.jpa.block.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.domain.block.Block; | ||
import org.depromeet.spot.jpa.block.entity.BlockEntity; | ||
import org.depromeet.spot.usecase.port.out.block.BlockRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BlockRepositoryImpl implements BlockRepository { | ||
|
||
private final BlockJpaRepository blockJpaRepository; | ||
|
||
@Override | ||
public List<Block> findAllBySection(final Long sectionId) { | ||
List<BlockEntity> entities = blockJpaRepository.findAllBySectionId(sectionId); | ||
return entities.stream().map(BlockEntity::toDomain).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
usecase/src/main/java/org/depromeet/spot/usecase/port/in/block/BlockReadUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.depromeet.spot.usecase.port.in.block; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
public interface BlockReadUsecase { | ||
|
||
List<BlockCodeInfo> findCodeInfosByStadium(Long stadiumId, Long sectionId); | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
class BlockCodeInfo { | ||
private final Long id; | ||
private final String code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
usecase/src/main/java/org/depromeet/spot/usecase/port/out/block/BlockRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.depromeet.spot.usecase.port.out.block; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.domain.block.Block; | ||
|
||
public interface BlockRepository { | ||
|
||
List<Block> findAllBySection(Long sectionId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
usecase/src/main/java/org/depromeet/spot/usecase/service/block/BlockReadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.depromeet.spot.usecase.service.block; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.common.exception.section.SectionException.SectionNotBelongStadiumException; | ||
import org.depromeet.spot.common.exception.stadium.StadiumException.StadiumNotFoundException; | ||
import org.depromeet.spot.domain.block.Block; | ||
import org.depromeet.spot.usecase.port.in.block.BlockReadUsecase; | ||
import org.depromeet.spot.usecase.port.in.section.SectionReadUsecase; | ||
import org.depromeet.spot.usecase.port.in.stadium.StadiumReadUsecase; | ||
import org.depromeet.spot.usecase.port.out.block.BlockRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BlockReadService implements BlockReadUsecase { | ||
|
||
private final BlockRepository blockRepository; | ||
private final StadiumReadUsecase stadiumReadUsecase; | ||
private final SectionReadUsecase sectionReadUsecase; | ||
|
||
@Override | ||
public List<BlockCodeInfo> findCodeInfosByStadium(final Long stadiumId, final Long sectionId) { | ||
if (!stadiumReadUsecase.existsById(stadiumId)) { | ||
throw new StadiumNotFoundException(); | ||
} | ||
if (!sectionReadUsecase.existsInStadium(stadiumId, sectionId)) { | ||
throw new SectionNotBelongStadiumException(); | ||
} | ||
List<Block> blocks = blockRepository.findAllBySection(sectionId); | ||
return blocks.stream().map(b -> new BlockCodeInfo(b.getId(), b.getCode())).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters