Skip to content

Commit

Permalink
Merge branch 'main' into feat/BSVR-225
Browse files Browse the repository at this point in the history
  • Loading branch information
pminsung12 authored Aug 21, 2024
2 parents 6f02847 + 705406e commit 58236ac
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.depromeet.spot.application.stadium.dto.response;

import java.util.List;

import org.depromeet.spot.usecase.port.in.stadium.StadiumReadUsecase.StadiumBlockTagInfo;

public record StadiumBlockTagResponse(
long id, String name, List<String> blockCodes, String description) {
public static StadiumBlockTagResponse from(StadiumBlockTagInfo info) {
return new StadiumBlockTagResponse(
info.getId(), info.getName(), info.getBlockCodes(), info.getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public record StadiumInfoWithSeatChartResponse(
String name,
String seatChartWithLabel,
String thumbnail,
List<HomeTeamInfoResponse> homeTeams) {
List<HomeTeamInfoResponse> homeTeams,
List<StadiumSectionInfoResponse> sections,
List<StadiumBlockTagResponse> blockTags) {

public static StadiumInfoWithSeatChartResponse from(
StadiumInfoWithSeatChart stadiumInfoWithSeatChart) {
Expand All @@ -21,11 +23,23 @@ public static StadiumInfoWithSeatChartResponse from(
.map(HomeTeamInfoResponse::from)
.toList();

List<StadiumSectionInfoResponse> sections =
stadiumInfoWithSeatChart.getSections().stream()
.map(StadiumSectionInfoResponse::from)
.toList();

List<StadiumBlockTagResponse> blockTags =
stadiumInfoWithSeatChart.getBlockTags().stream()
.map(StadiumBlockTagResponse::from)
.toList();

return new StadiumInfoWithSeatChartResponse(
stadiumInfoWithSeatChart.getId(),
stadiumInfoWithSeatChart.getName(),
stadiumInfoWithSeatChart.getSeatChartWithLabel(),
stadiumInfoWithSeatChart.getThumbnail(),
homeTeams);
homeTeams,
sections,
blockTags);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.depromeet.spot.application.stadium.dto.response;

import org.depromeet.spot.usecase.port.in.stadium.StadiumReadUsecase.StadiumSectionInfo;

public record StadiumSectionInfoResponse(long id, String name, String alias) {
public static StadiumSectionInfoResponse from(StadiumSectionInfo info) {
return new StadiumSectionInfoResponse(info.getId(), info.getName(), info.getAlias());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.depromeet.spot.infrastructure.jpa.hashtag.entity.HashTagEntity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "block_tags")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.depromeet.spot.infrastructure.jpa.block.repository.tag;

import static org.depromeet.spot.infrastructure.jpa.block.entity.QBlockEntity.blockEntity;
import static org.depromeet.spot.infrastructure.jpa.block.entity.QBlockTagEntity.blockTagEntity;
import static org.depromeet.spot.infrastructure.jpa.hashtag.entity.QHashTagEntity.hashTagEntity;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.depromeet.spot.infrastructure.jpa.block.entity.BlockEntity;
import org.depromeet.spot.infrastructure.jpa.block.entity.BlockTagEntity;
import org.depromeet.spot.infrastructure.jpa.hashtag.entity.HashTagEntity;
import org.springframework.stereotype.Repository;

import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class BlockTagCustomRepository {

private final JPAQueryFactory queryFactory;

public Map<HashTagEntity, List<BlockEntity>> findAllByStadium(Long stadiumId) {
List<BlockTagEntity> blockTagEntities =
queryFactory
.selectFrom(blockTagEntity)
.join(blockTagEntity.block, blockEntity)
.fetchJoin()
.join(blockTagEntity.hashTag, hashTagEntity)
.fetchJoin()
.where(blockEntity.stadiumId.eq(stadiumId))
.fetch();

return blockTagEntities.stream()
.collect(
Collectors.groupingBy(
BlockTagEntity::getHashTag,
Collectors.mapping(BlockTagEntity::getBlock, Collectors.toList())));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.depromeet.spot.infrastructure.jpa.block.repository.tag;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.domain.hashtag.HashTag;
import org.depromeet.spot.infrastructure.jpa.block.entity.BlockEntity;
import org.depromeet.spot.infrastructure.jpa.hashtag.entity.HashTagEntity;
import org.depromeet.spot.usecase.port.out.block.BlockTagRepository;
import org.springframework.stereotype.Repository;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class BlockTagRepositoryImpl implements BlockTagRepository {

private final BlockTagCustomRepository blockTagCustomRepository;

@Override
public Map<HashTag, List<Block>> findAllByStadium(Long stadiumId) {
Map<HashTagEntity, List<BlockEntity>> entities =
blockTagCustomRepository.findAllByStadium(stadiumId);
return entities.entrySet().stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toDomain(),
entry ->
entry.getValue().stream()
.map(BlockEntity::toDomain)
.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ReviewImageEntity extends BaseEntity {
foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private ReviewEntity review;

@Column(name = "url", nullable = false, length = 255)
@Column(name = "url", nullable = false, length = 1000)
private String url;

public ReviewImage toDomain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.depromeet.spot.usecase.port.in.block;

import java.util.List;
import java.util.Map;

import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.domain.hashtag.HashTag;

public interface ReadBlockTagUsecase {

Map<HashTag, List<Block>> findAllByStadium(Long stadiumId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

public interface SectionReadUsecase {

List<Section> findAllBy(Long stadiumId);

StadiumSections findAllByStadium(Long stadiumId);

boolean existsInStadium(Long stadiumId, Long sectionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.depromeet.spot.domain.section.Section;
import org.depromeet.spot.domain.stadium.Stadium;
import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase.HomeTeamInfo;

Expand Down Expand Up @@ -42,6 +43,8 @@ class StadiumInfoWithSeatChart {
private final List<HomeTeamInfo> homeTeams;
private final String seatChartWithLabel;
private final String thumbnail;
private final List<StadiumSectionInfo> sections;
private final List<StadiumBlockTagInfo> blockTags;
}

@Getter
Expand All @@ -51,4 +54,25 @@ class StadiumNameInfo {
private final String name;
private final boolean isActive;
}

@Getter
@AllArgsConstructor
class StadiumSectionInfo {
private final long id;
private final String name;
private final String alias;

public static StadiumSectionInfo from(Section section) {
return new StadiumSectionInfo(section.getId(), section.getName(), section.getAlias());
}
}

@Getter
@Builder
class StadiumBlockTagInfo {
private final long id;
private final String name;
private final List<String> blockCodes;
private final String description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.depromeet.spot.usecase.port.out.block;

import java.util.List;
import java.util.Map;

import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.domain.hashtag.HashTag;

public interface BlockTagRepository {

Map<HashTag, List<Block>> findAllByStadium(Long stadiumId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.depromeet.spot.usecase.service.block;

import java.util.List;
import java.util.Map;

import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.domain.hashtag.HashTag;
import org.depromeet.spot.usecase.port.in.block.ReadBlockTagUsecase;
import org.depromeet.spot.usecase.port.out.block.BlockTagRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ReadBlockTagService implements ReadBlockTagUsecase {

private final BlockTagRepository blockTagRepository;

@Override
public Map<HashTag, List<Block>> findAllByStadium(final Long stadiumId) {
return blockTagRepository.findAllByStadium(stadiumId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ReviewImageProcessor {
public List<String> getImageUrl(List<MultipartFile> images) {
List<String> urls = new ArrayList<>();
for (MultipartFile image : images) {
String name = image.getName();
String name = image.getOriginalFilename();
urls.add(imageUploadPort.upload(name, image, MediaProperty.REVIEW));
}
return urls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class SectionReadService implements SectionReadUsecase {
private final StadiumReadUsecase stadiumReadUsecase;
private final SectionRepository sectionRepository;

@Override
public List<Section> findAllBy(final Long stadiumId) {
return sectionRepository.findAllByStadium(stadiumId);
}

@Override
public StadiumSections findAllByStadium(final Long stadiumId) {
Stadium stadium = stadiumReadUsecase.findById(stadiumId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.depromeet.spot.common.exception.stadium.StadiumException.StadiumNotFoundException;
import org.depromeet.spot.domain.block.Block;
import org.depromeet.spot.domain.hashtag.HashTag;
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.ReadStadiumHomeTeamUsecase;
import org.depromeet.spot.usecase.port.in.team.ReadStadiumHomeTeamUsecase.HomeTeamInfo;
import org.depromeet.spot.usecase.port.out.section.SectionRepository;
import org.depromeet.spot.usecase.port.out.stadium.StadiumRepository;
import org.depromeet.spot.usecase.service.block.ReadBlockTagService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -25,6 +30,8 @@
public class StadiumReadService implements StadiumReadUsecase {

private final ReadStadiumHomeTeamUsecase readStadiumHomeTeamUsecase;
private final ReadBlockTagService readBlockTagService;
private final SectionRepository sectionRepository;
private final StadiumRepository stadiumRepository;

@Override
Expand Down Expand Up @@ -74,16 +81,40 @@ public List<StadiumNameInfo> findAllNames() {
@Override
public StadiumInfoWithSeatChart findWithSeatChartById(final Long id) {
Stadium stadium = stadiumRepository.findById(id);
List<StadiumSectionInfo> sections =
sectionRepository.findAllByStadium(id).stream()
.map(StadiumSectionInfo::from)
.toList();
List<HomeTeamInfo> homeTeams = readStadiumHomeTeamUsecase.findByStadium(id);
List<StadiumBlockTagInfo> blockTags = makeBlockTagInfoByStadium(id);
return StadiumInfoWithSeatChart.builder()
.id(stadium.getId())
.name(stadium.getName())
.homeTeams(homeTeams)
.thumbnail(stadium.getMainImage())
.seatChartWithLabel(stadium.getLabeledSeatingChartImage())
.sections(sections)
.blockTags(blockTags)
.build();
}

private List<StadiumBlockTagInfo> makeBlockTagInfoByStadium(final Long id) {
List<StadiumBlockTagInfo> result = new ArrayList<>();
Map<HashTag, List<Block>> blockTags = readBlockTagService.findAllByStadium(id);
for (Entry<HashTag, List<Block>> blockTag : blockTags.entrySet()) {
HashTag hashTag = blockTag.getKey();
List<Block> blocks = blockTag.getValue();
result.add(
StadiumBlockTagInfo.builder()
.id(hashTag.getId())
.name(hashTag.getName())
.description(hashTag.getDescription())
.blockCodes(blocks.stream().map(Block::getCode).toList())
.build());
}
return result;
}

@Override
public Stadium findById(final Long id) {
return stadiumRepository.findById(id);
Expand Down

0 comments on commit 58236ac

Please sign in to comment.