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

feat 해답 블로그 새로고침 기능 구현 #35

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public class SearchController {

@GetMapping
public SuccessResponse<GoogleListResponseDto> getList(@RequestParam String query){
GoogleListResponseDto response = searchService.findBlog(query);
GoogleListResponseDto response = searchService.findBlog(query, 1);
return new SuccessResponse<>(response);
}

@GetMapping("/refresh")
public SuccessResponse<GoogleListResponseDto> getRefresh(@RequestParam String query, @RequestParam(value = "start") int index){
GoogleListResponseDto response = searchService.findBlog(query, index);
return new SuccessResponse<>(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.api.TaveShot.domain.search.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Slf4j
public class GoogleQueryDto {

@JsonProperty(value = "request")
private List<GoogleRequestDto> requests;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.api.TaveShot.domain.search.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Slf4j
public class GoogleRequestDto {

@JsonProperty(value = "totalResults")
private String totalResults;

@JsonProperty(value = "startIndex")
private Integer startIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
@NoArgsConstructor
public class GoogleResponseDto {

@JsonProperty(value = "queries")
private GoogleQueryDto queries;

@JsonProperty(value = "items")
private List<GoogleItemDto> items;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SearchService {
private String CX;


public GoogleListResponseDto findBlog(String query) {
public GoogleListResponseDto findBlog(String query, int index) {
WebClient webClient = WebClient.builder()
.baseUrl("https://www.googleapis.com/customsearch/v1")
.build();
Expand All @@ -41,6 +41,7 @@ public GoogleListResponseDto findBlog(String query) {
.queryParam("key", KEY)
.queryParam("cx", CX)
.queryParam("q", query)
.queryParam("start", index)
.build())
.accept(MediaType.APPLICATION_JSON)
.retrieve()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.cors(corsCustomizer -> corsCustomizer.configurationSource(request -> {
CorsConfiguration cors = new CorsConfiguration();
cors.setAllowedOrigins(List.of("*", "http://localhost:3000", "http://localhost:8080"));
cors.setAllowedMethods(List.of("GET", "POST", "PATCH", "DELETE"));
cors.setAllowedMethods(List.of("GET", "POST", "PATCH", "DELETE", "OPTIONS"));
// cookie 비활성화
cors.setAllowCredentials(false);
// Authorization Header 노출
Expand Down