Skip to content

Commit

Permalink
[ADD] Naver Maps Api 연동 완료 + Path API 테스트 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjoo-lab committed Aug 28, 2023
1 parent a46fe83 commit 6ae7dc0
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity
@EnableWebSecurity(debug = true)
@RequiredArgsConstructor
public class SecurityConfig {
private final JwtFilter jwtFilter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.twtw.backend.domain.member;
package com.twtw.backend.domain;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import com.twtw.backend.domain.path.dto.client.SearchPathRequest;
import com.twtw.backend.domain.path.dto.client.SearchPathResponse;
import com.twtw.backend.domain.plan.dto.client.SearchDestinationResponse;
import com.twtw.backend.global.client.PathClient;
import com.twtw.backend.global.exception.WebClientResponseException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriBuilder;

import java.net.URI;
import java.nio.charset.StandardCharsets;


@Component
public class SearchPathClient implements PathClient<SearchPathRequest, SearchPathResponse> {
Expand All @@ -19,5 +24,27 @@ public SearchPathClient(WebClient webClient){
this.webClient = webClient;
}

/*상세 검색을 위한 변경 필요*/
private URI getPathUri(final SearchPathRequest request, final UriBuilder uriBuilder){
final UriBuilder builder =
uriBuilder.
path("driving")
.queryParam("start",request.getStart())
.queryParam("goal",request.getEnd());

return builder.build();
}

@Override
public String request(final SearchPathRequest request) {
return webClient
.get()
.uri(uri -> getPathUri(request,uri))
.accept(MediaType.APPLICATION_JSON)
.acceptCharset(StandardCharsets.UTF_8)
.retrieve()
.bodyToMono(String.class)
.blockOptional()
.orElseThrow(WebClientResponseException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.twtw.backend.domain.path.controller;

import com.twtw.backend.domain.path.dto.client.SearchPathRequest;
import com.twtw.backend.domain.path.service.PathService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/paths")
public class PathController {
private final PathService pathService;

public PathController(PathService pathService){
this.pathService = pathService;
}

/*response 변경*/
@PostMapping("/search/path")
String searchPath(@RequestBody SearchPathRequest request){
return pathService.searchPath(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.twtw.backend.domain.path.dto.client;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum SearchPathFuel {
GASOLINE("gasoline"),
HIGHGRADEGASOLINE("highgradegasoline"),
DIESEL("diesel"),
LPG("lpg");

private final String toSmall;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.twtw.backend.domain.path.dto.client;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum SearchPathOption {
TRAFAST("실시간 빠른길","trafast"),
TRACOMFORT("실시간 편한길","tracomfort"),
TRAOPTIONAL("실시간 최적","traoptional"),
TRAAVOIDTOLL("무료 우선","travoidtoll"),
TRAAVOIDCARONLY("자동차 전용도로 회피 우선","traavoidcaronly");

private final String toKorean;
private final String toSmall;

public String toSmallOption(){
return this.toSmall;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.twtw.backend.domain.path.dto.client;

import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;



@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SearchPathRequest {

String start;
String end;
String wayPoint;
@Enumerated(value = EnumType.STRING)
SearchPathOption option;
String carType;
@Enumerated(value = EnumType.STRING)
SearchPathFuel fuelType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SearchPathResponse {
int code;
String message;
String currentDateTime;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package com.twtw.backend.domain.path.service;

import com.twtw.backend.domain.path.dto.client.SearchPathRequest;
import com.twtw.backend.domain.path.dto.client.SearchPathResponse;
import com.twtw.backend.global.client.PathClient;
import org.springframework.stereotype.Service;

@Service
public class PathService {
private final PathClient<SearchPathRequest, SearchPathResponse> client;

PathService(PathClient<SearchPathRequest, SearchPathResponse> client){
this.client = client;
}

public String searchPath(final SearchPathRequest request){
return this.client.request(request);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.twtw.backend.global.client;

public interface PathClient<T, R>{

public String request(T request);
}

0 comments on commit 6ae7dc0

Please sign in to comment.