diff --git a/.env.sample b/.env.sample index 3505b912..6e3b542e 100644 --- a/.env.sample +++ b/.env.sample @@ -4,4 +4,6 @@ MYSQL_DATABASE=TALKKA_DB MYSQL_URL=jdbc:mysql://localhost:3306/TALKKA_DB?createDatabaseIfNotExist=true NAVER_CLIENT_ID=CLIENT_ID -NAVER_CLINET_SECRET=CLIENT_SECRET \ No newline at end of file +NAVER_CLINET_SECRET=CLIENT_SECRET + +SERVICE_KEY_1=SERVICE_KEY_1 \ No newline at end of file diff --git a/server/build.gradle b/server/build.gradle index bbcd336d..c27ae026 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -31,6 +31,9 @@ dependencies { // Thymeleaf 의 경우 테스트 혹은 관리자에서 추후에 사용하기 위해서 유지합니다. implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + // XML Parser + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml' + compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/server/src/main/java/com/talkka/server/api/core/config/ApiKeyProperty.java b/server/src/main/java/com/talkka/server/api/core/config/ApiKeyProperty.java new file mode 100644 index 00000000..114ce92d --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/core/config/ApiKeyProperty.java @@ -0,0 +1,5 @@ +package com.talkka.server.api.core.config; + +public interface ApiKeyProperty { + String getApiKey(); +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/config/BusApiKeyProperty.java b/server/src/main/java/com/talkka/server/api/datagg/config/BusApiKeyProperty.java new file mode 100644 index 00000000..d5ac166e --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/config/BusApiKeyProperty.java @@ -0,0 +1,27 @@ +package com.talkka.server.api.datagg.config; + +import java.util.List; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import com.talkka.server.api.core.config.ApiKeyProperty; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Component +@ConfigurationProperties(prefix = "openapi.public.bus.service-key") +public class BusApiKeyProperty implements ApiKeyProperty { + @Setter + private List keys; + + private int rollingKeyIndex = 0; + + @Override + public String getApiKey() { + rollingKeyIndex = (rollingKeyIndex + 1) % keys.size(); + return keys.get(rollingKeyIndex); + } +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationBodyDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationBodyDto.java new file mode 100644 index 00000000..ba14ecc8 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationBodyDto.java @@ -0,0 +1,8 @@ +package com.talkka.server.api.datagg.dto; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "busLocationList") +public record BusLocationBodyDto(String endBus, String lowPlate, String plateNo, String plateType, + Integer remainSeatCnt, Long routeId, Long stationId, Integer stationSeq) { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationRespDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationRespDto.java new file mode 100644 index 00000000..4a1b363e --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusLocationRespDto.java @@ -0,0 +1,14 @@ +package com.talkka.server.api.datagg.dto; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "response") +public record BusLocationRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map comMsgHeader, + @JacksonXmlProperty(localName = "msgHeader") Map msgHeader, + @JacksonXmlProperty(localName = "msgBody") List msgBody) + implements PublicBusApiResp { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoBodyDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoBodyDto.java new file mode 100644 index 00000000..f8859548 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoBodyDto.java @@ -0,0 +1,28 @@ +package com.talkka.server.api.datagg.dto; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "busRouteInfoItem") +public record BusRouteInfoBodyDto( + String companyId, // 운수업체 아이디 + String companyName, // 운수업체명 + String companyTel, // 운수업체 전화번호 + int districtCd, // 관할 지역 코드 + String downFirstTime, // 평일 종점 첫차 시간 + String downLastTime, // 평일 종점 막차 시간 + Long endStationId, // 종점 정류소 아이디 + String endStationName, // 종점 정류소명 + int peekAlloc, // 평일 최소 배차 시간 + String regionName, // 지역명 + Long routeId, // 노선 아이디 + String routeName, // 노선 번호 + int routeTypeCd, // 노선 유형 코드 + String routeTypeName, // 노선 유형명 + String startMobileNo, // 기점 정류소 번호 + Long startStationId, // 기점 정류소 아이디 + String startStationName, // 기점 정류소명 + String upFirstTime, // 평일 기점 첫차 시간 + String upLastTime, // 평일 기점 막차 시간 + int nPeekAlloc // 평일 최대 배차 시간 +) { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoRespDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoRespDto.java new file mode 100644 index 00000000..86fbe315 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteInfoRespDto.java @@ -0,0 +1,14 @@ +package com.talkka.server.api.datagg.dto; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "response") +public record BusRouteInfoRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map comMsgHeader, + @JacksonXmlProperty(localName = "msgHeader") Map msgHeader, + @JacksonXmlProperty(localName = "msgBody") List msgBody) + implements PublicBusApiResp { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchBodyDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchBodyDto.java new file mode 100644 index 00000000..e0b28bdf --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchBodyDto.java @@ -0,0 +1,15 @@ +package com.talkka.server.api.datagg.dto; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +/** + * @param routeId 노선 아이디 + * @param routeName 노선 번호 + * @param routeTypeCd 노선 유형 코드 + * @param routeTypeName 노선 유형명 + * @param regionName 노선 운행 지역 + * @param districtCd 노선 관할 지역 코드 */ +@JacksonXmlRootElement(localName = "busRouteList") +public record BusRouteSearchBodyDto(Long routeId, String routeName, String routeTypeCd, String routeTypeName, + String regionName, int districtCd) { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchRespDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchRespDto.java new file mode 100644 index 00000000..aa1407bf --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteSearchRespDto.java @@ -0,0 +1,14 @@ +package com.talkka.server.api.datagg.dto; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "response") +public record BusRouteSearchRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map comMsgHeader, + @JacksonXmlProperty(localName = "msgHeader") Map msgHeader, + @JacksonXmlProperty(localName = "msgBody") List msgBody) + implements PublicBusApiResp { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationBodyDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationBodyDto.java new file mode 100644 index 00000000..3098e42c --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationBodyDto.java @@ -0,0 +1,20 @@ +package com.talkka.server.api.datagg.dto; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +/** + * @param stationId 정류소 아이디 + * @param stationSeq 정류소 순번 + * @param stationName 정류소 명칭 + * @param mobileNo 정류소 고유 모바일 번호 + * @param regionName 정류소 위치 지역명 + * @param districtCd 노선 관할 지역 코드 + * @param centerYn 중앙차로 여부 (N: 일반, Y: 중앙차로) + * @param turnYn 회차점 여부 (N: 일반, Y: 회차점) + * @param x 정류소 X 좌표 + * @param y 정류소 Y 좌표 */ +@JacksonXmlRootElement(localName = "busRouteStationList") +public record BusRouteStationBodyDto(Long stationId, Integer stationSeq, String stationName, String mobileNo, + String regionName, String districtCd, String centerYn, String turnYn, Double x, + Double y) { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationRespDto.java b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationRespDto.java new file mode 100644 index 00000000..39625455 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/BusRouteStationRespDto.java @@ -0,0 +1,14 @@ +package com.talkka.server.api.datagg.dto; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "response") +public record BusRouteStationRespDto(@JacksonXmlProperty(localName = "comMsgHeader") Map comMsgHeader, + @JacksonXmlProperty(localName = "msgHeader") Map msgHeader, + @JacksonXmlProperty(localName = "msgBody") List msgBody) + implements PublicBusApiResp { +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/dto/PublicBusApiResp.java b/server/src/main/java/com/talkka/server/api/datagg/dto/PublicBusApiResp.java new file mode 100644 index 00000000..3125a1e8 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/dto/PublicBusApiResp.java @@ -0,0 +1,12 @@ +package com.talkka.server.api.datagg.dto; + +import java.util.List; +import java.util.Map; + +public interface PublicBusApiResp { + Map comMsgHeader(); + + Map msgHeader(); + + List msgBody(); +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/service/BusApiService.java b/server/src/main/java/com/talkka/server/api/datagg/service/BusApiService.java new file mode 100644 index 00000000..19ead347 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/service/BusApiService.java @@ -0,0 +1,20 @@ +package com.talkka.server.api.datagg.service; + +import java.util.List; + +import com.talkka.server.api.datagg.dto.BusLocationBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteInfoBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteSearchBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteStationBodyDto; + +public interface BusApiService { + List getSearchedRouteInfo(String routeName); + + List getRouteInfo(String apiRouteId); + + List getRouteStationInfo(String apiRouteId); + + List getBusLocationInfo(String apiRouteId); + + // List getBusStationArrivalInfo(String routeId); +} diff --git a/server/src/main/java/com/talkka/server/api/datagg/service/BusApiServiceImpl.java b/server/src/main/java/com/talkka/server/api/datagg/service/BusApiServiceImpl.java new file mode 100644 index 00000000..5d722a48 --- /dev/null +++ b/server/src/main/java/com/talkka/server/api/datagg/service/BusApiServiceImpl.java @@ -0,0 +1,88 @@ +package com.talkka.server.api.datagg.service; + +import java.net.URI; +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.DefaultUriBuilderFactory; + +import com.talkka.server.api.datagg.config.BusApiKeyProperty; +import com.talkka.server.api.datagg.dto.BusLocationBodyDto; +import com.talkka.server.api.datagg.dto.BusLocationRespDto; +import com.talkka.server.api.datagg.dto.BusRouteInfoBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteInfoRespDto; +import com.talkka.server.api.datagg.dto.BusRouteSearchBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteSearchRespDto; +import com.talkka.server.api.datagg.dto.BusRouteStationBodyDto; +import com.talkka.server.api.datagg.dto.BusRouteStationRespDto; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class BusApiServiceImpl implements BusApiService { + private final BusApiKeyProperty busApiKeyProperty; + private final RestTemplate restTemplate = new RestTemplate(); + private static final String host = "apis.data.go.kr"; + + @Override + public List getSearchedRouteInfo(String keyword) { + final String path = "/6410000/busrouteservice/getBusRouteList"; + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("keyword", keyword); + URI uri = this.getOpenApiURI(path, params); + ResponseEntity resp = restTemplate.getForEntity(uri, BusRouteSearchRespDto.class); + return resp.getBody().msgBody(); + } + + @Override + public List getRouteInfo(String apiRouteId) { + final String path = "/6410000/busrouteservice/getBusRouteInfoItem"; + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("routeId", apiRouteId); + URI uri = this.getOpenApiURI(path, params); + ResponseEntity resp = restTemplate.getForEntity(uri, BusRouteInfoRespDto.class); + return resp.getBody().msgBody(); + } + + @Override + public List getRouteStationInfo(String apiRouteId) { + final String path = "/6410000/busrouteservice/getBusRouteStationList"; + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("routeId", apiRouteId); + URI uri = this.getOpenApiURI(path, params); + ResponseEntity resp = restTemplate.getForEntity(uri, BusRouteStationRespDto.class); + return resp.getBody().msgBody(); + } + + @Override + public List getBusLocationInfo(String apiRouteId) { + final String path = "/6410000/buslocationservice/getBusLocationList"; + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("routeId", apiRouteId); + URI uri = this.getOpenApiURI(path, params); + ResponseEntity resp = restTemplate.getForEntity(uri, BusLocationRespDto.class); + return resp.getBody().msgBody(); + } + + // @Override + // public List getBusStationArrivalInfo(String routeId) { + // return null; + // } + + private URI getOpenApiURI(String path, MultiValueMap params) { + final var builder = new DefaultUriBuilderFactory(); + builder.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); + return builder.builder() + .scheme("https") + .host(host) + .path(path) + .queryParam("serviceKey", this.busApiKeyProperty.getApiKey()) + .queryParams(params) + .build(); + } +} diff --git a/server/src/main/java/com/talkka/server/bus/controller/BusRouteController.java b/server/src/main/java/com/talkka/server/bus/controller/BusRouteController.java index 88a64eed..11004317 100644 --- a/server/src/main/java/com/talkka/server/bus/controller/BusRouteController.java +++ b/server/src/main/java/com/talkka/server/bus/controller/BusRouteController.java @@ -4,6 +4,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -22,12 +23,31 @@ public class BusRouteController { private final BusRouteService busRouteService; @GetMapping("") - public ResponseEntity>> findByRouteName(@RequestParam("search") String routeName) { + public ResponseEntity>> getRoutes( + @RequestParam(value = "search", required = false) String routeName) { + List routeList; + + if (routeName != null) { + routeList = busRouteService.getRoutesByRouteName(routeName); + } else { + routeList = busRouteService.getRoutes(); + } return ResponseEntity.ok( ApiRespDto.>builder() .statusCode(StatusCode.OK.getCode()) .message(StatusCode.OK.getMessage()) - .data(busRouteService.findByRouteName(routeName)) + .data(routeList) + .build() + ); + } + + @GetMapping("/{id}") + public ResponseEntity> getRouteById(@PathVariable("id") Long routeId) { + return ResponseEntity.ok( + ApiRespDto.builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(busRouteService.getRouteById(routeId)) .build() ); } diff --git a/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java b/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java new file mode 100644 index 00000000..0b868ee1 --- /dev/null +++ b/server/src/main/java/com/talkka/server/bus/controller/BusRouteStationController.java @@ -0,0 +1,60 @@ +package com.talkka.server.bus.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import com.talkka.server.bus.dto.BusRouteStationRespDto; +import com.talkka.server.bus.service.BusRouteStationService; +import com.talkka.server.common.dto.ApiRespDto; +import com.talkka.server.common.enums.StatusCode; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +@RequestMapping("/api/bus/route-station") +public class BusRouteStationController { + private final BusRouteStationService routeStationService; + + @GetMapping("/{id}") + public ResponseEntity> getRouteStationById( + @PathVariable("id") Long routeStationId) { + return ResponseEntity.ok( + ApiRespDto.builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(routeStationService.getRouteStationById(routeStationId)) + .build() + ); + } + + @GetMapping("") + public ResponseEntity>> getRouteStations( + @RequestParam(value = "routeId", required = false) Long routeId, + @RequestParam(value = "stationId", required = false) Long stationId) { + List routeStationList; + + if (routeId != null && stationId != null) { + routeStationList = routeStationService.getRouteStationsByRouteIdAndStationId(routeId, stationId); + } else if (routeId != null) { + routeStationList = routeStationService.getRouteStationsByRouteId(routeId); + } else if (stationId != null) { + routeStationList = routeStationService.getRouteStationsByStationId(stationId); + } else { + routeStationList = routeStationService.getRouteStations(); + } + return ResponseEntity.ok( + ApiRespDto.>builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(routeStationList) + .build() + ); + } +} diff --git a/server/src/main/java/com/talkka/server/bus/controller/BusStationController.java b/server/src/main/java/com/talkka/server/bus/controller/BusStationController.java new file mode 100644 index 00000000..6ddaeabf --- /dev/null +++ b/server/src/main/java/com/talkka/server/bus/controller/BusStationController.java @@ -0,0 +1,54 @@ +package com.talkka.server.bus.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.talkka.server.bus.dto.BusStationRespDto; +import com.talkka.server.bus.service.BusStationService; +import com.talkka.server.common.dto.ApiRespDto; +import com.talkka.server.common.enums.StatusCode; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/bus/station") +public class BusStationController { + private final BusStationService stationService; + + @GetMapping("") + public ResponseEntity>> getStations( + @RequestParam(value = "search", required = false) String stationName) { + List stationList; + + if (stationName != null) { + stationList = stationService.getStationsByStationName(stationName); + } else { + stationList = stationService.getStations(); + } + return ResponseEntity.ok( + ApiRespDto.>builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(stationList) + .build() + ); + } + + @GetMapping("/{id}") + public ResponseEntity> getStationById(@PathVariable("id") Long stationId) { + return ResponseEntity.ok( + ApiRespDto.builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(stationService.getStationById(stationId)) + .build() + ); + } +} diff --git a/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java b/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java index 64562d95..a9adc185 100644 --- a/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java +++ b/server/src/main/java/com/talkka/server/bus/dao/BusRouteRepository.java @@ -13,6 +13,6 @@ public interface BusRouteRepository extends JpaRepository Optional findByApiRouteId(String apiRouteId); - List findByRouteNameLikeOrderByRouteNameAsc(String routeName); + List findAllByRouteNameLikeOrderByRouteNameAsc(String routeName); } diff --git a/server/src/main/java/com/talkka/server/bus/dao/BusRouteStationRepository.java b/server/src/main/java/com/talkka/server/bus/dao/BusRouteStationRepository.java index ad1785b8..dd8bf57f 100644 --- a/server/src/main/java/com/talkka/server/bus/dao/BusRouteStationRepository.java +++ b/server/src/main/java/com/talkka/server/bus/dao/BusRouteStationRepository.java @@ -7,7 +7,9 @@ @Repository public interface BusRouteStationRepository extends JpaRepository { - List findByRouteId(Long routeId); + List findAllByRouteId(Long routeId); - List findByStationId(Long stationId); + List findAllByStationId(Long stationId); + + List findAllByRouteIdAndStationId(Long routeId, Long stationId); } diff --git a/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationRespDto.java b/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationRespDto.java index 78e0eef9..bff700ec 100644 --- a/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationRespDto.java +++ b/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationRespDto.java @@ -9,19 +9,21 @@ @Builder public record BusRouteStationRespDto( Long busRouteStationId, - BusRouteRespDto route, - BusStationRespDto station, Short stationSeq, String stationName, + Long routeId, + String routeName, + Long stationId, LocalDateTime createdAt ) { public static BusRouteStationRespDto of(BusRouteStationEntity busRouteStationEntity) { return new BusRouteStationRespDto( busRouteStationEntity.getId(), - BusRouteRespDto.of(busRouteStationEntity.getRoute()), - BusStationRespDto.of(busRouteStationEntity.getStation()), busRouteStationEntity.getStationSeq(), - busRouteStationEntity.getStationName(), + busRouteStationEntity.getStation().getStationName(), + busRouteStationEntity.getRoute().getId(), + busRouteStationEntity.getRoute().getRouteName(), + busRouteStationEntity.getStation().getId(), busRouteStationEntity.getCreatedAt() ); } diff --git a/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java b/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java index 662ba502..e2b05100 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusRouteService.java @@ -17,19 +17,25 @@ public class BusRouteService { private final BusRouteRepository busRouteRepository; - public BusRouteRespDto findByRouteId(Long routeId) { + public BusRouteRespDto getRouteById(Long routeId) { BusRouteEntity busRouteEntity = busRouteRepository.findById(routeId) .orElseThrow(() -> new BadRequestException("존재하지 않는 노선입니다.")); return BusRouteRespDto.of(busRouteEntity); } - public List findByRouteName(String routeName) { - return busRouteRepository.findByRouteNameLikeOrderByRouteNameAsc(routeName).stream() + public List getRoutes() { + return busRouteRepository.findAll().stream() .map(BusRouteRespDto::of) .toList(); } - public BusRouteRespDto createBusRoute(BusRouteCreateDto busRouteCreateDto) { + public List getRoutesByRouteName(String routeName) { + return busRouteRepository.findAllByRouteNameLikeOrderByRouteNameAsc(routeName).stream() + .map(BusRouteRespDto::of) + .toList(); + } + + public BusRouteRespDto createRoute(BusRouteCreateDto busRouteCreateDto) { if (!busRouteRepository.existsByApiRouteId(busRouteCreateDto.apiRouteId())) { throw new BadRequestException("이미 등록된 버스 노선입니다."); } diff --git a/server/src/main/java/com/talkka/server/bus/service/BusRouteStationService.java b/server/src/main/java/com/talkka/server/bus/service/BusRouteStationService.java index 4d2a72f8..17107fac 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusRouteStationService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusRouteStationService.java @@ -24,7 +24,7 @@ public class BusRouteStationService { private final BusStationRepository stationRepository; private final BusRouteStationRepository routeStationRepository; - public BusRouteStationRespDto createBusRouteStation(BusRouteStationCreateDto busRouteStationCreateDto) { + public BusRouteStationRespDto createRouteStation(BusRouteStationCreateDto busRouteStationCreateDto) { BusRouteEntity routeEntity = routeRepository.findByApiRouteId(busRouteStationCreateDto.apiRouteId()) .orElseThrow(() -> new BadRequestException("존재하지 않는 노선입니다.")); BusStationEntity stationEntity = stationRepository.findByApiStationId( @@ -34,20 +34,32 @@ public BusRouteStationRespDto createBusRouteStation(BusRouteStationCreateDto bus return BusRouteStationRespDto.of(routeStationRepository.save(busRouteStationEntity)); } - public BusRouteStationRespDto findById(Long id) { + public BusRouteStationRespDto getRouteStationById(Long id) { BusRouteStationEntity busRouteStationEntity = routeStationRepository.findById(id) .orElseThrow(() -> new BadRequestException("존재하지 않는 노선정류장입니다.")); return BusRouteStationRespDto.of(busRouteStationEntity); } - public List findByRouteId(Long routeId) { - return routeStationRepository.findByRouteId(routeId).stream() + public List getRouteStationsByRouteIdAndStationId(Long routeId, Long stationId) { + return routeStationRepository.findAllByRouteIdAndStationId(routeId, stationId).stream() .map(BusRouteStationRespDto::of) .toList(); } - public List findByStationId(Long stationId) { - return routeStationRepository.findByStationId(stationId).stream() + public List getRouteStationsByRouteId(Long routeId) { + return routeStationRepository.findAllByRouteId(routeId).stream() + .map(BusRouteStationRespDto::of) + .toList(); + } + + public List getRouteStationsByStationId(Long stationId) { + return routeStationRepository.findAllByStationId(stationId).stream() + .map(BusRouteStationRespDto::of) + .toList(); + } + + public List getRouteStations() { + return routeStationRepository.findAll().stream() .map(BusRouteStationRespDto::of) .toList(); } diff --git a/server/src/main/java/com/talkka/server/bus/service/BusStationService.java b/server/src/main/java/com/talkka/server/bus/service/BusStationService.java index 70cfdc26..3a2938b4 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusStationService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusStationService.java @@ -17,19 +17,25 @@ public class BusStationService { private final BusStationRepository busStationRepository; - public BusStationRespDto findByStationId(Long stationId) { + public BusStationRespDto getStationById(Long stationId) { BusStationEntity busStationEntity = busStationRepository.findById(stationId) .orElseThrow(() -> new BadRequestException("존재하지 않는 정거장입니다.")); return BusStationRespDto.of(busStationEntity); } - public List findByStationName(String stationName) { + public List getStationsByStationName(String stationName) { return busStationRepository.findByStationNameLikeOrderByStationNameAsc(stationName).stream() .map(BusStationRespDto::of) .toList(); } - public BusStationRespDto createBusStation(BusStationCreateDto busStationCreateDto) { + public List getStations() { + return busStationRepository.findAll().stream() + .map(BusStationRespDto::of) + .toList(); + } + + public BusStationRespDto createStation(BusStationCreateDto busStationCreateDto) { if (busStationRepository.existsByApiStationId(busStationCreateDto.apiStationId())) { throw new BadRequestException("이미 등록된 정거장입니다."); } diff --git a/server/src/main/java/com/talkka/server/review/controller/BusReviewController.java b/server/src/main/java/com/talkka/server/review/controller/BusReviewController.java index c6ec41ad..94c1cf5c 100644 --- a/server/src/main/java/com/talkka/server/review/controller/BusReviewController.java +++ b/server/src/main/java/com/talkka/server/review/controller/BusReviewController.java @@ -33,13 +33,18 @@ public class BusReviewController { @GetMapping("") public ResponseEntity>> getBusReviewList( - @AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo, - @RequestParam Long routeId, - @RequestParam Long busRouteStationId, - @RequestParam String timeSlot + @RequestParam(required = true) Long routeId, + @RequestParam(required = false) Long busRouteStationId, + @RequestParam(required = false) String timeSlot ) { - List reviewData = busReviewService.getBusReviewList(oAuth2UserInfo.getUserId(), routeId, - busRouteStationId, timeSlot); + List reviewData; + if (busRouteStationId != null && timeSlot != null) { + reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId, timeSlot); + } else if (busRouteStationId != null) { + reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId); + } else { + reviewData = busReviewService.getBusReviewList(routeId); + } return ResponseEntity.ok( ApiRespDto.>builder() diff --git a/server/src/main/java/com/talkka/server/review/dao/BusReviewRepository.java b/server/src/main/java/com/talkka/server/review/dao/BusReviewRepository.java index aa56ecd6..82754cce 100644 --- a/server/src/main/java/com/talkka/server/review/dao/BusReviewRepository.java +++ b/server/src/main/java/com/talkka/server/review/dao/BusReviewRepository.java @@ -9,9 +9,19 @@ @Repository public interface BusReviewRepository extends JpaRepository { - List findAllByWriterIdAndRouteIdAndStationIdAndTimeSlot( + + List findAllByWriterIdAndRouteIdAndStationIdAndTimeSlotOrderByUpdatedAtDesc( Long userId, Long routeId, Long busRouteStationId, TimeSlot timeSlot); + + List findAllByRouteIdOrderByCreatedAtDesc(Long routeId); + + List findAllByRouteIdAndStationIdOrderByCreatedAtDesc(Long routeId, Long stationId); + + List findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc( + Long routeId, + Long stationId, + TimeSlot timeSlot); } diff --git a/server/src/main/java/com/talkka/server/review/dto/BusReviewRespDto.java b/server/src/main/java/com/talkka/server/review/dto/BusReviewRespDto.java index e551d5b2..8edcc10a 100644 --- a/server/src/main/java/com/talkka/server/review/dto/BusReviewRespDto.java +++ b/server/src/main/java/com/talkka/server/review/dto/BusReviewRespDto.java @@ -8,8 +8,11 @@ @Builder public record BusReviewRespDto( Long userId, + String userName, Long routeId, + String routeName, Long busRouteStationId, + String stationName, String content, TimeSlot timeSlot, Integer rating @@ -17,8 +20,11 @@ public record BusReviewRespDto( public static BusReviewRespDto of(BusReviewEntity busEntity) { return new BusReviewRespDto( busEntity.getWriter().getId(), + busEntity.getWriter().getName(), busEntity.getRoute().getId(), + busEntity.getRoute().getRouteName(), busEntity.getStation().getId(), + busEntity.getStation().getStationName(), busEntity.getContent(), busEntity.getTimeSlot(), busEntity.getRating() diff --git a/server/src/main/java/com/talkka/server/review/service/BusReviewService.java b/server/src/main/java/com/talkka/server/review/service/BusReviewService.java index 84a80004..8ccfce3b 100644 --- a/server/src/main/java/com/talkka/server/review/service/BusReviewService.java +++ b/server/src/main/java/com/talkka/server/review/service/BusReviewService.java @@ -31,10 +31,11 @@ public class BusReviewService { private final BusRouteStationRepository busRouteStationRepository; private final BusRouteRepository busRouteRepository; - public List getBusReviewList( + public List getUsersBusReviewList( Long userId, Long routeId, Long busRouteStationId, String timeSlot ) { - List reviewList = busReviewRepository.findAllByWriterIdAndRouteIdAndStationIdAndTimeSlot( + // request param의 존재 유무에 따라 response가 변경되어야합니다. + List reviewList = busReviewRepository.findAllByWriterIdAndRouteIdAndStationIdAndTimeSlotOrderByUpdatedAtDesc( userId, routeId, busRouteStationId, EnumCodeConverterUtils.fromCode(TimeSlot.class, timeSlot)); return reviewList.stream() @@ -42,6 +43,30 @@ public List getBusReviewList( .toList(); } + public List getBusReviewList(Long routeId) { + List reviewEntityList = busReviewRepository.findAllByRouteIdOrderByCreatedAtDesc(routeId); + return reviewEntityList.stream() + .map(BusReviewRespDto::of) + .toList(); + } + + public List getBusReviewList(Long routeId, Long busRouteStationId) { + List reviewEntityList = busReviewRepository.findAllByRouteIdAndStationIdOrderByCreatedAtDesc( + routeId, busRouteStationId); + return reviewEntityList.stream() + .map(BusReviewRespDto::of) + .toList(); + } + + public List getBusReviewList(Long routeId, Long busRouteStationId, String timeSlot) { + List reviewEntityList = busReviewRepository.findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc( + routeId, busRouteStationId, EnumCodeConverterUtils.fromCode(TimeSlot.class, timeSlot)); + return reviewEntityList.stream() + .map(BusReviewRespDto::of) + .toList(); + } + + @Transactional public BusReviewRespDto createBusReview(Long userId, BusReviewReqDto busReviewReqDto) { UserEntity user = userRepository.findById(userId) .orElseThrow(() -> new NotFoundException("존재하지 않는 유저입니다.")); @@ -77,6 +102,7 @@ public BusReviewRespDto updateBusReview(Long userId, Long busReviewId, BusReview return BusReviewRespDto.of(review); } + @Transactional public Long deleteBusReview(Long userId, Long busReviewId) { BusReviewEntity review = busReviewRepository.findById(busReviewId) .orElseThrow(() -> new NotFoundException("존재하지 않는 리뷰입니다.")); diff --git a/server/src/main/resources/application.yaml b/server/src/main/resources/application.yaml index feb3c15d..7a64a879 100644 --- a/server/src/main/resources/application.yaml +++ b/server/src/main/resources/application.yaml @@ -35,4 +35,12 @@ spring: user-name-attribute: response thymeleaf: prefix: classpath:/templates/ - suffix: .html \ No newline at end of file + suffix: .html + + +openapi: + public: + bus: + service-key: + keys: + - ${SERVICE_KEY_1} \ No newline at end of file diff --git a/server/src/test/java/com/talkka/server/api/datagg/service/BusApiServiceImplTest.java b/server/src/test/java/com/talkka/server/api/datagg/service/BusApiServiceImplTest.java new file mode 100644 index 00000000..f8b78b0f --- /dev/null +++ b/server/src/test/java/com/talkka/server/api/datagg/service/BusApiServiceImplTest.java @@ -0,0 +1,92 @@ +package com.talkka.server.api.datagg.service; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class BusApiServiceImplTest { + @Autowired + private BusApiService busApiService; + + @Nested + @DisplayName("getSearchedRouteInfo method") + public class GetSearchedRouteInfo { + @Test + void routeName을_검색하면_해당_키워드를_가진_버스_노선_정보를_리스트로_반환한다() { + // given + String routeName = "78"; + + // when + var result = busApiService.getSearchedRouteInfo(routeName); + + // then + assertNotNull(result); + assertFalse(result.isEmpty()); + for (var dto : result) { + assertThat(dto.routeName()).contains(routeName); + } + } + } + + @Nested + @DisplayName("getRouteInfo method") + public class GetRouteInfo { + @Test + void routeId를_검색하면_해당_버스_노선_정보를_리스트로_반환한다() { + // given + String routeId = "200000150"; + + // when + var result = busApiService.getRouteInfo(routeId); + + // then + assertNotNull(result); + assertFalse(result.isEmpty()); + for (var dto : result) { + assertThat(dto.routeId()).isEqualTo(Long.parseLong(routeId)); + } + } + } + + @Nested + @DisplayName("getRouteStationInfo method") + public class GetRouteStationInfo { + @Test + void routeId를_검색하면_해당_버스_노선_정류장_정보를_리스트로_반환한다() { + // given + String routeId = "200000150"; + + // when + var result = busApiService.getRouteStationInfo(routeId); + + // then + assertNotNull(result); + assertFalse(result.isEmpty()); + System.out.println(result); + } + } + + @Nested + @DisplayName("getBusLocationInfo method") + public class GetBusLocationInfo { + @Test + void routeId를_검색하면_해당_버스_위치_정보를_리스트로_반환한다() { + // given + String routeId = "200000150"; + + // when + var result = busApiService.getBusLocationInfo(routeId); + + // then + assertNotNull(result); + assertFalse(result.isEmpty()); + System.out.println(result); + } + } +} \ No newline at end of file diff --git a/server/src/test/java/com/talkka/server/bus/service/BusFactory.java b/server/src/test/java/com/talkka/server/bus/BusTestFactory.java similarity index 82% rename from server/src/test/java/com/talkka/server/bus/service/BusFactory.java rename to server/src/test/java/com/talkka/server/bus/BusTestFactory.java index 29d0f5c8..a285e9b9 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusFactory.java +++ b/server/src/test/java/com/talkka/server/bus/BusTestFactory.java @@ -1,4 +1,4 @@ -package com.talkka.server.bus.service; +package com.talkka.server.bus; import java.math.BigDecimal; @@ -16,9 +16,9 @@ import com.talkka.server.bus.enums.DistrictCode; import com.talkka.server.bus.enums.TurnStation; -public class BusFactory { +public class BusTestFactory { - protected static BusRouteEntity getBusRouteEntity(Long id) { + public static BusRouteEntity getBusRouteEntity(Long id) { return BusRouteEntity.builder() .id(id) .apiRouteId("BRT" + id) @@ -45,7 +45,7 @@ protected static BusRouteEntity getBusRouteEntity(Long id) { .build(); } - protected static BusRouteCreateDto getBusRouteCreateDto(Long id) { + public static BusRouteCreateDto getBusRouteCreateDto(Long id) { return BusRouteCreateDto.builder() .apiRouteId("BRT" + id) @@ -72,7 +72,7 @@ protected static BusRouteCreateDto getBusRouteCreateDto(Long id) { .build(); } - protected static BusRouteRespDto getBusRouteRespDto(Long id) { + public static BusRouteRespDto getBusRouteRespDto(Long id) { return BusRouteRespDto.builder() .routeId(id) .routeName("7800" + id) @@ -95,7 +95,7 @@ protected static BusRouteRespDto getBusRouteRespDto(Long id) { .build(); } - protected static BusStationEntity getBusStationEntity(Long id) { + public static BusStationEntity getBusStationEntity(Long id) { return BusStationEntity.builder() .id(id) .apiStationId("BST" + id) @@ -109,7 +109,7 @@ protected static BusStationEntity getBusStationEntity(Long id) { .build(); } - protected static BusStationCreateDto getBusStationCreateDto(Long id) { + public static BusStationCreateDto getBusStationCreateDto(Long id) { return BusStationCreateDto.builder() .apiStationId("BST" + id) .stationName("정거장" + id) @@ -122,7 +122,7 @@ protected static BusStationCreateDto getBusStationCreateDto(Long id) { .build(); } - protected static BusStationRespDto getBusStationRespDto(Long id) { + public static BusStationRespDto getBusStationRespDto(Long id) { return BusStationRespDto.builder() .stationId(id) .stationName("정거장" + id) @@ -135,7 +135,7 @@ protected static BusStationRespDto getBusStationRespDto(Long id) { .build(); } - protected static BusRouteStationEntity getBusRouteStationEntity(Long id, BusRouteEntity routeEntity, + public static BusRouteStationEntity getBusRouteStationEntity(Long id, BusRouteEntity routeEntity, BusStationEntity stationEntity) { return BusRouteStationEntity.builder() .id(id) @@ -146,7 +146,7 @@ protected static BusRouteStationEntity getBusRouteStationEntity(Long id, BusRout .build(); } - protected static BusRouteStationCreateDto getBusRouteStationCreateDto(Long id) { + public static BusRouteStationCreateDto getBusRouteStationCreateDto(Long id) { return BusRouteStationCreateDto.builder() .apiRouteId("BRT" + id) .apiStationId("BST" + id) @@ -155,14 +155,15 @@ protected static BusRouteStationCreateDto getBusRouteStationCreateDto(Long id) { .build(); } - protected static BusRouteStationRespDto getBusRouteStationRespDto(Long id, BusRouteRespDto routeRespDto, + public static BusRouteStationRespDto getBusRouteStationRespDto(Long id, BusRouteRespDto routeRespDto, BusStationRespDto stationRespDto) { return BusRouteStationRespDto.builder() .busRouteStationId(id) - .route(routeRespDto) - .station(stationRespDto) - .stationName("정거장" + id) + .stationId(stationRespDto.stationId()) + .stationName("정거장" + stationRespDto.stationId()) .stationSeq(Short.valueOf(String.valueOf(id))) + .routeId(routeRespDto.routeId()) + .routeName(routeRespDto.routeName()) .build(); } diff --git a/server/src/test/java/com/talkka/server/bus/controller/BusRouteControllerTest.java b/server/src/test/java/com/talkka/server/bus/controller/BusRouteControllerTest.java new file mode 100644 index 00000000..fe3f59c9 --- /dev/null +++ b/server/src/test/java/com/talkka/server/bus/controller/BusRouteControllerTest.java @@ -0,0 +1,91 @@ +package com.talkka.server.bus.controller; + +import static com.talkka.server.bus.BusTestFactory.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.ResponseEntity; + +import com.talkka.server.bus.dto.BusRouteRespDto; +import com.talkka.server.bus.service.BusRouteService; +import com.talkka.server.common.dto.ApiRespDto; +import com.talkka.server.common.enums.StatusCode; + +@ExtendWith(MockitoExtension.class) +public class BusRouteControllerTest { + + @InjectMocks + private BusRouteController routeController; + + @Mock + private BusRouteService routeService; + + @Nested + @DisplayName("findByRouteId method") + public class FindByRouteIdTest { + @Test + void routeId를_받아_해당_아이디의_노선을_조회한다() { + // given + Long id = 1L; + var expected = ResponseEntity.ok( + ApiRespDto.builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data(getBusRouteRespDto(id)) + .build() + ); + given(routeService.getRouteById(anyLong())).willReturn(getBusRouteRespDto(id)); + // when + var result = routeController.getRouteById(id); + // then + verify(routeService, times(1)).getRouteById(anyLong()); + Assertions.assertThat(result).isEqualTo(expected); + } + } + + @Nested + @DisplayName("findByRouteId method") + public class FindByRouteNameTest { + @Test + void routeName을_받아_해당_이름으로_시작하는_노선을_조회한다() { + // given + Long id1 = 1L; + Long id2 = 2L; + Long id3 = 3L; + var expected = ResponseEntity.ok( + ApiRespDto.>builder() + .statusCode(StatusCode.OK.getCode()) + .message(StatusCode.OK.getMessage()) + .data( + List.of( + getBusRouteRespDto(id1), + getBusRouteRespDto(id2), + getBusRouteRespDto(id3) + ) + ) + .build() + ); + given(routeService.getRoutesByRouteName(anyString())).willReturn( + List.of( + getBusRouteRespDto(id1), + getBusRouteRespDto(id2), + getBusRouteRespDto(id3) + ) + ); + // when + var result = routeController.getRoutes("7800"); + // then + verify(routeService, times(1)).getRoutesByRouteName(anyString()); + Assertions.assertThat(result).isEqualTo(expected); + } + } +} diff --git a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java index f3f735b7..7da099cc 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java @@ -1,6 +1,6 @@ package com.talkka.server.bus.service; -import static com.talkka.server.bus.service.BusFactory.*; +import static com.talkka.server.bus.BusTestFactory.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -31,8 +31,8 @@ public class BusRouteServiceTest { private BusRouteRepository busRouteRepository; @Nested - @DisplayName("createBusRoute method") - public class CreateBusRouteTest { + @DisplayName("createRoute method") + public class CreateRouteTest { @Test void 버스_노선을_생성한다() { // given @@ -42,7 +42,7 @@ public class CreateBusRouteTest { given(busRouteRepository.save(any(BusRouteEntity.class))).willReturn(busRouteEntity); given(busRouteRepository.existsByApiRouteId(any(String.class))).willReturn(true); // when - BusRouteRespDto result = busRouteService.createBusRoute(busRouteCreateDto); + BusRouteRespDto result = busRouteService.createRoute(busRouteCreateDto); // then assertThat(result).isEqualTo(busRouteRespDto); } @@ -55,15 +55,15 @@ public class CreateBusRouteTest { // when // then assertThatThrownBy( - () -> busRouteService.createBusRoute(reqDto) + () -> busRouteService.createRoute(reqDto) ).isInstanceOf(BadRequestException.class) .hasMessage("이미 등록된 버스 노선입니다."); } } @Nested - @DisplayName("findByRouteId method") - public class FindByRouteIdTest { + @DisplayName("getRouteByRouteId method") + public class GetRouteByIdTest { @Test void ID를_기반으로_버스_노선을_요청하면_레포지토리를_통해_결과를_DTO로_반환한다() { // given @@ -71,7 +71,7 @@ public class FindByRouteIdTest { BusRouteEntity foundEntity = getBusRouteEntity(routeId); given(busRouteRepository.findById(anyLong())).willReturn(Optional.of(foundEntity)); // when - var BusRouteRespDto = busRouteService.findByRouteId(routeId); + var BusRouteRespDto = busRouteService.getRouteById(routeId); // then verify(busRouteRepository).findById(anyLong()); assertThat(BusRouteRespDto).isEqualTo(getBusRouteRespDto(routeId)); @@ -85,7 +85,7 @@ public class FindByRouteIdTest { // when // then assertThatThrownBy( - () -> busRouteService.findByRouteId(1L) + () -> busRouteService.getRouteById(1L) ).isInstanceOf(exceptionClass) .hasMessage("존재하지 않는 노선입니다."); verify(busRouteRepository, times(1)).findById(anyLong()); @@ -93,8 +93,8 @@ public class FindByRouteIdTest { } @Nested - @DisplayName("findByRouteName method") - public class FindByRouteNameTest { + @DisplayName("getRoutesByRouteName method") + public class GetRoutesByRouteNameTest { @Test void 버스노선이름을_요청으로_받아_repository에서_조회하고_해당_이름으로_시작하는_노선들을_리스트로_반환한다() { @@ -103,15 +103,33 @@ public class FindByRouteNameTest { String routeName = "7800"; var entityList = List.of(getBusRouteEntity(1L), getBusRouteEntity(2L)); var expectedList = List.of(getBusRouteRespDto(1L), getBusRouteRespDto(2L)); - given(busRouteRepository.findByRouteNameLikeOrderByRouteNameAsc(any(String.class))).willReturn(entityList); + given(busRouteRepository.findAllByRouteNameLikeOrderByRouteNameAsc(any(String.class))).willReturn( + entityList); // when - var resultList = busRouteService.findByRouteName(routeName); + var resultList = busRouteService.getRoutesByRouteName(routeName); // then - verify(busRouteRepository, times(1)).findByRouteNameLikeOrderByRouteNameAsc(anyString()); + verify(busRouteRepository, times(1)).findAllByRouteNameLikeOrderByRouteNameAsc(anyString()); assertThat(resultList).containsAll(expectedList); } } + + @Nested + @DisplayName("getRoutes method") + public class GetRoutesTest { + @Test + void 모든_버스_노선을_조회한다() { + // given + var entityList = List.of(getBusRouteEntity(1L), getBusRouteEntity(2L)); + var expectedList = List.of(getBusRouteRespDto(1L), getBusRouteRespDto(2L)); + given(busRouteRepository.findAll()).willReturn(entityList); + // when + var resultList = busRouteService.getRoutes(); + // then + verify(busRouteRepository, times(1)).findAll(); + assertThat(resultList).containsAll(expectedList); + } + } } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java index 5c319b7d..02ea1450 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java @@ -1,6 +1,6 @@ package com.talkka.server.bus.service; -import static com.talkka.server.bus.service.BusFactory.*; +import static com.talkka.server.bus.BusTestFactory.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.*; @@ -36,8 +36,8 @@ public class BusRouteStationServiceTest { private BusRouteStationRepository routeStationRepository; @Nested - @DisplayName("createBusStation method") - public class CreateBusStationTest { + @DisplayName("createStation method") + public class CreateStationTest { @Test void BusRouteStationReqDto를_요청으로_받아_BusRouteStationRepository에_저장한다() { /// given @@ -50,7 +50,7 @@ public class CreateBusStationTest { given(routeStationRepository.save(any(BusRouteStationEntity.class))).willReturn( getBusRouteStationEntity(id, getBusRouteEntity(id), getBusStationEntity(id))); // when - var result = routeStationService.createBusRouteStation(createDto); + var result = routeStationService.createRouteStation(createDto); // then assertThat(result).isEqualTo(expected); } @@ -62,7 +62,7 @@ public class CreateBusStationTest { given(routeRepository.findByApiRouteId(any())).willReturn(Optional.empty()); // when // then - assertThatThrownBy(() -> routeStationService.createBusRouteStation(createDto)).isInstanceOf( + assertThatThrownBy(() -> routeStationService.createRouteStation(createDto)).isInstanceOf( BadRequestException.class).hasMessage("존재하지 않는 노선입니다."); } @@ -74,98 +74,112 @@ public class CreateBusStationTest { given(stationRepository.findByApiStationId(any())).willReturn(Optional.empty()); // when // then - assertThatThrownBy(() -> routeStationService.createBusRouteStation(createDto)).isInstanceOf( + assertThatThrownBy(() -> routeStationService.createRouteStation(createDto)).isInstanceOf( BadRequestException.class).hasMessage("존재하지 않는 정류장입니다."); } } @Nested - @DisplayName("findById method") - public class FindByIdTest { - + @DisplayName("getRouteStationsByRouteIdAndStationId method") + public class GetRouteStationsByRouteIdAndStationIdTest { @Test - void Id를_받아_해당되는_정류장노선_정보를_조회하고_결과를_RespDto로_반환한다() { + void RouteId와_StationId를_받아_해당_아이디의_노선정류장을_조회한다() { // given - Long id = 1L; - var expected = getBusRouteStationRespDto(id, getBusRouteRespDto(id), getBusStationRespDto(id)); - given(routeStationRepository.findById(any(Long.class))).willReturn( - Optional.of(getBusRouteStationEntity(id, getBusRouteEntity(id), getBusStationEntity(id)))); + Long routeId = 1L; + Long stationId = 1L; + var expected = List.of(getBusRouteStationRespDto(1L, getBusRouteRespDto(1L), getBusStationRespDto(1L))); + given(routeStationRepository.findAllByRouteIdAndStationId(anyLong(), anyLong())).willReturn( + List.of(getBusRouteStationEntity(1L, getBusRouteEntity(1L), getBusStationEntity(1L)))); // when - var result = routeStationService.findById(id); + var result = routeStationService.getRouteStationsByRouteIdAndStationId(routeId, stationId); // then assertThat(result).isEqualTo(expected); + verify(routeStationRepository, times(1)).findAllByRouteIdAndStationId(anyLong(), anyLong()); } + } + @Nested + @DisplayName("getRouteStationsByRouteId method") + public class GetRouteStationsByRouteIdTest { @Test - void 존재하지_않는_Id면_Exception을_throw한다() { + void RouteId를_받아_해당_아이디의_노선정류장을_조회한다() { // given - Long id = 1L; - given(routeStationRepository.findById(anyLong())).willReturn(Optional.empty()); + Long routeId = 1L; + var expected = List.of(getBusRouteStationRespDto(1L, getBusRouteRespDto(1L), getBusStationRespDto(1L))); + given(routeStationRepository.findAllByRouteId(anyLong())).willReturn( + List.of(getBusRouteStationEntity(1L, getBusRouteEntity(1L), getBusStationEntity(1L)))); // when - + var result = routeStationService.getRouteStationsByRouteId(routeId); // then - assertThatThrownBy(() -> routeStationService.findById(id)).isInstanceOf(BadRequestException.class) - .hasMessage("존재하지 않는 노선정류장입니다."); + assertThat(result).isEqualTo(expected); + verify(routeStationRepository, times(1)).findAllByRouteId(anyLong()); } } @Nested - @DisplayName("findByRouteId method") - public class FindByRouteIdTest { - + @DisplayName("getRouteStationsByStationId method") + public class GetRouteStationsByStationIdTest { @Test - void RouteId를_받아_해당노선에_속하는_정류장정보를_조회하고_결과를_RespDto의_리스트로_반환한다() { + void StationId를_받아_해당_아이디의_노선정류장을_조회한다() { // given - Long routeId = 1L; - Long id1 = 2L; - Long id2 = 3L; - Long id3 = 4L; - var expected = List.of( - getBusRouteStationRespDto(id1, getBusRouteRespDto(routeId), getBusStationRespDto(id1)), - getBusRouteStationRespDto(id2, getBusRouteRespDto(routeId), getBusStationRespDto(id2)), - getBusRouteStationRespDto(id3, getBusRouteRespDto(routeId), getBusStationRespDto(id3)) - ); - given(routeStationRepository.findByRouteId(any(Long.class))).willReturn( - List.of( - getBusRouteStationEntity(id1, getBusRouteEntity(routeId), getBusStationEntity(id1)), - getBusRouteStationEntity(id2, getBusRouteEntity(routeId), getBusStationEntity(id2)), - getBusRouteStationEntity(id3, getBusRouteEntity(routeId), getBusStationEntity(id3)) - ) - ); + Long stationId = 1L; + var expected = List.of(getBusRouteStationRespDto(1L, getBusRouteRespDto(1L), getBusStationRespDto(1L))); + given(routeStationRepository.findAllByStationId(anyLong())).willReturn( + List.of(getBusRouteStationEntity(1L, getBusRouteEntity(1L), getBusStationEntity(1L)))); // when - var result = routeStationService.findByRouteId(routeId); + var result = routeStationService.getRouteStationsByStationId(stationId); // then assertThat(result).isEqualTo(expected); + verify(routeStationRepository, times(1)).findAllByStationId(anyLong()); } } @Nested - @DisplayName("findByStationId method") - public class FindByStationIdTest { + @DisplayName("getRouteStations method") + public class GetRouteStationsTest { + @Test + void 모든_노선정류장을_조회한다() { + // given + var expected = List.of(getBusRouteStationRespDto(1L, getBusRouteRespDto(1L), getBusStationRespDto(1L))); + given(routeStationRepository.findAll()).willReturn( + List.of(getBusRouteStationEntity(1L, getBusRouteEntity(1L), getBusStationEntity(1L)))); + // when + var result = routeStationService.getRouteStations(); + // then + assertThat(result).isEqualTo(expected); + verify(routeStationRepository, times(1)).findAll(); + } + } + @Nested + @DisplayName("getRouteStationById method") + public class GetRouteStationByIdTest { @Test - void StationId를_받아_해당노선에_속하는_정류장정보를_조회하고_결과를_RespDto의_리스트로_반환한다() { + void ID를_받아_해당_아이디의_노선정류장을_조회한다() { // given - Long stationId = 1L; - Long id1 = 2L; - Long id2 = 3L; - Long id3 = 4L; - var expected = List.of( - getBusRouteStationRespDto(id1, getBusRouteRespDto(id1), getBusStationRespDto(stationId)), - getBusRouteStationRespDto(id2, getBusRouteRespDto(id2), getBusStationRespDto(stationId)), - getBusRouteStationRespDto(id3, getBusRouteRespDto(id3), getBusStationRespDto(stationId)) - ); - given(routeStationRepository.findByStationId(any(Long.class))).willReturn( - List.of( - getBusRouteStationEntity(id1, getBusRouteEntity(id1), getBusStationEntity(stationId)), - getBusRouteStationEntity(id2, getBusRouteEntity(id2), getBusStationEntity(stationId)), - getBusRouteStationEntity(id3, getBusRouteEntity(id3), getBusStationEntity(stationId)) - ) - ); + Long id = 1L; + var expected = getBusRouteStationRespDto(id, getBusRouteRespDto(id), getBusStationRespDto(id)); + given(routeStationRepository.findById(anyLong())).willReturn( + Optional.of(getBusRouteStationEntity(id, getBusRouteEntity(id), getBusStationEntity(id)))); // when - var result = routeStationService.findByStationId(stationId); + var result = routeStationService.getRouteStationById(id); // then assertThat(result).isEqualTo(expected); + verify(routeStationRepository, times(1)).findById(anyLong()); + } + + @Test + void ID가_존재하지_않으면_Exception을_throw한다() { + // given + Class exceptionClass = BadRequestException.class; + given(routeStationRepository.findById(anyLong())).willReturn(Optional.empty()); + // when + // then + assertThatThrownBy( + () -> routeStationService.getRouteStationById(1L) + ).isInstanceOf(exceptionClass) + .hasMessage("존재하지 않는 노선정류장입니다."); + verify(routeStationRepository, times(1)).findById(anyLong()); } } } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java index 2c912cec..b6191cfb 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java @@ -1,6 +1,6 @@ package com.talkka.server.bus.service; -import static com.talkka.server.bus.service.BusFactory.*; +import static com.talkka.server.bus.BusTestFactory.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -30,8 +30,8 @@ class BusStationServiceTest { private BusStationRepository busStationRepository; @Nested - @DisplayName("findByStationId method") - public class FindByStationId { + @DisplayName("getStationByStationId method") + public class GetStationByStationId { @Test void ID를_기반으로_버스_정류장을_요청하면_레포지토리를_통해_조회하여_결과를_DTO로_반환한다() { Long stationId = 1L; @@ -39,7 +39,7 @@ public class FindByStationId { BusStationRespDto expected = getBusStationRespDto(stationId); given(busStationRepository.findById(stationId)).willReturn(Optional.of(busStationEntity)); // when - BusStationRespDto result = busStationService.findByStationId(stationId); + BusStationRespDto result = busStationService.getStationById(stationId); // then verify(busStationRepository, times(1)).findById(anyLong()); assertThat(result).isEqualTo(expected); @@ -54,7 +54,7 @@ public class FindByStationId { // when // then assertThatThrownBy( - () -> busStationService.findByStationId(stationId) + () -> busStationService.getStationById(stationId) ).isInstanceOf(exceptionCLass) .hasMessage("존재하지 않는 정거장입니다."); verify(busStationRepository, times(1)).findById(anyLong()); @@ -70,7 +70,7 @@ public class CreateBusStationTest { BusStationCreateDto createDto = getBusStationCreateDto(1L); given(busStationRepository.save(any(BusStationEntity.class))).willReturn(getBusStationEntity(1L)); // when - var result = busStationService.createBusStation(createDto); + var result = busStationService.createStation(createDto); // then verify(busStationRepository, times(1)).save(any(BusStationEntity.class)); assertThat(result).isEqualTo(getBusStationRespDto(1L)); @@ -84,14 +84,14 @@ public class CreateBusStationTest { given(busStationRepository.existsByApiStationId(createDto.apiStationId())).willReturn(true); // when // then - assertThatThrownBy(() -> busStationService.createBusStation(createDto)) + assertThatThrownBy(() -> busStationService.createStation(createDto)) .isInstanceOf(exceptionClass).hasMessage("이미 등록된 정거장입니다."); } } @Nested - @DisplayName("findByStationName method") - public class FindByStationNameTest { + @DisplayName("getStationsByStationName method") + public class GetStationsByStationNameTest { @Test void 정류장_이름으로_요청하면_해당_이름으로_시작하는_정류장의_리스트를_반환한다() { // given @@ -106,10 +106,33 @@ public class FindByStationNameTest { ); given(busStationRepository.findByStationNameLikeOrderByStationNameAsc(anyString())).willReturn(entityList); // when - var result = busStationService.findByStationName(stationName); + var result = busStationService.getStationsByStationName(stationName); // then assertThat(result).containsAll(expected); verify(busStationRepository, times(1)).findByStationNameLikeOrderByStationNameAsc(anyString()); } } + + @Nested + @DisplayName("getStations method") + public class GetStationsTest { + @Test + void 모든_정류장을_조회한다() { + // given + List expected = List.of( + getBusStationRespDto(1L), + getBusStationRespDto(12L) + ); + List entityList = List.of( + getBusStationEntity(1L), + getBusStationEntity(12L) + ); + given(busStationRepository.findAll()).willReturn(entityList); + // when + var result = busStationService.getStations(); + // then + assertThat(result).containsAll(expected); + verify(busStationRepository, times(1)).findAll(); + } + } } \ No newline at end of file diff --git a/server/src/test/java/com/talkka/server/review/service/BusReviewServiceTest.java b/server/src/test/java/com/talkka/server/review/service/BusReviewServiceTest.java index 4bcf6fc3..e9a4f9f6 100644 --- a/server/src/test/java/com/talkka/server/review/service/BusReviewServiceTest.java +++ b/server/src/test/java/com/talkka/server/review/service/BusReviewServiceTest.java @@ -3,6 +3,8 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -49,8 +51,11 @@ public class BusReviewServiceTest { private BusReviewRespDto busReviewRespDtoFixture(Long userId) { return BusReviewRespDto.builder() .userId(userId) + .userName("유저 이름") .routeId(236000050L) + .routeName("노선 이름") .busRouteStationId(1L) + .stationName("정류장 이름") .content("리뷰 내용") .timeSlot(TimeSlot.T_00_00) .rating(4) @@ -60,27 +65,165 @@ private BusReviewRespDto busReviewRespDtoFixture(Long userId) { private UserEntity getUserFixture(Long userId) { return UserEntity.builder() .id(userId) + .name("유저 이름") .build(); } private BusRouteStationEntity getBusRouteStationFixture(Long busRouteStationId) { return BusRouteStationEntity.builder() .id(busRouteStationId) + .stationName("정류장 이름") .build(); } private BusRouteEntity getBusRouteFixture(Long routeId) { return BusRouteEntity.builder() .id(routeId) + .routeName("노선 이름") .build(); } + private List getReviewEntity(Long routeId, Long busRouteStationId, TimeSlot timeSlot) { + if (busRouteStationId == null) { + return List.of( + BusReviewEntity.builder() + .id(1L) + .content("리뷰 내용") + .timeSlot(TimeSlot.T_00_00) + .rating(4) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(1L)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now().plusMinutes(1)) + .updatedAt(LocalDateTime.now()) + .build(), + BusReviewEntity.builder() + .id(2L) + .content("리뷰 내용") + .timeSlot(TimeSlot.T_00_00) + .rating(5) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(1L)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now()) + .updatedAt(LocalDateTime.now()) + .build() + ); + } else if (timeSlot == null) { + return List.of( + BusReviewEntity.builder() + .id(1L) + .content("리뷰 내용") + .timeSlot(TimeSlot.T_00_00) + .rating(4) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(busRouteStationId)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now().plusMinutes(1)) + .updatedAt(LocalDateTime.now()) + .build(), + BusReviewEntity.builder() + .id(2L) + .content("리뷰 내용") + .timeSlot(TimeSlot.T_00_00) + .rating(5) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(busRouteStationId)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now().plusMinutes(1)) + .updatedAt(LocalDateTime.now()) + .build() + ); + } else { + return List.of( + BusReviewEntity.builder() + .id(1L) + .content("리뷰 내용") + .timeSlot(timeSlot) + .rating(4) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(busRouteStationId)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now()) + .updatedAt(LocalDateTime.now()) + .build(), + BusReviewEntity.builder() + .id(2L) + .content("리뷰 내용") + .timeSlot(timeSlot) + .rating(5) + .writer(getUserFixture(1L)) + .station(getBusRouteStationFixture(busRouteStationId)) + .route(getBusRouteFixture(routeId)) + .createdAt(LocalDateTime.now()) + .updatedAt(LocalDateTime.now()) + .build() + ); + } + } + + @Nested + @DisplayName("getBusReviewList 메서드 테스트") + public class GetBusReviewListTest { + @Test + void 버스_노선_아이디_대한_리뷰를_조회한다() { + // given + Long routeId = 236000050L; + List reviewEntityList = getReviewEntity(routeId, null, null); + var expected = reviewEntityList.stream().map(BusReviewRespDto::of).toList(); + + given(busReviewRepository.findAllByRouteIdOrderByCreatedAtDesc(anyLong())).willReturn(reviewEntityList); + // when + var result = busReviewService.getBusReviewList(routeId); + // then + verify(busReviewRepository, times(1)).findAllByRouteIdOrderByCreatedAtDesc(routeId); + assertThat(result).isEqualTo(expected); + } + + @Test + void 버스_노선_아이디와_정거장에_대한_리뷰를_조회한다() { + // given + Long routeId = 236000050L; + Long busRouteStationId = 1L; + + List reviewEntityList = getReviewEntity(routeId, busRouteStationId, null); + var expected = reviewEntityList.stream().map(BusReviewRespDto::of).toList(); + given(busReviewRepository.findAllByRouteIdAndStationIdOrderByCreatedAtDesc(anyLong(), anyLong())) + .willReturn(reviewEntityList); + // when + var result = busReviewService.getBusReviewList(routeId, busRouteStationId); + // then + verify(busReviewRepository, times(1)).findAllByRouteIdAndStationIdOrderByCreatedAtDesc(routeId, + busRouteStationId); + assertThat(result).isEqualTo(expected); + } + + @Test + void 버스_노선_아이디와_정거장_그리고_타임슬롯에_대한_리뷰를_조회한다() { + // given + Long routeId = 236000050L; + Long busRouteStationId = 1L; + TimeSlot timeSlot = EnumCodeConverterUtils.fromCode(TimeSlot.class, TimeSlot.T_00_00.getCode()); + + List reviewEntityList = getReviewEntity(routeId, busRouteStationId, timeSlot); + var expected = reviewEntityList.stream().map(BusReviewRespDto::of).toList(); + given(busReviewRepository.findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(anyLong(), anyLong(), + any(TimeSlot.class))).willReturn(reviewEntityList); + // when + var result = busReviewService.getBusReviewList(routeId, busRouteStationId, TimeSlot.T_00_00.getCode()); + // then + verify(busReviewRepository, times(1)).findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(routeId, + busRouteStationId, timeSlot); + assertThat(result).isEqualTo(expected); + } + } + @Nested @DisplayName("createBusReview 메서드 테스트") public class CreateBusReviewTest { @Test - void 제한된_요청에_따라_버스리뷰를_생성한다() { + void 제안된_요청에_따라_버스리뷰를_생성한다() { //given UserEntity user = getUserFixture(1L); BusRouteStationEntity station = getBusRouteStationFixture(1L); diff --git a/server/src/test/resources/application.yaml b/server/src/test/resources/application.yaml index e3ca91ba..6ce96e64 100644 --- a/server/src/test/resources/application.yaml +++ b/server/src/test/resources/application.yaml @@ -5,9 +5,9 @@ spring: property-naming-strategy: SNAKE_CASE datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: ${MYSQL_URL} - username: ${MYSQL_USERNAME} - password: ${MYSQL_PASSWORD} + url: jdbc:mysql://localhost:3306/TALKKA_DB?createDatabaseIfNotExist=true + username: root + password: 1234 jpa: hibernate: ddl-auto: create @@ -21,7 +21,7 @@ spring: client: registration: naver: - client-id: ${NAVER_CLIENT_ID} + client-id: ${NAVER_CLIENT_ID} # NOTE: 실제 테스트 시에는 env 에 대해서 값을 삽입하고 사용할 것. client-secret: ${NAVER_CLINET_SECRET} redirect_uri: http://localhost:8080/login/oauth2/code/naver client-name: Naver @@ -37,4 +37,11 @@ spring: user-name-attribute: response thymeleaf: prefix: classpath:/templates/ - suffix: .html \ No newline at end of file + suffix: .html + +openapi: + public: + bus: + service-key: + keys: + - ${SERVICE_KEY_1} \ No newline at end of file