-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
135 additions
and
78 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
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
42 changes: 42 additions & 0 deletions
42
...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,42 @@ | ||
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.jpa.stadium.entity.StadiumEntity; | ||
import org.depromeet.spot.jpa.team.entity.BaseballTeamEntity; | ||
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; | ||
|
||
@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())); | ||
} | ||
} |
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.List; | ||
|
||
public interface CreateHomeTeamUsecase { | ||
|
||
void createHomeTeam(Long stadiumId, List<Long> teamIds); | ||
} |
8 changes: 0 additions & 8 deletions
8
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,15 @@ | ||
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); | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
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 HomeTeamRepository { | ||
|
||
List<BaseballTeam> findAllHomeTeamByStadium(Long stadiumId); | ||
|
||
Map<Stadium, List<BaseballTeam>> findAllStadiumHomeTeam(); | ||
} |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
package org.depromeet.spot.usecase.service.team; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.usecase.port.in.team.CreateHomeTeamUsecase; | ||
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; | ||
|
||
@Override | ||
public void createHomeTeam(Long stadiumId, List<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
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
33 changes: 33 additions & 0 deletions
33
usecase/src/test/java/org/depromeet/spot/usecase/service/fake/FakeHomeTeamRepository.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,33 @@ | ||
package org.depromeet.spot.usecase.service.fake; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.stream.Collectors; | ||
|
||
import org.depromeet.spot.domain.stadium.Stadium; | ||
import org.depromeet.spot.domain.team.BaseballTeam; | ||
import org.depromeet.spot.usecase.port.out.team.HomeTeamRepository; | ||
|
||
public class FakeHomeTeamRepository implements HomeTeamRepository { | ||
|
||
private final AtomicLong autoGeneratedId = new AtomicLong(0); | ||
|
||
private final Map<Stadium, List<BaseballTeam>> homeTeamMap = | ||
Collections.synchronizedMap(new HashMap<>()); | ||
|
||
@Override | ||
public List<BaseballTeam> 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<Stadium, List<BaseballTeam>> findAllStadiumHomeTeam() { | ||
return homeTeamMap; | ||
} | ||
} |