-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
248 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...tion/src/main/java/org/depromeet/spot/application/team/dto/request/CreateHomeTeamReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.depromeet.spot.application.team.dto.request; | ||
|
||
import java.util.Set; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public record CreateHomeTeamReq(@NotEmpty @NotNull Set<@Positive @NotNull Long> teamIds) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
domain/src/main/java/org/depromeet/spot/domain/team/StadiumHomeTeam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../src/main/java/org/depromeet/spot/jpa/team/repository/hometeam/HomeTeamJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.depromeet.spot.jpa.team.repository.hometeam; | ||
|
||
import org.depromeet.spot.jpa.team.entity.StadiumHomeTeamEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface HomeTeamJpaRepository extends JpaRepository<StadiumHomeTeamEntity, Long> {} |
52 changes: 52 additions & 0 deletions
52
...src/main/java/org/depromeet/spot/jpa/team/repository/hometeam/HomeTeamRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.depromeet.spot.jpa.team.repository.hometeam; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.depromeet.spot.domain.stadium.Stadium; | ||
import org.depromeet.spot.domain.team.BaseballTeam; | ||
import org.depromeet.spot.domain.team.StadiumHomeTeam; | ||
import org.depromeet.spot.jpa.stadium.entity.StadiumEntity; | ||
import org.depromeet.spot.jpa.team.entity.BaseballTeamEntity; | ||
import org.depromeet.spot.jpa.team.entity.StadiumHomeTeamEntity; | ||
import org.depromeet.spot.usecase.port.out.team.HomeTeamRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class HomeTeamRepositoryImpl implements HomeTeamRepository { | ||
|
||
private final StadiumHomeTeamCustomRepository stadiumHomeTeamCustomRepository; | ||
private final HomeTeamJpaRepository homeTeamJpaRepository; | ||
|
||
@Override | ||
public List<BaseballTeam> findAllHomeTeamByStadium(final Long stadiumId) { | ||
List<BaseballTeamEntity> homeTeamEntities = | ||
stadiumHomeTeamCustomRepository.findAllHomeTeamByStadium(stadiumId); | ||
return homeTeamEntities.stream().map(BaseballTeamEntity::toDomain).toList(); | ||
} | ||
|
||
@Override | ||
public Map<Stadium, List<BaseballTeam>> findAllStadiumHomeTeam() { | ||
Map<StadiumEntity, List<BaseballTeamEntity>> stadiumHomeTeamMap = | ||
stadiumHomeTeamCustomRepository.findAllStadiumHomeTeam(); | ||
return stadiumHomeTeamMap.entrySet().stream() | ||
.collect( | ||
Collectors.toMap( | ||
entry -> entry.getKey().toDomain(), | ||
entry -> | ||
entry.getValue().stream() | ||
.map(BaseballTeamEntity::toDomain) | ||
.toList())); | ||
} | ||
|
||
@Override | ||
public void saveAll(List<StadiumHomeTeam> homeTeams) { | ||
List<StadiumHomeTeamEntity> entities = | ||
homeTeams.stream().map(StadiumHomeTeamEntity::from).toList(); | ||
homeTeamJpaRepository.saveAll(entities); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tory/StadiumHomeTeamCustomRepository.java → ...team/StadiumHomeTeamCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/CreateHomeTeamUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.depromeet.spot.usecase.port.in.team; | ||
|
||
import java.util.Set; | ||
|
||
public interface CreateHomeTeamUsecase { | ||
|
||
void createHomeTeams(Long stadiumId, Set<Long> teamIds); | ||
} |
5 changes: 5 additions & 0 deletions
5
usecase/src/main/java/org/depromeet/spot/usecase/port/in/team/ReadBaseballTeamUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package org.depromeet.spot.usecase.port.in.team; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.depromeet.spot.domain.team.BaseballTeam; | ||
|
||
public interface ReadBaseballTeamUsecase { | ||
|
||
BaseballTeam findById(Long id); | ||
|
||
List<BaseballTeam> findAll(); | ||
|
||
void areAllTeamIdsExist(Set<Long> teamIds); | ||
} |
10 changes: 2 additions & 8 deletions
10
usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/BaseballTeamRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
package org.depromeet.spot.usecase.port.out.team; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.depromeet.spot.domain.stadium.Stadium; | ||
import org.depromeet.spot.domain.team.BaseballTeam; | ||
|
||
public interface BaseballTeamRepository { | ||
BaseballTeam findById(Long id); | ||
|
||
List<BaseballTeam> findAll(); | ||
|
||
List<BaseballTeam> findAllHomeTeamByStadium(Long stadiumId); | ||
|
||
Map<Stadium, List<BaseballTeam>> findAllStadiumHomeTeam(); | ||
|
||
void saveAll(List<BaseballTeam> teams); | ||
|
||
void createHomeTeam(Long stadiumId, List<Long> teamIds); | ||
|
||
boolean existsByNameIn(List<String> names); | ||
|
||
boolean existsById(Long id); | ||
} |
17 changes: 17 additions & 0 deletions
17
usecase/src/main/java/org/depromeet/spot/usecase/port/out/team/HomeTeamRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.depromeet.spot.usecase.port.out.team; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.depromeet.spot.domain.stadium.Stadium; | ||
import org.depromeet.spot.domain.team.BaseballTeam; | ||
import org.depromeet.spot.domain.team.StadiumHomeTeam; | ||
|
||
public interface HomeTeamRepository { | ||
|
||
List<BaseballTeam> findAllHomeTeamByStadium(Long stadiumId); | ||
|
||
Map<Stadium, List<BaseballTeam>> findAllStadiumHomeTeam(); | ||
|
||
void saveAll(List<StadiumHomeTeam> homeTeams); | ||
} |
38 changes: 38 additions & 0 deletions
38
usecase/src/main/java/org/depromeet/spot/usecase/service/team/CreateHomeTeamService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.depromeet.spot.usecase.service.team; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.depromeet.spot.domain.team.StadiumHomeTeam; | ||
import org.depromeet.spot.usecase.port.in.stadium.StadiumReadUsecase; | ||
import org.depromeet.spot.usecase.port.in.team.CreateHomeTeamUsecase; | ||
import org.depromeet.spot.usecase.port.in.team.ReadBaseballTeamUsecase; | ||
import org.depromeet.spot.usecase.port.out.team.HomeTeamRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CreateHomeTeamService implements CreateHomeTeamUsecase { | ||
|
||
private final HomeTeamRepository homeTeamRepository; | ||
private final StadiumReadUsecase stadiumReadUsecase; | ||
private final ReadBaseballTeamUsecase readBaseballTeamUsecase; | ||
|
||
@Override | ||
public void createHomeTeams(final Long stadiumId, Set<Long> teamIds) { | ||
stadiumReadUsecase.checkIsExistsBy(stadiumId); | ||
readBaseballTeamUsecase.areAllTeamIdsExist(teamIds); | ||
List<StadiumHomeTeam> homeTeams = new ArrayList<>(); | ||
teamIds.forEach( | ||
teamId -> | ||
homeTeams.add( | ||
StadiumHomeTeam.builder() | ||
.stadiumId(stadiumId) | ||
.teamId(teamId) | ||
.build())); | ||
homeTeamRepository.saveAll(homeTeams); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.