diff --git a/application/src/main/java/org/depromeet/spot/application/block/BlockReadController.java b/application/src/main/java/org/depromeet/spot/application/block/BlockReadController.java new file mode 100644 index 00000000..6358e420 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/block/BlockReadController.java @@ -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 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 infos = blockReadUsecase.findCodeInfosByStadium(stadiumId, sectionId); + return infos.stream().map(BlockCodeInfoResponse::from).toList(); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/block/dto/response/BlockCodeInfoResponse.java b/application/src/main/java/org/depromeet/spot/application/block/dto/response/BlockCodeInfoResponse.java new file mode 100644 index 00000000..21d75bdd --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/block/dto/response/BlockCodeInfoResponse.java @@ -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()); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/common/dto/RgbCodeRequest.java b/application/src/main/java/org/depromeet/spot/application/common/dto/RgbCodeRequest.java new file mode 100644 index 00000000..7335f27f --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/common/dto/RgbCodeRequest.java @@ -0,0 +1,9 @@ +package org.depromeet.spot.application.common.dto; + +import org.depromeet.spot.domain.common.RgbCode; + +public record RgbCodeRequest(Integer red, Integer green, Integer blue) { + public RgbCode toDomain() { + return RgbCode.builder().red(red).green(green).blue(blue).build(); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/stadium/dto/response/HomeTeamInfoResponse.java b/application/src/main/java/org/depromeet/spot/application/stadium/dto/response/HomeTeamInfoResponse.java index 24809d56..1ece6284 100644 --- a/application/src/main/java/org/depromeet/spot/application/stadium/dto/response/HomeTeamInfoResponse.java +++ b/application/src/main/java/org/depromeet/spot/application/stadium/dto/response/HomeTeamInfoResponse.java @@ -2,7 +2,7 @@ import org.depromeet.spot.application.common.dto.RgbCodeResponse; import org.depromeet.spot.domain.common.RgbCode; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase.HomeTeamInfo; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase.HomeTeamInfo; public record HomeTeamInfoResponse(Long id, String alias, RgbCodeResponse color) { diff --git a/application/src/main/java/org/depromeet/spot/application/team/CreateBaseballTeamController.java b/application/src/main/java/org/depromeet/spot/application/team/CreateBaseballTeamController.java new file mode 100644 index 00000000..b5ccdeb2 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/team/CreateBaseballTeamController.java @@ -0,0 +1,37 @@ +package org.depromeet.spot.application.team; + +import java.util.List; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; + +import org.depromeet.spot.application.team.dto.request.CreateBaseballTeamReq; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.port.in.team.CreateBaseballTeamUsecase; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +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.tags.Tag; +import lombok.RequiredArgsConstructor; + +@RestController +@Tag(name = "야구 팀") +@RequiredArgsConstructor +@RequestMapping("/api/v1") +public class CreateBaseballTeamController { + + private final CreateBaseballTeamUsecase createBaseballTeamUsecase; + + @PostMapping("/baseball-teams") + @ResponseStatus(HttpStatus.CREATED) + @Operation(summary = "신규 야구 팀(구단) 정보를 생성한다.") + public void create(@RequestBody @Valid @NotEmpty List requests) { + List teams = requests.stream().map(CreateBaseballTeamReq::toDomain).toList(); + createBaseballTeamUsecase.saveAll(teams); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/team/ReadBaseballTeamController.java b/application/src/main/java/org/depromeet/spot/application/team/ReadBaseballTeamController.java new file mode 100644 index 00000000..d6f264b7 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/team/ReadBaseballTeamController.java @@ -0,0 +1,33 @@ +package org.depromeet.spot.application.team; + +import java.util.List; + +import org.depromeet.spot.application.team.dto.response.BaseballTeamLogoRes; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.port.in.team.ReadBaseballTeamUsecase; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +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.tags.Tag; +import lombok.RequiredArgsConstructor; + +@RestController +@Tag(name = "야구 팀") +@RequiredArgsConstructor +@RequestMapping("/api/v1") +public class ReadBaseballTeamController { + + private final ReadBaseballTeamUsecase readBaseballTeamUsecase; + + @GetMapping("/baseball-teams") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "SPOT에서 관리하는 모든 야구 팀 정보를 조회한다.") + public List findAll() { + List infos = readBaseballTeamUsecase.findAll(); + return infos.stream().map(BaseballTeamLogoRes::from).toList(); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/team/dto/request/CreateBaseballTeamReq.java b/application/src/main/java/org/depromeet/spot/application/team/dto/request/CreateBaseballTeamReq.java new file mode 100644 index 00000000..e8979094 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/team/dto/request/CreateBaseballTeamReq.java @@ -0,0 +1,27 @@ +package org.depromeet.spot.application.team.dto.request; + +import jakarta.validation.constraints.NotBlank; + +import org.depromeet.spot.application.common.dto.RgbCodeRequest; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.hibernate.validator.constraints.Length; + +public record CreateBaseballTeamReq( + @NotBlank(message = "구단명을 입력해주세요.") + @Length(max = 20, message = "구단명은 최대 20글자 까지만 입력할 수 있습니다.") + String name, + @NotBlank(message = "구단 별칭을 입력해주세요.") + @Length(max = 10, message = "구단 별칭은 최대 10글자 까지만 입력할 수 있습니다.") + String alias, + @NotBlank(message = "구단 로고를 입력해주세요.") String logo, + RgbCodeRequest rgbCode) { + + public BaseballTeam toDomain() { + return BaseballTeam.builder() + .name(name) + .alias(alias) + .logo(logo) + .labelRgbCode(rgbCode.toDomain()) + .build(); + } +} diff --git a/application/src/main/java/org/depromeet/spot/application/team/dto/response/BaseballTeamLogoRes.java b/application/src/main/java/org/depromeet/spot/application/team/dto/response/BaseballTeamLogoRes.java new file mode 100644 index 00000000..b66b3e17 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/team/dto/response/BaseballTeamLogoRes.java @@ -0,0 +1,10 @@ +package org.depromeet.spot.application.team.dto.response; + +import org.depromeet.spot.domain.team.BaseballTeam; + +public record BaseballTeamLogoRes(Long id, String name, String logo) { + + public static BaseballTeamLogoRes from(BaseballTeam team) { + return new BaseballTeamLogoRes(team.getId(), team.getName(), team.getLogo()); + } +} diff --git a/common/src/main/java/org/depromeet/spot/common/exception/section/SectionErrorCode.java b/common/src/main/java/org/depromeet/spot/common/exception/section/SectionErrorCode.java new file mode 100644 index 00000000..65435715 --- /dev/null +++ b/common/src/main/java/org/depromeet/spot/common/exception/section/SectionErrorCode.java @@ -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; + } +} diff --git a/common/src/main/java/org/depromeet/spot/common/exception/section/SectionException.java b/common/src/main/java/org/depromeet/spot/common/exception/section/SectionException.java new file mode 100644 index 00000000..053b5f02 --- /dev/null +++ b/common/src/main/java/org/depromeet/spot/common/exception/section/SectionException.java @@ -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); + } + } +} diff --git a/common/src/main/java/org/depromeet/spot/common/exception/team/TeamErrorCode.java b/common/src/main/java/org/depromeet/spot/common/exception/team/TeamErrorCode.java new file mode 100644 index 00000000..71e4194e --- /dev/null +++ b/common/src/main/java/org/depromeet/spot/common/exception/team/TeamErrorCode.java @@ -0,0 +1,31 @@ +package org.depromeet.spot.common.exception.team; + +import org.depromeet.spot.common.exception.ErrorCode; +import org.springframework.http.HttpStatus; + +import lombok.Getter; + +@Getter +public enum TeamErrorCode implements ErrorCode { + BASEBALL_TEAM_NOT_FOUND(HttpStatus.NOT_FOUND, "T001", "요청 구단이 존재하지 않습니다."), + INVALID_TEAM_NAME_NOT_FOUND(HttpStatus.BAD_REQUEST, "T002", "구단명이 잘못되었습니다."), + INVALID_TEAM_ALIAS_NOT_FOUND(HttpStatus.BAD_REQUEST, "T003", "구단 별칭이 잘못되었습니다."), + DUPLICATE_TEAM_NAME(HttpStatus.CONFLICT, "T004", "이미 등록된 구단입니다."), + EMPTY_TEAM_LOGO(HttpStatus.BAD_REQUEST, "T005", "구단 로고를 등록해주세요."), + ; + + private final HttpStatus status; + private final String code; + private String message; + + TeamErrorCode(HttpStatus status, String code, String message) { + this.status = status; + this.code = code; + this.message = message; + } + + public TeamErrorCode appended(Object o) { + message = message + " {" + o.toString() + "}"; + return this; + } +} diff --git a/common/src/main/java/org/depromeet/spot/common/exception/team/TeamException.java b/common/src/main/java/org/depromeet/spot/common/exception/team/TeamException.java new file mode 100644 index 00000000..b217581e --- /dev/null +++ b/common/src/main/java/org/depromeet/spot/common/exception/team/TeamException.java @@ -0,0 +1,40 @@ +package org.depromeet.spot.common.exception.team; + +import org.depromeet.spot.common.exception.BusinessException; + +public abstract class TeamException extends BusinessException { + + protected TeamException(TeamErrorCode errorCode) { + super(errorCode); + } + + public static class BaseballTeamNotFoundException extends TeamException { + public BaseballTeamNotFoundException() { + super(TeamErrorCode.BASEBALL_TEAM_NOT_FOUND); + } + } + + public static class InvalidBaseballTeamNameException extends TeamException { + public InvalidBaseballTeamNameException() { + super(TeamErrorCode.INVALID_TEAM_NAME_NOT_FOUND); + } + } + + public static class InvalidBaseballAliasNameException extends TeamException { + public InvalidBaseballAliasNameException() { + super(TeamErrorCode.INVALID_TEAM_ALIAS_NOT_FOUND); + } + } + + public static class DuplicateTeamNameException extends TeamException { + public DuplicateTeamNameException() { + super(TeamErrorCode.DUPLICATE_TEAM_NAME); + } + } + + public static class EmptyTeamLogoException extends TeamException { + public EmptyTeamLogoException() { + super(TeamErrorCode.EMPTY_TEAM_LOGO); + } + } +} diff --git a/domain/src/main/java/org/depromeet/spot/domain/review/Review.java b/domain/src/main/java/org/depromeet/spot/domain/review/Review.java index 8c63a8b6..0d22b9ab 100644 --- a/domain/src/main/java/org/depromeet/spot/domain/review/Review.java +++ b/domain/src/main/java/org/depromeet/spot/domain/review/Review.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.util.List; + import lombok.Builder; import lombok.Getter; @@ -17,6 +18,7 @@ public class Review { private final Long seatId; private final Long rowId; private final Long seatNumber; + private final LocalDateTime dateTime; // 시간은 미표기 private final String content; private final LocalDateTime createdAt; @@ -24,4 +26,5 @@ public class Review { private final LocalDateTime deletedAt; private final List images; private final List keywords; + } diff --git a/domain/src/main/java/org/depromeet/spot/domain/team/BaseballTeam.java b/domain/src/main/java/org/depromeet/spot/domain/team/BaseballTeam.java index 0cc8ce91..2b28d4a7 100644 --- a/domain/src/main/java/org/depromeet/spot/domain/team/BaseballTeam.java +++ b/domain/src/main/java/org/depromeet/spot/domain/team/BaseballTeam.java @@ -1,10 +1,15 @@ package org.depromeet.spot.domain.team; +import org.depromeet.spot.common.exception.team.TeamException.EmptyTeamLogoException; +import org.depromeet.spot.common.exception.team.TeamException.InvalidBaseballAliasNameException; +import org.depromeet.spot.common.exception.team.TeamException.InvalidBaseballTeamNameException; import org.depromeet.spot.domain.common.RgbCode; +import lombok.Builder; import lombok.Getter; @Getter +@Builder public class BaseballTeam { private final Long id; @@ -13,11 +18,40 @@ public class BaseballTeam { private final String logo; private final RgbCode labelRgbCode; + private static final int MAX_NAME_LENGTH = 20; + private static final int MAX_ALIAS_LENGTH = 10; + public BaseballTeam(Long id, String name, String alias, String logo, RgbCode labelRgbCode) { + checkValidName(name); + checkValidAlias(alias); + checkValidLogo(logo); + this.id = id; this.name = name; this.alias = alias; this.logo = logo; this.labelRgbCode = labelRgbCode; } + + private void checkValidName(final String name) { + if (isNullOrBlank(name) || name.length() > MAX_NAME_LENGTH) { + throw new InvalidBaseballTeamNameException(); + } + } + + private void checkValidAlias(final String alias) { + if (isNullOrBlank(alias) || alias.length() > MAX_ALIAS_LENGTH) { + throw new InvalidBaseballAliasNameException(); + } + } + + private void checkValidLogo(final String logo) { + if (isNullOrBlank(logo)) { + throw new EmptyTeamLogoException(); + } + } + + private boolean isNullOrBlank(String str) { + return str == null || str.isBlank(); + } } diff --git a/domain/src/test/java/org/depromeet/spot/domain/team/BaseballTeamTest.java b/domain/src/test/java/org/depromeet/spot/domain/team/BaseballTeamTest.java new file mode 100644 index 00000000..076f4985 --- /dev/null +++ b/domain/src/test/java/org/depromeet/spot/domain/team/BaseballTeamTest.java @@ -0,0 +1,111 @@ +package org.depromeet.spot.domain.team; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import org.depromeet.spot.common.exception.team.TeamException.EmptyTeamLogoException; +import org.depromeet.spot.common.exception.team.TeamException.InvalidBaseballAliasNameException; +import org.depromeet.spot.common.exception.team.TeamException.InvalidBaseballTeamNameException; +import org.depromeet.spot.domain.common.RgbCode; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; + +class BaseballTeamTest { + + @ParameterizedTest + @NullAndEmptySource + void name이_null_또는_blank일_때_BaseballTeam을_생성할_수_없다(String name) { + // given + RgbCode rgbCode = new RgbCode(100, 100, 100); + + // when + // then + assertAll( + () -> + assertThatThrownBy( + () -> new BaseballTeam(1L, name, "alias", "logo", rgbCode)) + .isInstanceOf(InvalidBaseballTeamNameException.class), + () -> + assertThatThrownBy( + () -> + BaseballTeam.builder() + .name(name) + .alias("alias") + .logo("logo") + .build()) + .isInstanceOf(InvalidBaseballTeamNameException.class)); + } + + @Test + void name_길이는_20글자를_초과할_수_없다() { + // given + final String name = "012345678901234567890"; + RgbCode rgbCode = new RgbCode(100, 100, 100); + + // when + // then + assertThatThrownBy(() -> new BaseballTeam(1L, name, "alias", "logo", rgbCode)) + .isInstanceOf(InvalidBaseballTeamNameException.class); + } + + @ParameterizedTest + @NullAndEmptySource + void alias가_null_또는_blank일_때_BaseballTeam을_생성할_수_없다(String alias) { + // given + RgbCode rgbCode = new RgbCode(100, 100, 100); + + // when + // then + assertAll( + () -> + assertThatThrownBy( + () -> new BaseballTeam(1L, "name", alias, "logo", rgbCode)) + .isInstanceOf(InvalidBaseballAliasNameException.class), + () -> + assertThatThrownBy( + () -> + BaseballTeam.builder() + .name("name") + .alias(alias) + .logo("logo") + .build()) + .isInstanceOf(InvalidBaseballAliasNameException.class)); + } + + @Test + void alias_길이는_10글자를_초과할_수_없다() { + // given + final String alias = "01234567890"; + RgbCode rgbCode = new RgbCode(100, 100, 100); + + // when + // then + assertThatThrownBy(() -> new BaseballTeam(1L, "name", alias, "logo", rgbCode)) + .isInstanceOf(InvalidBaseballAliasNameException.class); + } + + @ParameterizedTest + @NullAndEmptySource + void logo가_null_또는_blank일_때_BaseballTeam을_생성할_수_없다(String logo) { + // given + RgbCode rgbCode = new RgbCode(100, 100, 100); + + // when + // then + assertAll( + () -> + assertThatThrownBy( + () -> new BaseballTeam(1L, "name", "alias", logo, rgbCode)) + .isInstanceOf(EmptyTeamLogoException.class), + () -> + assertThatThrownBy( + () -> + BaseballTeam.builder() + .name("name") + .alias("alias") + .logo(logo) + .build()) + .isInstanceOf(EmptyTeamLogoException.class)); + } +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockEntity.java index 51b4a870..18eafbf3 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockEntity.java @@ -2,23 +2,19 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.block.Block; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "blocks") @NoArgsConstructor -public class BlockEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class BlockEntity extends BaseEntity { @Column(name = "stadium_id", nullable = false) private Long stadiumId; @@ -32,24 +28,12 @@ public class BlockEntity { @Column(name = "max_rows", nullable = false) private Integer maxRows; - public BlockEntity(Long id, Long stadiumId, Long sectionId, String code, Integer maxRows) { - this.id = id; - this.stadiumId = stadiumId; - this.sectionId = sectionId; - this.code = code; - this.maxRows = maxRows; - } - public static BlockEntity from(Block block) { return new BlockEntity( - block.getId(), - block.getStadiumId(), - block.getSectionId(), - block.getCode(), - block.getMaxRows()); + block.getStadiumId(), block.getSectionId(), block.getCode(), block.getMaxRows()); } public Block toDomain() { - return new Block(id, stadiumId, sectionId, code, maxRows); + return new Block(this.getId(), stadiumId, sectionId, code, maxRows); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockRowEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockRowEntity.java index f7fdf65d..e3d2f490 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockRowEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/entity/BlockRowEntity.java @@ -2,24 +2,19 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.block.BlockRow; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "block_rows") @NoArgsConstructor -public class BlockRowEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; - +@AllArgsConstructor +public class BlockRowEntity extends BaseEntity { @Column(name = "block_id", nullable = false) private Long blockId; @@ -29,22 +24,12 @@ public class BlockRowEntity { @Column(name = "max_seats", nullable = false) private Long maxSeats; - public BlockRowEntity(Long id, Long blockId, Long number, Long maxSeats) { - this.id = id; - this.blockId = blockId; - this.number = number; - this.maxSeats = maxSeats; - } - public static BlockRowEntity from(BlockRow blockRow) { return new BlockRowEntity( - blockRow.getId(), - blockRow.getBlockId(), - blockRow.getNumber(), - blockRow.getMaxSeats()); + blockRow.getBlockId(), blockRow.getNumber(), blockRow.getMaxSeats()); } public BlockRow toDomain() { - return new BlockRow(id, blockId, number, maxSeats); + return new BlockRow(this.getId(), blockId, number, maxSeats); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockJpaRepository.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockJpaRepository.java new file mode 100644 index 00000000..8e7aed5e --- /dev/null +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockJpaRepository.java @@ -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 { + + List findAllBySectionId(Long sectionId); +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockRepositoryImpl.java new file mode 100644 index 00000000..764abf62 --- /dev/null +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/block/repository/BlockRepositoryImpl.java @@ -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 findAllBySection(final Long sectionId) { + List entities = blockJpaRepository.findAllBySectionId(sectionId); + return entities.stream().map(BlockEntity::toDomain).toList(); + } +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/common/entity/BaseEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/common/entity/BaseEntity.java new file mode 100644 index 00000000..7ab09ace --- /dev/null +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/common/entity/BaseEntity.java @@ -0,0 +1,64 @@ +package org.depromeet.spot.jpa.common.entity; + +import java.time.LocalDateTime; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; + +import org.hibernate.annotations.Where; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +@MappedSuperclass +@AllArgsConstructor +@Where(clause = "deleted_at is null") +@EntityListeners(AuditingEntityListener.class) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public abstract class BaseEntity { + + @Id + @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(updatable = false, name = "created_at") + private LocalDateTime createdAt; + + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + @Column(name = "deleted_at") + private LocalDateTime deletedAt; + + @PrePersist + public void prePersist() { + this.createdAt = LocalDateTime.now(); + this.updatedAt = LocalDateTime.now(); + } + + @PreUpdate + public void preUpdate() { + this.updatedAt = LocalDateTime.now(); + } + + public boolean isDeleted() { + return null != this.deletedAt; + } + + public void delete() { + this.deletedAt = LocalDateTime.now(); + } +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/entity/MemberEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/entity/MemberEntity.java index d0dda28a..fd59477a 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/entity/MemberEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/entity/MemberEntity.java @@ -1,26 +1,20 @@ package org.depromeet.spot.jpa.member.entity; -import java.time.LocalDateTime; - import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.member.Member; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "members") @NoArgsConstructor -public class MemberEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "user_id", nullable = false) - private Long userId; +@AllArgsConstructor +public class MemberEntity extends BaseEntity { @Column(name = "email", nullable = false, unique = true, length = 50) private String email; @@ -52,44 +46,8 @@ public class MemberEntity { @Column(name = "role", nullable = false) private Integer role; - @Column(name = "created_at", nullable = false) - private LocalDateTime createdAt; - - @Column(name = "deleted_at") - private LocalDateTime deletedAt; - - public MemberEntity( - Long userId, - String email, - String name, - String nickname, - String phoneNumber, - Integer level, - String profileImage, - String snsProvider, - String idToken, - String myTeam, - Integer role, - LocalDateTime createdAt, - LocalDateTime deletedAt) { - this.userId = userId; - this.email = email; - this.name = name; - this.nickname = nickname; - this.phoneNumber = phoneNumber; - this.level = level; - this.profileImage = profileImage; - this.snsProvider = snsProvider; - this.idToken = idToken; - this.myTeam = myTeam; - this.role = role; - this.createdAt = createdAt; - this.deletedAt = deletedAt; - } - public static MemberEntity from(Member member) { return new MemberEntity( - member.getUserId(), member.getEmail(), member.getName(), member.getNickname(), @@ -99,14 +57,12 @@ public static MemberEntity from(Member member) { member.getSnsProvider(), member.getIdToken(), member.getMyTeam(), - member.getRole(), - member.getCreatedAt(), - member.getDeletedAt()); + member.getRole()); } public Member toDomain() { return new Member( - userId, + this.getId(), email, name, nickname, @@ -117,7 +73,7 @@ public Member toDomain() { idToken, myTeam, role, - createdAt, - deletedAt); + this.getCreatedAt(), + this.getDeletedAt()); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/seat/entity/SeatEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/seat/entity/SeatEntity.java index dba2ca5d..0f9cea16 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/seat/entity/SeatEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/seat/entity/SeatEntity.java @@ -2,23 +2,19 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.seat.Seat; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "seats") @NoArgsConstructor -public class SeatEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class SeatEntity extends BaseEntity { @Column(name = "stadium_id", nullable = false) private Long stadiumId; @@ -35,19 +31,8 @@ public class SeatEntity { @Column(name = "seat_number", nullable = false) private Integer seatNumber; - public SeatEntity( - Long id, Long stadiumId, Long sectionId, Long blockId, Long rowId, Integer seatNumber) { - this.id = id; - this.stadiumId = stadiumId; - this.sectionId = sectionId; - this.blockId = blockId; - this.rowId = rowId; - this.seatNumber = seatNumber; - } - public static SeatEntity from(Seat seat) { return new SeatEntity( - seat.getId(), seat.getStadiumId(), seat.getSectionId(), seat.getBlockId(), @@ -56,6 +41,6 @@ public static SeatEntity from(Seat seat) { } public Seat toDomain() { - return new Seat(id, stadiumId, sectionId, blockId, rowId, seatNumber); + return new Seat(this.getId(), stadiumId, sectionId, blockId, rowId, seatNumber); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/entity/SectionEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/entity/SectionEntity.java index 4bd16dd1..eba0428c 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/entity/SectionEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/entity/SectionEntity.java @@ -2,24 +2,20 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.common.RgbCode; import org.depromeet.spot.domain.section.Section; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "sections") @NoArgsConstructor -public class SectionEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class SectionEntity extends BaseEntity { @Column(name = "stadium_id", nullable = false) private Long stadiumId; @@ -39,27 +35,9 @@ public class SectionEntity { @Column(name = "blue") private Integer blue; - public SectionEntity( - Long id, - Long stadiumId, - String name, - String alias, - Integer red, - Integer green, - Integer blue) { - this.id = id; - this.stadiumId = stadiumId; - this.name = name; - this.alias = alias; - this.red = red; - this.green = green; - this.blue = blue; - } - public static SectionEntity from(Section section) { RgbCode labelRgbCode = section.getLabelRgbCode(); return new SectionEntity( - section.getId(), section.getStadiumId(), section.getName(), section.getAlias(), @@ -70,6 +48,6 @@ public static SectionEntity from(Section section) { public Section toDomain() { RgbCode rgbCode = RgbCode.builder().red(red).green(green).blue(blue).build(); - return new Section(id, stadiumId, name, alias, rgbCode); + return new Section(this.getId(), stadiumId, name, alias, rgbCode); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionJpaRepository.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionJpaRepository.java index f11e6885..96cce20e 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionJpaRepository.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionJpaRepository.java @@ -8,4 +8,6 @@ public interface SectionJpaRepository extends JpaRepository { List findAllByStadiumId(Long stadiumId); + + boolean existsByStadiumIdAndId(Long stadiumId, Long id); } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionRepositoryImpl.java index bdaa5811..97c20a0b 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionRepositoryImpl.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/section/repository/SectionRepositoryImpl.java @@ -26,4 +26,9 @@ public Section save(Section section) { // TODO: test를 위해 추가 -> 구역 생성 티켓 작업할 때 구현 예정 return null; } + + @Override + public boolean existsInStadium(Long stadiumId, Long sectionId) { + return sectionJpaRepository.existsByStadiumIdAndId(stadiumId, sectionId); + } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/entity/StadiumEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/entity/StadiumEntity.java index 0f0589a8..1041d101 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/entity/StadiumEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/entity/StadiumEntity.java @@ -2,23 +2,19 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.stadium.Stadium; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "stadiums") @NoArgsConstructor -public class StadiumEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class StadiumEntity extends BaseEntity { @Column(name = "name", nullable = false, length = 50) private String name; @@ -35,24 +31,8 @@ public class StadiumEntity { @Column(name = "is_active", nullable = false) private boolean isActive; - public StadiumEntity( - Long id, - String name, - String mainImage, - String seatingChartImage, - String labeledSeatingChartImage, - boolean isActive) { - this.id = id; - this.name = name; - this.mainImage = mainImage; - this.seatingChartImage = seatingChartImage; - this.labeledSeatingChartImage = labeledSeatingChartImage; - this.isActive = isActive; - } - public static StadiumEntity from(Stadium stadium) { return new StadiumEntity( - stadium.getId(), stadium.getName(), stadium.getMainImage(), stadium.getSeatingChartImage(), @@ -62,7 +42,7 @@ public static StadiumEntity from(Stadium stadium) { public Stadium toDomain() { return Stadium.builder() - .id(id) + .id(this.getId()) .name(name) .mainImage(mainImage) .seatingChartImage(seatingChartImage) diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/repository/StadiumRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/repository/StadiumRepositoryImpl.java index 0a7b6084..a3f896ee 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/repository/StadiumRepositoryImpl.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/stadium/repository/StadiumRepositoryImpl.java @@ -35,4 +35,9 @@ public Stadium save(Stadium stadium) { // TODO: test를 위해 추가 -> 구장 저장 API 티켓때 구현 예정 return null; } + + @Override + public boolean existsById(final Long id) { + return stadiumJpaRepository.existsById(id); + } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/BaseballTeamEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/BaseballTeamEntity.java index 53d7e4d9..de8d4723 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/BaseballTeamEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/BaseballTeamEntity.java @@ -2,24 +2,20 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.common.RgbCode; import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "baseball_teams") @NoArgsConstructor -public class BaseballTeamEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class BaseballTeamEntity extends BaseEntity { @Column(name = "name", nullable = false, length = 20) private String name; @@ -39,27 +35,9 @@ public class BaseballTeamEntity { @Column(name = "blue") private Integer blue; - public BaseballTeamEntity( - Long id, - String name, - String alias, - String logo, - Integer red, - Integer green, - Integer blue) { - this.id = id; - this.name = name; - this.alias = alias; - this.logo = logo; - this.red = red; - this.green = green; - this.blue = blue; - } - public static BaseballTeamEntity from(BaseballTeam baseballTeam) { RgbCode labelRgbCode = baseballTeam.getLabelRgbCode(); return new BaseballTeamEntity( - baseballTeam.getId(), baseballTeam.getName(), baseballTeam.getAlias(), baseballTeam.getLogo(), @@ -70,6 +48,6 @@ public static BaseballTeamEntity from(BaseballTeam baseballTeam) { public BaseballTeam toDomain() { RgbCode labelRgbCode = RgbCode.builder().red(red).green(green).blue(blue).build(); - return new BaseballTeam(id, name, alias, logo, labelRgbCode); + return new BaseballTeam(this.getId(), name, alias, logo, labelRgbCode); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/StadiumHomeTeamEntity.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/StadiumHomeTeamEntity.java index ae241d40..a98fee4e 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/StadiumHomeTeamEntity.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/entity/StadiumHomeTeamEntity.java @@ -2,23 +2,19 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Table; import org.depromeet.spot.domain.team.StadiumHomeTeam; +import org.depromeet.spot.jpa.common.entity.BaseEntity; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity @Table(name = "stadium_home_teams") @NoArgsConstructor -public class StadiumHomeTeamEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; +@AllArgsConstructor +public class StadiumHomeTeamEntity extends BaseEntity { @Column(name = "stadium_id", nullable = false) private Long stadiumId; @@ -26,20 +22,12 @@ public class StadiumHomeTeamEntity { @Column(name = "team_id", nullable = false) private Long teamId; - public StadiumHomeTeamEntity(Long id, Long stadiumId, Long teamId) { - this.id = id; - this.stadiumId = stadiumId; - this.teamId = teamId; - } - public static StadiumHomeTeamEntity from(StadiumHomeTeam stadiumHomeTeam) { return new StadiumHomeTeamEntity( - stadiumHomeTeam.getId(), - stadiumHomeTeam.getStadiumId(), - stadiumHomeTeam.getTeamId()); + stadiumHomeTeam.getStadiumId(), stadiumHomeTeam.getTeamId()); } public StadiumHomeTeam toDomain() { - return new StadiumHomeTeam(id, stadiumId, teamId); + return new StadiumHomeTeam(this.getId(), stadiumId, teamId); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJdbcRepository.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJdbcRepository.java new file mode 100644 index 00000000..a54ecb84 --- /dev/null +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJdbcRepository.java @@ -0,0 +1,41 @@ +package org.depromeet.spot.jpa.team.repository; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; + +import org.depromeet.spot.domain.team.BaseballTeam; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class BaseballTeamJdbcRepository { + + private final JdbcTemplate jdbcTemplate; + + public void createBaseballTeams(List teams) { + jdbcTemplate.batchUpdate( + "insert into baseball_teams" + + "(name, alias, logo, red, green, blue) values (?, ?, ?, ?, ?, ?)", + new BatchPreparedStatementSetter() { + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + ps.setString(1, teams.get(i).getName()); + ps.setString(2, teams.get(i).getAlias()); + ps.setString(3, teams.get(i).getLogo()); + ps.setInt(4, teams.get(i).getLabelRgbCode().getRed()); + ps.setInt(5, teams.get(i).getLabelRgbCode().getGreen()); + ps.setInt(6, teams.get(i).getLabelRgbCode().getBlue()); + } + + @Override + public int getBatchSize() { + return teams.size(); + } + }); + } +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJpaRepository.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJpaRepository.java new file mode 100644 index 00000000..242c3837 --- /dev/null +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamJpaRepository.java @@ -0,0 +1,10 @@ +package org.depromeet.spot.jpa.team.repository; + +import java.util.List; + +import org.depromeet.spot.jpa.team.entity.BaseballTeamEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BaseballTeamJpaRepository extends JpaRepository { + boolean existsByNameIn(List names); +} diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamRepositoryImpl.java index dfb99f6b..13cb6db4 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamRepositoryImpl.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/team/repository/BaseballTeamRepositoryImpl.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.depromeet.spot.common.exception.team.TeamException.BaseballTeamNotFoundException; import org.depromeet.spot.domain.stadium.Stadium; import org.depromeet.spot.domain.team.BaseballTeam; import org.depromeet.spot.jpa.stadium.entity.StadiumEntity; @@ -18,6 +19,23 @@ public class BaseballTeamRepositoryImpl implements BaseballTeamRepository { private final StadiumHomeTeamCustomRepository stadiumHomeTeamCustomRepository; + private final BaseballTeamJpaRepository baseballTeamJpaRepository; + private final BaseballTeamJdbcRepository baseballTeamJdbcRepository; + + @Override + public BaseballTeam findById(final Long id) { + BaseballTeamEntity entity = + baseballTeamJpaRepository + .findById(id) + .orElseThrow(BaseballTeamNotFoundException::new); + return entity.toDomain(); + } + + @Override + public List findAll() { + List entities = baseballTeamJpaRepository.findAll(); + return entities.stream().map(BaseballTeamEntity::toDomain).toList(); + } @Override public List findAllHomeTeamByStadium(final Long stadiumId) { @@ -39,4 +57,19 @@ public Map> findAllStadiumHomeTeam() { .map(BaseballTeamEntity::toDomain) .toList())); } + + @Override + public void saveAll(List teams) { + baseballTeamJdbcRepository.createBaseballTeams(teams); + } + + @Override + public void createHomeTeam(Long stadiumId, List teamIds) { + // TODO: 홈 팀 등록할 때 구현 예정 + } + + @Override + public boolean existsByNameIn(List names) { + return baseballTeamJpaRepository.existsByNameIn(names); + } } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/block/BlockReadUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/block/BlockReadUsecase.java new file mode 100644 index 00000000..1d439fac --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/block/BlockReadUsecase.java @@ -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 findCodeInfosByStadium(Long stadiumId, Long sectionId); + + @Getter + @AllArgsConstructor + class BlockCodeInfo { + private final Long id; + private final String code; + } +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/section/SectionReadUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/section/SectionReadUsecase.java index 45154cb6..727a10aa 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/section/SectionReadUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/section/SectionReadUsecase.java @@ -13,6 +13,8 @@ public interface SectionReadUsecase { StadiumSections findAllByStadium(Long stadiumId); + boolean existsInStadium(Long stadiumId, Long sectionId); + @Getter @AllArgsConstructor class StadiumSections { diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/stadium/StadiumReadUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/stadium/StadiumReadUsecase.java index b9ddb20b..7557c46e 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/stadium/StadiumReadUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/stadium/StadiumReadUsecase.java @@ -3,7 +3,7 @@ import java.util.List; import org.depromeet.spot.domain.stadium.Stadium; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase.HomeTeamInfo; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase.HomeTeamInfo; import lombok.AllArgsConstructor; import lombok.Builder; @@ -19,6 +19,8 @@ public interface StadiumReadUsecase { Stadium findById(Long id); + boolean existsById(Long id); + @Getter @AllArgsConstructor class StadiumHomeTeamInfo { diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/CreateBaseballTeamUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/CreateBaseballTeamUsecase.java new file mode 100644 index 00000000..ca544e0b --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/CreateBaseballTeamUsecase.java @@ -0,0 +1,10 @@ +package org.depromeet.spot.usecase.port.in.team; + +import java.util.List; + +import org.depromeet.spot.domain.team.BaseballTeam; + +public interface CreateBaseballTeamUsecase { + + void saveAll(List teams); +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadBaseballTeamUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadBaseballTeamUsecase.java new file mode 100644 index 00000000..700045de --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadBaseballTeamUsecase.java @@ -0,0 +1,10 @@ +package org.depromeet.spot.usecase.port.in.team; + +import java.util.List; + +import org.depromeet.spot.domain.team.BaseballTeam; + +public interface ReadBaseballTeamUsecase { + + List findAll(); +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/StadiumHomeTeamReadUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadStadiumHomeTeamUsecase.java similarity index 92% rename from usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/StadiumHomeTeamReadUsecase.java rename to usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadStadiumHomeTeamUsecase.java index 4174cf96..78b1236e 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/StadiumHomeTeamReadUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadStadiumHomeTeamUsecase.java @@ -10,7 +10,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; -public interface StadiumHomeTeamReadUsecase { +public interface ReadStadiumHomeTeamUsecase { List findByStadium(Long stadiumId); diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/block/BlockRepository.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/block/BlockRepository.java new file mode 100644 index 00000000..b146f7d9 --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/block/BlockRepository.java @@ -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 findAllBySection(Long sectionId); +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/section/SectionRepository.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/section/SectionRepository.java index 5a6004c9..9e960c1b 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/section/SectionRepository.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/section/SectionRepository.java @@ -9,4 +9,6 @@ public interface SectionRepository { List
findAllByStadium(Long stadiumId); Section save(Section section); + + boolean existsInStadium(Long stadiumId, Long sectionId); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/stadium/StadiumRepository.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/stadium/StadiumRepository.java index 4212ff6e..3f52f796 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/stadium/StadiumRepository.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/stadium/StadiumRepository.java @@ -10,4 +10,6 @@ public interface StadiumRepository { List findAll(); Stadium save(Stadium stadium); + + boolean existsById(Long id); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/BaseballTeamRepository.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/BaseballTeamRepository.java index 537e1911..f578e032 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/BaseballTeamRepository.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/BaseballTeamRepository.java @@ -7,8 +7,17 @@ import org.depromeet.spot.domain.team.BaseballTeam; public interface BaseballTeamRepository { + BaseballTeam findById(Long id); + + List findAll(); List findAllHomeTeamByStadium(Long stadiumId); Map> findAllStadiumHomeTeam(); + + void saveAll(List teams); + + void createHomeTeam(Long stadiumId, List teamIds); + + boolean existsByNameIn(List names); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/block/BlockReadService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/block/BlockReadService.java new file mode 100644 index 00000000..4e0336cc --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/block/BlockReadService.java @@ -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 findCodeInfosByStadium(final Long stadiumId, final Long sectionId) { + if (!stadiumReadUsecase.existsById(stadiumId)) { + throw new StadiumNotFoundException(); + } + if (!sectionReadUsecase.existsInStadium(stadiumId, sectionId)) { + throw new SectionNotBelongStadiumException(); + } + List blocks = blockRepository.findAllBySection(sectionId); + return blocks.stream().map(b -> new BlockCodeInfo(b.getId(), b.getCode())).toList(); + } +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/section/SectionReadService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/section/SectionReadService.java index daa49405..03f55aed 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/section/SectionReadService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/section/SectionReadService.java @@ -27,4 +27,9 @@ public StadiumSections findAllByStadium(final Long stadiumId) { List sectionInfos = sections.stream().map(SectionInfo::from).toList(); return new StadiumSections(stadium.getSeatingChartImage(), sectionInfos); } + + @Override + public boolean existsInStadium(final Long stadiumId, final Long sectionId) { + return sectionRepository.existsInStadium(stadiumId, sectionId); + } } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/stadium/StadiumReadService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/stadium/StadiumReadService.java index 0d07421c..4b062ae3 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/stadium/StadiumReadService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/stadium/StadiumReadService.java @@ -7,8 +7,8 @@ import org.depromeet.spot.domain.stadium.Stadium; import org.depromeet.spot.domain.team.BaseballTeam; import org.depromeet.spot.usecase.port.in.stadium.StadiumReadUsecase; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase.HomeTeamInfo; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase.HomeTeamInfo; import org.depromeet.spot.usecase.port.out.stadium.StadiumRepository; import org.springframework.stereotype.Service; @@ -20,13 +20,13 @@ @RequiredArgsConstructor public class StadiumReadService implements StadiumReadUsecase { - private final StadiumHomeTeamReadUsecase stadiumHomeTeamReadUsecase; + private final ReadStadiumHomeTeamUsecase readStadiumHomeTeamUsecase; private final StadiumRepository stadiumRepository; @Override public List findAllStadiums() { Map> stadiumHomeTeams = - stadiumHomeTeamReadUsecase.findAllStadiumHomeTeam(); + readStadiumHomeTeamUsecase.findAllStadiumHomeTeam(); return stadiumHomeTeams.entrySet().stream() .map( entry -> { @@ -61,7 +61,7 @@ public List findAllNames() { @Override public StadiumInfoWithSeatChart findWithSeatChartById(final Long id) { Stadium stadium = stadiumRepository.findById(id); - List homeTeams = stadiumHomeTeamReadUsecase.findByStadium(id); + List homeTeams = readStadiumHomeTeamUsecase.findByStadium(id); return StadiumInfoWithSeatChart.builder() .id(stadium.getId()) .name(stadium.getName()) @@ -74,4 +74,9 @@ public StadiumInfoWithSeatChart findWithSeatChartById(final Long id) { public Stadium findById(final Long id) { return stadiumRepository.findById(id); } + + @Override + public boolean existsById(final Long id) { + return stadiumRepository.existsById(id); + } } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamService.java new file mode 100644 index 00000000..2c9414af --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamService.java @@ -0,0 +1,29 @@ +package org.depromeet.spot.usecase.service.team; + +import java.util.List; + +import org.depromeet.spot.common.exception.team.TeamException.DuplicateTeamNameException; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.port.in.team.CreateBaseballTeamUsecase; +import org.depromeet.spot.usecase.port.out.team.BaseballTeamRepository; +import org.springframework.stereotype.Service; + +import lombok.Builder; +import lombok.RequiredArgsConstructor; + +@Service +@Builder +@RequiredArgsConstructor +public class CreateBaseballTeamService implements CreateBaseballTeamUsecase { + + private final BaseballTeamRepository baseballTeamRepository; + + @Override + public void saveAll(List teams) { + List names = teams.stream().map(BaseballTeam::getName).toList(); + if (baseballTeamRepository.existsByNameIn(names)) { + throw new DuplicateTeamNameException(); + } + baseballTeamRepository.saveAll(teams); + } +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamService.java new file mode 100644 index 00000000..c7e69932 --- /dev/null +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamService.java @@ -0,0 +1,24 @@ +package org.depromeet.spot.usecase.service.team; + +import java.util.List; + +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.port.in.team.ReadBaseballTeamUsecase; +import org.depromeet.spot.usecase.port.out.team.BaseballTeamRepository; +import org.springframework.stereotype.Service; + +import lombok.Builder; +import lombok.RequiredArgsConstructor; + +@Service +@Builder +@RequiredArgsConstructor +public class ReadBaseballTeamService implements ReadBaseballTeamUsecase { + + private final BaseballTeamRepository baseballTeamRepository; + + @Override + public List findAll() { + return baseballTeamRepository.findAll(); + } +} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/team/StadiumHomeTeamReadService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadStadiumHomeTeamService.java similarity index 85% rename from usecase/src/main/java/org/depromeet/spot/usecase/service/team/StadiumHomeTeamReadService.java rename to usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadStadiumHomeTeamService.java index f9bb05cf..1ad2dbc4 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/team/StadiumHomeTeamReadService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/team/ReadStadiumHomeTeamService.java @@ -5,7 +5,7 @@ import org.depromeet.spot.domain.stadium.Stadium; import org.depromeet.spot.domain.team.BaseballTeam; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase; import org.depromeet.spot.usecase.port.out.team.BaseballTeamRepository; import org.springframework.stereotype.Service; @@ -13,7 +13,7 @@ @Service @RequiredArgsConstructor -public class StadiumHomeTeamReadService implements StadiumHomeTeamReadUsecase { +public class ReadStadiumHomeTeamService implements ReadStadiumHomeTeamUsecase { private final BaseballTeamRepository baseballTeamRepository; diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeBaseballTeamRepository.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeBaseballTeamRepository.java new file mode 100644 index 00000000..5db0b739 --- /dev/null +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeBaseballTeamRepository.java @@ -0,0 +1,95 @@ +package org.depromeet.spot.usecase.service.fake; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +import org.depromeet.spot.common.exception.team.TeamException.BaseballTeamNotFoundException; +import org.depromeet.spot.domain.stadium.Stadium; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.port.out.team.BaseballTeamRepository; + +public class FakeBaseballTeamRepository implements BaseballTeamRepository { + + private final AtomicLong autoGeneratedId = new AtomicLong(0); + private final List data = Collections.synchronizedList(new ArrayList<>()); + private final Map> homeTeamMap = + Collections.synchronizedMap(new HashMap<>()); + + @Override + public BaseballTeam findById(Long id) { + return getById(id).orElseThrow(BaseballTeamNotFoundException::new); + } + + private Optional getById(Long id) { + return data.stream().filter(team -> team.getId().equals(id)).findAny(); + } + + @Override + public List findAll() { + return data; + } + + @Override + public List findAllHomeTeamByStadium(Long stadiumId) { + return homeTeamMap.entrySet().stream() + .filter(entry -> stadiumId.equals(entry.getKey().getId())) + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toList()); + } + + @Override + public Map> findAllStadiumHomeTeam() { + return homeTeamMap; + } + + public BaseballTeam save(BaseballTeam team) { + if (team.getId() == null || team.getId() == 0) { + BaseballTeam newTeam = + BaseballTeam.builder() + .id(autoGeneratedId.incrementAndGet()) + .name(team.getName()) + .alias(team.getAlias()) + .logo(team.getLogo()) + .labelRgbCode(team.getLabelRgbCode()) + .build(); + data.add(newTeam); + return newTeam; + } else { + data.removeIf(item -> Objects.equals(item.getId(), team.getId())); + data.add(team); + return team; + } + } + + @Override + public void saveAll(List teams) { + teams.forEach(this::save); + } + + @Override + public void createHomeTeam(Long stadiumId, List teamIds) { + Stadium stadium = Stadium.builder().id(stadiumId).build(); + List newTeams = + teamIds.stream().map(t -> BaseballTeam.builder().id(t).build()).toList(); + + homeTeamMap.merge( + stadium, + newTeams, + (existingTeams, teams) -> { + existingTeams.addAll(teams); + return existingTeams; + }); + } + + @Override + public boolean existsByNameIn(List names) { + return data.stream().map(BaseballTeam::getName).anyMatch(names::contains); + } +} diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeSectionRepository.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeSectionRepository.java index d09bf0c9..ea7e0480 100644 --- a/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeSectionRepository.java +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeSectionRepository.java @@ -38,4 +38,11 @@ public Section save(Section section) { return section; } } + + @Override + public boolean existsInStadium(Long stadiumId, Long sectionId) { + return data.stream() + .filter(section -> section.getStadiumId().equals(sectionId)) + .anyMatch(section -> section.getId().equals(sectionId)); + } } diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeStadiumRepository.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeStadiumRepository.java index db1462b6..a3003010 100644 --- a/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeStadiumRepository.java +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeStadiumRepository.java @@ -50,4 +50,9 @@ public Stadium save(Stadium stadium) { return stadium; } } + + @Override + public boolean existsById(final Long id) { + return data.stream().anyMatch(stadium -> stadium.getId().equals(id)); + } } diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/section/SectionReadServiceTest.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/section/SectionReadServiceTest.java index ad16c44b..90ae1ff9 100644 --- a/usecase/src/test/java/org/depromeet/spot/usecase/service/section/SectionReadServiceTest.java +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/section/SectionReadServiceTest.java @@ -12,7 +12,7 @@ import org.depromeet.spot.domain.stadium.Stadium; import org.depromeet.spot.usecase.port.in.section.SectionReadUsecase.SectionInfo; import org.depromeet.spot.usecase.port.in.section.SectionReadUsecase.StadiumSections; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase; import org.depromeet.spot.usecase.service.fake.FakeSectionRepository; import org.depromeet.spot.usecase.service.fake.FakeStadiumRepository; import org.depromeet.spot.usecase.service.stadium.StadiumReadService; @@ -23,7 +23,7 @@ public class SectionReadServiceTest { private SectionReadService sectionReadService; private StadiumReadService stadiumReadService; - private StadiumHomeTeamReadUsecase stadiumHomeTeamReadUsecase; + private ReadStadiumHomeTeamUsecase readStadiumHomeTeamUsecase; @BeforeEach void init() { @@ -32,7 +32,7 @@ void init() { this.stadiumReadService = StadiumReadService.builder() - .stadiumHomeTeamReadUsecase(stadiumHomeTeamReadUsecase) + .readStadiumHomeTeamUsecase(readStadiumHomeTeamUsecase) .stadiumRepository(fakeStadiumRepository) .build(); diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/stadium/StadiumReadServiceTest.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/stadium/StadiumReadServiceTest.java index 0f35140f..7e42f1f8 100644 --- a/usecase/src/test/java/org/depromeet/spot/usecase/service/stadium/StadiumReadServiceTest.java +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/stadium/StadiumReadServiceTest.java @@ -7,7 +7,7 @@ import org.depromeet.spot.common.exception.stadium.StadiumException.StadiumNotFoundException; import org.depromeet.spot.domain.stadium.Stadium; -import org.depromeet.spot.usecase.port.in.team.StadiumHomeTeamReadUsecase; +import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase; import org.depromeet.spot.usecase.service.fake.FakeStadiumRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,7 +15,7 @@ class StadiumReadServiceTest { private StadiumReadService stadiumReadService; - private StadiumHomeTeamReadUsecase stadiumHomeTeamReadUsecase; + private ReadStadiumHomeTeamUsecase readStadiumHomeTeamUsecase; @BeforeEach void init() { @@ -23,7 +23,7 @@ void init() { this.stadiumReadService = StadiumReadService.builder() - .stadiumHomeTeamReadUsecase(stadiumHomeTeamReadUsecase) + .readStadiumHomeTeamUsecase(readStadiumHomeTeamUsecase) .stadiumRepository(fakeStadiumRepository) .build(); diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamServiceTest.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamServiceTest.java new file mode 100644 index 00000000..4d26f637 --- /dev/null +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/team/CreateBaseballTeamServiceTest.java @@ -0,0 +1,55 @@ +package org.depromeet.spot.usecase.service.team; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.List; + +import org.depromeet.spot.common.exception.team.TeamException.DuplicateTeamNameException; +import org.depromeet.spot.domain.common.RgbCode; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.service.fake.FakeBaseballTeamRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class CreateBaseballTeamServiceTest { + + private CreateBaseballTeamService createBaseballTeamService; + + @BeforeEach + void init() { + FakeBaseballTeamRepository fakeBaseballTeamRepository = new FakeBaseballTeamRepository(); + this.createBaseballTeamService = + CreateBaseballTeamService.builder() + .baseballTeamRepository(fakeBaseballTeamRepository) + .build(); + + BaseballTeam team = + BaseballTeam.builder() + .id(1L) + .name("두산 베어스") + .alias("두산") + .logo("logo1.png") + .labelRgbCode(new RgbCode(0, 0, 0)) + .build(); + fakeBaseballTeamRepository.save(team); + } + + @Test + void 이미_존재하는_이름의_구단을_중복_저장할_수_없다() { + // given + BaseballTeam team = + BaseballTeam.builder() + .id(1L) + .name("두산 베어스") + .alias("두산") + .logo("logo1.png") + .labelRgbCode(new RgbCode(0, 0, 0)) + .build(); + List teams = List.of(team); + + // when + // then + assertThatThrownBy(() -> createBaseballTeamService.saveAll(teams)) + .isInstanceOf(DuplicateTeamNameException.class); + } +} diff --git a/usecase/src/test/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamServiceTest.java b/usecase/src/test/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamServiceTest.java new file mode 100644 index 00000000..dcf55ede --- /dev/null +++ b/usecase/src/test/java/org/depromeet/spot/usecase/service/team/ReadBaseballTeamServiceTest.java @@ -0,0 +1,69 @@ +package org.depromeet.spot.usecase.service.team; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +import java.util.List; + +import org.depromeet.spot.domain.common.RgbCode; +import org.depromeet.spot.domain.team.BaseballTeam; +import org.depromeet.spot.usecase.service.fake.FakeBaseballTeamRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ReadBaseballTeamServiceTest { + + private ReadBaseballTeamService baseballTeamReadService; + + @BeforeEach + void init() { + FakeBaseballTeamRepository fakeBaseballTeamRepository = new FakeBaseballTeamRepository(); + this.baseballTeamReadService = + ReadBaseballTeamService.builder() + .baseballTeamRepository(fakeBaseballTeamRepository) + .build(); + + BaseballTeam team1 = + BaseballTeam.builder() + .id(1L) + .name("두산 베어스") + .alias("두산") + .logo("logo1.png") + .labelRgbCode(new RgbCode(0, 0, 0)) + .build(); + BaseballTeam team2 = + BaseballTeam.builder() + .id(2L) + .name("SSG 랜더스") + .alias("SSG") + .logo("logo2.png") + .labelRgbCode(new RgbCode(100, 0, 0)) + .build(); + + fakeBaseballTeamRepository.save(team1); + fakeBaseballTeamRepository.save(team2); + } + + @Test + void findAll_은_모든_구단을_반환한다() { + // given + // when + List teams = baseballTeamReadService.findAll(); + + // then + assertAll( + () -> assertThat(teams).hasSize(2), + () -> + assertThat(teams) + .anyMatch( + team -> + team.getId().equals(1L) + && team.getName().equals("두산 베어스")), + () -> + assertThat(teams) + .anyMatch( + team -> + team.getId().equals(2L) + && team.getName().equals("SSG 랜더스"))); + } +}