Skip to content

Commit

Permalink
feat: 새로고침 기능 구현 및 파라미터 추가 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjd4204 committed Jan 9, 2024
1 parent 62d0402 commit 4e04f79
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
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

0 comments on commit 4e04f79

Please sign in to comment.