Skip to content

Commit

Permalink
Merge branch 'main' into feat/BSVR-118
Browse files Browse the repository at this point in the history
  • Loading branch information
pminsung12 authored Jul 15, 2024
2 parents dfea456 + 68ce52b commit 4ba4f51
Show file tree
Hide file tree
Showing 55 changed files with 1,093 additions and 228 deletions.
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();
}
}
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());
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
@@ -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<CreateBaseballTeamReq> requests) {
List<BaseballTeam> teams = requests.stream().map(CreateBaseballTeamReq::toDomain).toList();
createBaseballTeamUsecase.saveAll(teams);
}
}
Original file line number Diff line number Diff line change
@@ -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<BaseballTeamLogoRes> findAll() {
List<BaseballTeam> infos = readBaseballTeamUsecase.findAll();
return infos.stream().map(BaseballTeamLogoRes::from).toList();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
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;
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.List;


import lombok.Builder;
import lombok.Getter;

Expand All @@ -17,11 +18,13 @@ 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;
private final LocalDateTime updatedAt;
private final LocalDateTime deletedAt;
private final List<ReviewImage> images;
private final List<ReviewKeyword> keywords;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
Loading

0 comments on commit 4ba4f51

Please sign in to comment.