67 lines
2.1 KiB
Java
67 lines
2.1 KiB
Java
package com.myoa.engineering.crawl.ppomppu.processor.dto;
|
|
|
|
import java.time.Instant;
|
|
|
|
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
|
import com.myoa.engineering.crawl.ppomppu.support.util.DateUtil;
|
|
|
|
import lombok.Builder;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
|
|
/**
|
|
* PpomppuArticleParseDTO
|
|
*
|
|
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
|
* @since 2021-09-08
|
|
*/
|
|
@Getter
|
|
@NoArgsConstructor
|
|
public class PpomppuArticleParseDTO {
|
|
|
|
private String id;
|
|
private String articleId;
|
|
private String boardName;
|
|
private String articleUrl;
|
|
private String thumbnailUrl;
|
|
private String title;
|
|
private String hit;
|
|
private Integer recommended;
|
|
private String registeredAt;
|
|
|
|
@Builder
|
|
public PpomppuArticleParseDTO(String id, String articleId, String boardName, String articleUrl,
|
|
String thumbnailUrl, String title, String hit, Integer recommended,
|
|
String registeredAt) {
|
|
this.id = id;
|
|
this.articleId = articleId;
|
|
this.boardName = boardName;
|
|
this.articleUrl = articleUrl;
|
|
this.thumbnailUrl = thumbnailUrl;
|
|
this.title = title;
|
|
this.hit = hit;
|
|
this.recommended = recommended;
|
|
this.registeredAt = registeredAt;
|
|
}
|
|
|
|
public boolean isInValidated() {
|
|
return articleId == null || articleId.isEmpty()
|
|
|| hit == null || hit.isEmpty();
|
|
}
|
|
|
|
public PpomppuArticle convert() {
|
|
if (isInValidated()) {
|
|
throw new IllegalArgumentException("PpomppuArticleParseDTO was invalidated");
|
|
}
|
|
return PpomppuArticle.builder()
|
|
.articleId(Long.parseLong(articleId))
|
|
.title(title)
|
|
.articleUrl(articleUrl)
|
|
.thumbnailUrl(thumbnailUrl)
|
|
.recommended(recommended)
|
|
.hit(Integer.parseInt(hit))
|
|
.registeredAt(DateUtil.DATE_TIME_FORMATTER.parse(registeredAt, Instant::from))
|
|
.build();
|
|
}
|
|
}
|