Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] RSS 기능 구현 #22

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions backend/build.gradle
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'kernel360'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
// spring boot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.mysql:mysql-connector-j'
// spring boot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.2'

// lombok annotation
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'

// Sql logging formatter
// reference: https://www.baeldung.com/java-p6spy-intercept-sql-logging
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.2' //이쁘게
// lombok annotation
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// logback logger
implementation 'ch.qos.logback:logback-classic:1.4.12'
implementation 'org.slf4j:slf4j-api:2.0.3'
// Sql logging formatter
// reference: https://www.baeldung.com/java-p6spy-intercept-sql-logging
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.2' //이쁘게

// test environment
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// logback logger
implementation 'ch.qos.logback:logback-classic:1.4.12'
implementation 'org.slf4j:slf4j-api:2.0.3'

// springdoc swagger dependency
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
// test environment
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// springdoc swagger dependency
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'

}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kernel360.techpick.config;

import java.time.Duration;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder
.additionalMessageConverters(new MappingJackson2XmlHttpMessageConverter())
.defaultHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
.setConnectTimeout(Duration.ofSeconds(5))
.setReadTimeout(Duration.ofSeconds(5))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public class Article extends CreatedAndUpdatedTimeColumn {
@JoinColumn(name = "blog_id", nullable = false)
private Blog blog;

// 수집 날짜 (크롤링 시각)
@Column(name = "crawled_at", nullable = false)
private LocalDateTime crawled_at;

// 대표 이미지 CDN url
@Column(name = "image_url")
private String imageUrl; // nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package kernel360.techpick.entity.article;

import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import kernel360.techpick.entity.common.CreatedAndUpdatedTimeColumn;
import lombok.AccessLevel;
Expand All @@ -19,7 +22,6 @@
@Table(name = "raw_crawled_article")
@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RawCrawledArticle extends CreatedAndUpdatedTimeColumn {

Expand All @@ -28,8 +30,27 @@ public class RawCrawledArticle extends CreatedAndUpdatedTimeColumn {
@Column(name = "raw_crawled_article_id")
private Long rawCrawledArticleId;

// TODO: 아래 크롤링 데이터 칼럼은 토의 후 바뀔 예정 입니다.
// 크롤링 데이터
@Column(name = "data", nullable = false)
private String data;
// TODO: 변수명은 변경 될 수 있습니다.
@Column(name = "title")
private String title;

@Column(name = "link", columnDefinition = "LONGBLOB")
Gyaak marked this conversation as resolved.
Show resolved Hide resolved
private String link;

@Column(name = "pubDate")
private String pubDate;

@Column(name = "creator")
private String creator;

@Column(name = "joinedCategories")
private String joinedCategories;

public RawCrawledArticle(String title, String link, String pubDate, String creator, String joinedCategories) {
this.title = title;
this.link = link;
this.pubDate = pubDate;
this.creator = creator;
this.joinedCategories = joinedCategories;
}
}
sangwonsheep marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package kernel360.techpick.rss.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import kernel360.techpick.rss.dto.RssResponse;
import kernel360.techpick.rss.service.RssService;
import lombok.RequiredArgsConstructor;

/**
* RSS 테스트용 컨트롤러
*/
@RestController
@RequestMapping("/rss")
@RequiredArgsConstructor
public class RssController {

private final RssService rssService;

@GetMapping
public ResponseEntity<?> getNewRss() {
sangwonsheep marked this conversation as resolved.
Show resolved Hide resolved
List<RssResponse.Channel> rss = rssService.getNewRss();
return ResponseEntity.ok(rss);
}

@GetMapping("/baeldung")
public ResponseEntity<?> getBaeldung() {
RssResponse.Channel rss = rssService.getRssByBaeldung();
return ResponseEntity.ok(rss);
}

@GetMapping("/toss")
public ResponseEntity<?> getToss() {
RssResponse.Channel rss = rssService.getRssByToss();
return ResponseEntity.ok(rss);
}

@GetMapping("/woowa")
public ResponseEntity<?> getWoowa() {
RssResponse.Channel rss = rssService.getRssByWoowa();
return ResponseEntity.ok(rss);
}

@GetMapping("/kakao")
public ResponseEntity<?> getKakao() {
RssResponse.Channel rss = rssService.getRssByKakao();
return ResponseEntity.ok(rss);
}

@GetMapping("/daangn")
public ResponseEntity<?> getDaangn() {
RssResponse.Channel rss = rssService.getRssByDaangn();
return ResponseEntity.ok(rss);
}

@GetMapping("/line")
public ResponseEntity<?> getLine() {
RssResponse.Channel rss = rssService.getRssByLine();
return ResponseEntity.ok(rss);
}

}
43 changes: 43 additions & 0 deletions backend/src/main/java/kernel360/techpick/rss/dto/RssResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package kernel360.techpick.rss.dto;

import java.util.List;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import lombok.Getter;

@Getter
public class RssResponse {

@JacksonXmlProperty(localName = "channel")
private Channel channel;

@Getter
public static class Channel {

@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "item")
private List<Item> item;
}
Gyaak marked this conversation as resolved.
Show resolved Hide resolved

@Getter
public static class Item {

@JacksonXmlProperty(localName = "title")
private String title;

@JacksonXmlProperty(localName = "link")
private String link;

@JacksonXmlProperty(localName = "pubDate")
private String pubDate;

@JacksonXmlProperty(localName = "creator")
private String creator;

@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "category")
private List<String> category;
}
}
22 changes: 22 additions & 0 deletions backend/src/main/java/kernel360/techpick/rss/dto/Url.java
Gyaak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kernel360.techpick.rss.dto;

import lombok.Getter;

@Getter
public enum Url {

// TODO: Blog Entity에 rssUrl로 넣어야 함.
BAELDUNG_URL("https://www.baeldung.com/feed"),
sangwonsheep marked this conversation as resolved.
Show resolved Hide resolved
TOSS_URL("https://toss.tech/rss.xml"),
WOOWA_URL("https://techblog.woowahan.com/feed/"),
KAKAO_URL("https://tech.kakao.com/posts/feed"),
DAANGN_URL("https://medium.com/feed/daangn"),
LINE_URL("https://techblog.lycorp.co.jp/ko/feed/index.xml");

private final String url;

Url(String url) {
this.url = url;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kernel360.techpick.rss.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import kernel360.techpick.entity.article.RawCrawledArticle;

/**
* 파이썬 서버 구현 시 삭제 예정
*/
public interface RssRepository extends JpaRepository<RawCrawledArticle, Long> {
sangwonsheep marked this conversation as resolved.
Show resolved Hide resolved

@Query("SELECT r.link FROM RawCrawledArticle r")
List<String> findAllLinks();
}
Loading
Loading