From 795153e36237aefc3d6e86bb6df0f27d09a21539 Mon Sep 17 00:00:00 2001 From: kikuke Date: Tue, 14 Nov 2023 17:57:21 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20url=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/easyvel/server/tag/TagService.java | 1 + .../easyvel/server/velogapi/VelogClient.java | 41 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/easyvel/server/tag/TagService.java b/src/main/java/com/easyvel/server/tag/TagService.java index 8e5f15c..62bad46 100644 --- a/src/main/java/com/easyvel/server/tag/TagService.java +++ b/src/main/java/com/easyvel/server/tag/TagService.java @@ -70,6 +70,7 @@ public void deleteTag(String uid, String tagName) { userTagRepository.delete(userTag); } + // Todo: 이부분 로직의 변경과 사용하는 부분 수정이 필요합니다. /** * 해당 태그와 관련된 포스트를 크롤링해 PostDto를 만듭니다. * diff --git a/src/main/java/com/easyvel/server/velogapi/VelogClient.java b/src/main/java/com/easyvel/server/velogapi/VelogClient.java index 831ec63..8bd65a1 100644 --- a/src/main/java/com/easyvel/server/velogapi/VelogClient.java +++ b/src/main/java/com/easyvel/server/velogapi/VelogClient.java @@ -19,7 +19,6 @@ @RequiredArgsConstructor public class VelogClient { - //Todo: pageable 적용하기 public List getTrendData(int limit, int offset) throws JsonMappingException, JsonProcessingException { String query = "{\"query\":\"\\n query trendingPosts($input: TrendingPostsInput!) {\\n trendingPosts(input: $input) {\\n id\\n title\\n short_description\\n thumbnail\\n likes\\n user {\\n id\\n username\\n profile {\\n id\\n thumbnail\\n }\\n }\\n url_slug\\n released_at\\n updated_at\\n is_private\\n comments_count\\n }\\n}\\n \",\"variables\":{\"input\":{\"limit\":"+limit+",\"offset\":"+offset+",\"timeframe\":\"week\"}}}"; WebClient webClient = WebClient.builder() @@ -37,6 +36,42 @@ public List getTrendData(int limit, int offset) throws JsonMappingExcep List trendingPosts = response.getBody().getData().getTrendingPosts(); List trendPostList = new ArrayList<>(); + for (TrendData.Data.PostData p : trendingPosts) { + PostDto postDto = PostDto.builder() + .name(p.getUser().getUsername()) + .title(p.getTitle()) + .summary(p.getShort_description()) + .date(p.getReleased_at()) + .comment(p.getComments_count()) + .like(p.getLikes()) + .img(p.getThumbnail()) + .tag(null) // Comment: trend 게시물은 tag가 공백! + .url("velog.io/@"+p.getUser().getUsername()+"/"+p.url_slug) + .build(); + + trendPostList.add(postDto); + } + + return trendPostList; + } + + public List getTagData(int limit, int offset) throws JsonMappingException, JsonProcessingException { + String query = "{\"query\":\"\\n query trendingPosts($input: TrendingPostsInput!) {\\n trendingPosts(input: $input) {\\n id\\n title\\n short_description\\n thumbnail\\n likes\\n user {\\n id\\n username\\n profile {\\n id\\n thumbnail\\n }\\n }\\n url_slug\\n released_at\\n updated_at\\n is_private\\n comments_count\\n }\\n}\\n \",\"variables\":{\"input\":{\"limit\":"+limit+",\"offset\":"+offset+",\"timeframe\":\"week\"}}}"; + WebClient webClient = WebClient.builder() + .baseUrl("https://v3.velog.io") + .build(); + + ResponseEntity response = webClient.post() + .uri("/graphql") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(query) + .retrieve() + .toEntity(TrendData.class) + .block(); + + List trendingPosts = response.getBody().getData().getTrendingPosts(); + List trendPostList = new ArrayList<>(); + for (TrendData.Data.PostData p : trendingPosts) { log.info("loop"); PostDto postDto = PostDto.builder() @@ -47,8 +82,8 @@ public List getTrendData(int limit, int offset) throws JsonMappingExcep .comment(p.getComments_count()) .like(p.getLikes()) .img(p.getThumbnail()) - .tag(null) // Todo: 채워야 하는 데이터 - .url(null) // Todo: 채워야 하는 데이터 + .tag(null) // Comment: trend 게시물은 tag가 공백! + .url("velog.io/@"+p.getUser().getUsername()+"/"+p.url_slug) .build(); trendPostList.add(postDto);