-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
8 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com/khumu/community/application/dto/DetailedArticleDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.khumu.community.application.dto; | ||
|
||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class DetailedArticleDto { | ||
Integer id; | ||
String boardName; | ||
String boardDisplayName; | ||
// TODO: 익명의 경우 작성자를 숨기기 | ||
SimpleUserDto author; | ||
String title; | ||
String content; | ||
@Builder.Default | ||
List<String> images = new ArrayList<>(); | ||
|
||
@Builder.Default | ||
Long commentCount = 0L; | ||
|
||
@Builder.Default | ||
Boolean liked = false; | ||
@Builder.Default | ||
Long likeArticleCount = 0L; | ||
|
||
@Builder.Default | ||
Boolean bookmarked = false; | ||
@Builder.Default | ||
Long bookmarkArticleCount = 0L; | ||
|
||
String kind; | ||
Boolean isHot; | ||
|
||
// TODO: createdAt을 human readable한 text로 | ||
LocalDateTime createdAt; | ||
|
||
@Builder.Default | ||
Boolean isSubscribed = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/khumu/community/application/port/out/repository/AlimiRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.khumu.community.application.port.out.repository; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface AlimiRepository { | ||
Boolean isSubscribed(String username, String resourceKind, String resourceId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/com/khumu/community/infra/api/AlimiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.khumu.community.infra.api; | ||
|
||
import com.khumu.community.application.port.out.repository.AlimiRepository; | ||
import lombok.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.http.*; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
@Slf4j | ||
public class AlimiClient implements AlimiRepository { | ||
private final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter; | ||
|
||
@Value("${khumu.alimi.host}") | ||
private String alimiApiHost; | ||
|
||
@Override | ||
public Boolean isSubscribed(String username, String resourceKind, String resourceId) { | ||
RestTemplate restTemplate = new RestTemplateBuilder() | ||
.messageConverters(mappingJackson2HttpMessageConverter) | ||
.build(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); // send the post request | ||
HttpEntity<Object> entity = new HttpEntity<>(headers); | ||
ResponseEntity<AlimiClient.IsSubscribedHttpResponse> resp = restTemplate.exchange( | ||
String.format("%s/api/subscriptions/%s/%s/%s", alimiApiHost, username, resourceKind, resourceId), | ||
HttpMethod.GET, | ||
entity, | ||
AlimiClient.IsSubscribedHttpResponse.class | ||
); | ||
|
||
if (resp.getStatusCode() != HttpStatus.OK) { | ||
log.error("AlimiClient.isSubscribed 의 응답이 200이 아닙니다."); | ||
return false; | ||
} | ||
if (resp.getBody() == null) { | ||
log.error("AlimiClient.isSubscribed 의 응답 body가 null입니다."); | ||
return false; | ||
} | ||
|
||
log.info("AlimiClient.isSubscribed 의 응답: " + resp.getBody()); | ||
|
||
return resp.getBody().getData().getIsActivated(); | ||
} | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@ToString | ||
private static class IsSubscribedHttpResponse{ | ||
private IsSubscribedResponse data; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@ToString | ||
private static class IsSubscribedResponse{ | ||
private Long resourceId; | ||
private String resourceKind; | ||
private String subscriber; | ||
private Boolean isActivated; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters