Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step3 3단계 요금 정책 추가 리뷰 부탁드립니다. #235

Open
wants to merge 28 commits into
base: chosundeveloper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dbde3a5
refactor : 클래스명 변경
chosundeveloper Aug 24, 2022
5c8f1a5
feat : lombok annotation
chosundeveloper Aug 27, 2022
f76c4e3
feat : 나이별 할인 정책
chosundeveloper Aug 27, 2022
8294a8b
feat : 노선별 추가 요금
chosundeveloper Aug 27, 2022
fbe215f
feat : Anonymous User
chosundeveloper Aug 28, 2022
9f89ff8
refactor : 정적 팩토리 메서드
chosundeveloper Aug 28, 2022
cb7efff
refactor : 경로 조회 시 로그인 정보 고려
chosundeveloper Aug 28, 2022
879f2c0
refactor : builder 사용
chosundeveloper Aug 28, 2022
2db0f8a
feat : 어린이, 청소년 유저 생성
chosundeveloper Aug 28, 2022
a0d425f
feat : 노선 요금
chosundeveloper Aug 28, 2022
b85f9a6
test : 구간별 추가 요금 반영
chosundeveloper Aug 28, 2022
98eccb0
feat : 청소년 / 어린이 / 성인 AcceptanceTest 추가
chosundeveloper Sep 11, 2022
f353260
refactor : Authentication return type 변경 AnonymousUser -> User
chosundeveloper Sep 17, 2022
ce8b415
refactor : 패키지 이동
chosundeveloper Sep 17, 2022
40b1c22
test : 나이별 요금 할인
chosundeveloper Sep 18, 2022
57ea144
test : 구간 거리별 요금 경계값 추가
chosundeveloper Sep 18, 2022
4e7d2ce
refactor : 경로 조회 테스트 로직 변경 반영
chosundeveloper Sep 18, 2022
d428c25
feat : 요금 계산 로직 수정
chosundeveloper Sep 18, 2022
c8421d0
feat : duration 파라미터 포함
chosundeveloper Sep 18, 2022
71ea5b5
test : token 포함된 step 추가
chosundeveloper Sep 18, 2022
3025719
test : 요금 정책 인수테스트 추가
chosundeveloper Sep 18, 2022
007a470
refactor : 노선 추가 요금 stream 사용
chosundeveloper Sep 18, 2022
a961cc1
feat : dataLoader 청소년 성인 추가
chosundeveloper Sep 23, 2022
ef3ac97
feat : Anonymous -> Guest로 변경
chosundeveloper Sep 23, 2022
44d9e45
test : 라인별 추가 요금
chosundeveloper Sep 18, 2022
2465ceb
refactor(Path.java) : 요금 계산 클래스 생성
chosundeveloper Oct 16, 2022
b210739
test(LineExtraFareTest.java) : fare생성 메서드 추가
chosundeveloper Oct 16, 2022
d2aaaaf
test(SubwayMapTest.java) : fare 생성 메서드
chosundeveloper Oct 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured:4.2.0'

runtimeOnly 'com.h2database:h2'

annotationProcessor 'org.projectlombok:lombok'
}

ext {
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/nextstep/DataLoader.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package nextstep;

import lombok.RequiredArgsConstructor;
import nextstep.member.domain.Member;
import nextstep.member.domain.MemberRepository;
import nextstep.member.domain.RoleType;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@RequiredArgsConstructor
@Component
public class DataLoader {
private MemberRepository memberRepository;

public DataLoader(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}
private final MemberRepository memberRepository;

public void loadData() {
memberRepository.save(new Member("[email protected]", "password", 20, Arrays.asList(RoleType.ROLE_ADMIN.name())));
memberRepository.save(new Member("[email protected]", "password", 20, Arrays.asList(RoleType.ROLE_MEMBER.name())));
memberRepository.save(new Member("[email protected]", "password", 20, List.of(RoleType.ROLE_ADMIN.name())));
memberRepository.save(new Member("[email protected]", "password", 20, List.of(RoleType.ROLE_MEMBER.name())));
memberRepository.save(new Member("[email protected]", "password", 20, List.of(RoleType.ROLE_MEMBER.name())));
memberRepository.save(new Member("[email protected]", "password", 18, List.of(RoleType.ROLE_MEMBER.name())));
memberRepository.save(new Member("[email protected]", "password", 12, List.of(RoleType.ROLE_MEMBER.name())));
}
}
13 changes: 13 additions & 0 deletions src/main/java/nextstep/member/domain/Guest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package nextstep.member.domain;

import lombok.NoArgsConstructor;

@NoArgsConstructor
public class Guest extends Member {

@Override
public Integer getAge() {
return Integer.MAX_VALUE;
}

}
6 changes: 3 additions & 3 deletions src/main/java/nextstep/subway/applicaion/FavoriteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import nextstep.subway.applicaion.dto.FavoriteRequest;
import nextstep.subway.applicaion.dto.FavoriteResponse;
import nextstep.subway.applicaion.dto.StationResponse;
import nextstep.subway.domain.Favorite;
import nextstep.subway.domain.FavoriteRepository;
import nextstep.subway.domain.Station;
import nextstep.subway.domain.favorite.Favorite;
import nextstep.subway.domain.favorite.FavoriteRepository;
import nextstep.subway.domain.station.Station;
import org.springframework.stereotype.Service;

import java.util.HashSet;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/nextstep/subway/applicaion/LineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import nextstep.subway.applicaion.dto.LineResponse;
import nextstep.subway.applicaion.dto.SectionRequest;
import nextstep.subway.applicaion.dto.StationResponse;
import nextstep.subway.domain.Line;
import nextstep.subway.domain.LineRepository;
import nextstep.subway.domain.Station;
import nextstep.subway.domain.line.Line;
import nextstep.subway.domain.line.LineRepository;
import nextstep.subway.domain.station.Station;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -26,7 +26,7 @@ public LineService(LineRepository lineRepository, StationService stationService)

@Transactional
public LineResponse saveLine(LineRequest request) {
Line line = lineRepository.save(new Line(request.getName(), request.getColor()));
Line line = lineRepository.save(new Line(request.getName(), request.getColor(), request.getAddFare()));
if (request.getUpStationId() != null && request.getDownStationId() != null && request.getDistance() != 0) {
Station upStation = stationService.findById(request.getUpStationId());
Station downStation = stationService.findById(request.getDownStationId());
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/nextstep/subway/applicaion/PathService.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package nextstep.subway.applicaion;

import lombok.RequiredArgsConstructor;
import nextstep.member.domain.Guest;
import nextstep.member.domain.Member;
import nextstep.member.domain.MemberRepository;
import nextstep.subway.applicaion.dto.PathResponse;
import nextstep.subway.domain.*;
import nextstep.subway.domain.SubwayMap;
import nextstep.subway.domain.fare.Fare;
import nextstep.subway.domain.line.Line;
import nextstep.subway.domain.path.Path;
import nextstep.subway.domain.path.PathType;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class PathService {
private LineService lineService;
private StationService stationService;
private final LineService lineService;
private final StationService stationService;
private final MemberRepository memberRepository;

public PathService(LineService lineService, StationService stationService) {
this.lineService = lineService;
this.stationService = stationService;
}

public PathResponse findPath(PathType pathType, Long source, Long target) {
Station upStation = stationService.findById(source);
Station downStation = stationService.findById(target);
public PathResponse findPath(PathType pathType, Long source, Long target, String userName) {
List<Line> lines = lineService.findLines();
SubwayMap subwayMap = SubwayMap.create(lines, pathType);
Path path = subwayMap.findPath(upStation, downStation);
return PathResponse.of(path);
Member member = memberRepository.findByEmail(userName).orElse(new Guest());
Path path = subwayMap.findPath(stationService.findById(source), stationService.findById(target));
Fare fare = new Fare(path.extractDistance(), path.getSections(), member.getAge());
return PathResponse.of(path, fare.calculate());
}
}
4 changes: 2 additions & 2 deletions src/main/java/nextstep/subway/applicaion/StationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import nextstep.subway.applicaion.dto.StationRequest;
import nextstep.subway.applicaion.dto.StationResponse;
import nextstep.subway.domain.Station;
import nextstep.subway.domain.StationRepository;
import nextstep.subway.domain.station.Station;
import nextstep.subway.domain.station.StationRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.subway.applicaion.dto;

import nextstep.subway.domain.Favorite;
import nextstep.subway.domain.favorite.Favorite;

public class FavoriteResponse {
private Long id;
Expand Down
27 changes: 4 additions & 23 deletions src/main/java/nextstep/subway/applicaion/dto/LineRequest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
package nextstep.subway.applicaion.dto;

import lombok.Getter;

@Getter
public class LineRequest {
private String name;
private String color;
private Long upStationId;
private Long downStationId;
private int distance;
private int duration;

public String getName() {
return name;
}

public String getColor() {
return color;
}

public Long getUpStationId() {
return upStationId;
}

public Long getDownStationId() {
return downStationId;
}

public int getDistance() {
return distance;
}
public int getDuration() {
return duration;
}
private int addFare;
}
16 changes: 3 additions & 13 deletions src/main/java/nextstep/subway/applicaion/dto/LineResponse.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package nextstep.subway.applicaion.dto;

import nextstep.subway.domain.Line;
import lombok.Getter;
import nextstep.subway.domain.line.Line;

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

@Getter
public class LineResponse {
private Long id;
private String name;
Expand All @@ -25,18 +27,6 @@ public LineResponse(Long id, String name, String color, List<StationResponse> st
this.stations = stations;
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

public String getColor() {
return color;
}

public List<StationResponse> getStations() {
return stations;
}
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/nextstep/subway/applicaion/dto/PathResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nextstep.subway.applicaion.dto;

import nextstep.subway.domain.Path;
import lombok.Builder;
import nextstep.subway.domain.path.Path;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -11,21 +12,27 @@ public class PathResponse {
private int duration;
private int fare;

@Builder
public PathResponse(List<StationResponse> stations, int distance, int duration, int fare) {
this.stations = stations;
this.distance = distance;
this.duration = duration;
this.fare = fare;
}

public static PathResponse of(Path path) {
public static PathResponse of(Path path, int fare) {

List<StationResponse> stations = path.getStations().stream()
.map(StationResponse::of)
.collect(Collectors.toList());
int distance = path.extractDistance();
int duration = path.extractDuration();
int fare = path.extractFare();
return new PathResponse(stations, distance, duration, fare);

return PathResponse
.builder()
.stations(stations)
.distance(path.extractDistance())
.duration(path.extractDuration())
.fare(fare)
.build();
}

public List<StationResponse> getStations() {
Expand All @@ -35,9 +42,11 @@ public List<StationResponse> getStations() {
public int getDistance() {
return distance;
}

public int getDuration() {
return duration;
}

public int getFare() {
return fare;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public SectionRequest(Long upStationId, Long downStationId, int distance, int du
this.upStationId = upStationId;
this.downStationId = downStationId;
this.distance = distance;
this.duration = duration;
}

public Long getUpStationId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.subway.applicaion.dto;

import nextstep.subway.domain.Station;
import nextstep.subway.domain.station.Station;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/nextstep/subway/domain/DefaultFarePolicy.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/nextstep/subway/domain/DistanceFarePolicy.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/nextstep/subway/domain/ExceedDistanceFarePolicy.java

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/nextstep/subway/domain/SectionEdge.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nextstep.subway.domain;

import nextstep.subway.domain.line.Section;
import org.jgrapht.graph.DefaultWeightedEdge;

public class SectionEdge extends DefaultWeightedEdge {
Expand Down
Loading