-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathPathFindService.java
More file actions
32 lines (25 loc) · 1.05 KB
/
PathFindService.java
File metadata and controls
32 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package nextstep.subway.path;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import nextstep.subway.line.domain.Sections;
import nextstep.subway.section.service.SectionReadService;
import nextstep.subway.station.domain.Station;
import nextstep.subway.support.ErrorCode;
import nextstep.subway.support.SubwayException;
@Service
@Slf4j
@RequiredArgsConstructor
public class PathFindService {
private final SectionReadService sectionReadService;
private final ShortestPathFinder shortestPathFinder;
@Transactional(readOnly = true)
public ShortestPath getPath(Station sourceStation, Station targetStation) {
if (sourceStation.equals(targetStation)) {
throw new SubwayException(ErrorCode.PATH_SOURCE_TARGET_SHOULD_DIFFERENT);
}
Sections allSections = new Sections(sectionReadService.getAll());
return shortestPathFinder.find(allSections, sourceStation, targetStation);
}
}