Skip to content

Commit

Permalink
Merge pull request #37 from SSUDevelog/feat/#33
Browse files Browse the repository at this point in the history
[FIX] url추가
  • Loading branch information
kikuke authored Nov 23, 2023
2 parents ed83031 + 795153e commit 16f1b03
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/easyvel/server/tag/TagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void deleteTag(String uid, String tagName) {
userTagRepository.delete(userTag);
}

// Todo: 이부분 로직의 변경과 사용하는 부분 수정이 필요합니다.
/**
* 해당 태그와 관련된 포스트를 크롤링해 PostDto를 만듭니다.
*
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/com/easyvel/server/velogapi/VelogClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
@RequiredArgsConstructor
public class VelogClient {

//Todo: pageable 적용하기
public List<PostDto> 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()
Expand All @@ -37,6 +36,42 @@ public List<PostDto> getTrendData(int limit, int offset) throws JsonMappingExcep
List<TrendData.Data.PostData> trendingPosts = response.getBody().getData().getTrendingPosts();
List<PostDto> 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<PostDto> 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<TrendData> response = webClient.post()
.uri("/graphql")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(query)
.retrieve()
.toEntity(TrendData.class)
.block();

List<TrendData.Data.PostData> trendingPosts = response.getBody().getData().getTrendingPosts();
List<PostDto> trendPostList = new ArrayList<>();

for (TrendData.Data.PostData p : trendingPosts) {
log.info("loop");
PostDto postDto = PostDto.builder()
Expand All @@ -47,8 +82,8 @@ public List<PostDto> 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);
Expand Down

0 comments on commit 16f1b03

Please sign in to comment.