Skip to content

Commit

Permalink
Merge pull request #5 from Oh-Lottery/crawler
Browse files Browse the repository at this point in the history
크롤러 업데이트 및 Swagger 적용
  • Loading branch information
SalkCoding authored Dec 16, 2024
2 parents cae4460 + 280ab0a commit 0d47b2a
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 173 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

/src/main/resources/application.yml

### STS ###
.apt_generated
.classpath
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.session:spring-session-data-redis'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'

implementation 'com.google.code.gson:gson:2.11.0'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/ohlottery/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ohlottery.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig {
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(50);
executor.setThreadNamePrefix("AsyncExecutor-");
executor.initialize();
return executor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public ResponseEntity<?> getLotteryNumber(
Lottery720Dto resultDto = new Lottery720Dto(
resultEntity.getRound(),
resultEntity.getDrawDate(),
resultEntity.getRankWinNum(),
resultEntity.getRankClass(),
resultEntity.getRankNo()
resultEntity.getRankNo(),
resultEntity.getBonusNo()
);
return ResponseEntity.ok(resultDto);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
package com.ohlottery.controller;

import com.ohlottery.service.DHLotteryCrawlerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

//Authentication 과정 필수로 필요

@RestController
@RequestMapping("/crawler")
@RequiredArgsConstructor
@Tag(name = "Lottery Crawler Controller", description = "당첨 정보 수동 크롤링")
public class LotteryCrawlerController {

private final DHLotteryCrawlerService lotteryCrawlerService;

@PatchMapping("/lottery645/{round}")
public ResponseEntity<Void> fetchLottery645(@PathVariable long round) {
@Operation(summary = "6/45로또 데이터 업데이트", description = "해당 회차 6/45 당첨 정보를 데이터베이스에 저장")
@GetMapping("/lottery645/{round}")
public ResponseEntity<Void> fetchLottery645(
@Parameter(description = "회차", example = "1")
@PathVariable long round
) {
lotteryCrawlerService.fetchLottery645Data(round);
return ResponseEntity.ok().build();
}

@PatchMapping("/lottery720/{round}")
public ResponseEntity<Void> fetchLottery720(@PathVariable long round) {
@Operation(summary = "연금복권 데이터 업데이트", description = "해당 회차 6/45 당첨 정보를 데이터베이스에 저장")
@GetMapping("/lottery720/{round}")
public ResponseEntity<Void> fetchLottery720(
@Parameter(description = "회차", example = "1")
@PathVariable long round
) {
lotteryCrawlerService.fetchLottery720Data(round);
return ResponseEntity.ok().build();
}

@Operation(summary = "모든 로또 데이터 업데이트", description = "1~n 회차까지 전부 데이터베이스에 저장")
@GetMapping("/lottery/fetch")
public ResponseEntity<Void> fetchAllData() {
lotteryCrawlerService.fetchAllLotteryData();
return ResponseEntity.ok().build();
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/ohlottery/dto/Lottery720Dto.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class Lottery720Dto {
@Schema(description = "추첨 날짜", example = "2024-12-05")
private LocalDate drawDate;

@Schema(description = "등수", example = "1")
private int rankWinNum;

@Schema(description = "당첨 조 번호", example = "4")
private int rankClass;

@Schema(description = "당첨 번호", example = "446648")
private int rankNo;

@Schema(description = "당첨 번호", example = "761555")
private int bonusNo;
}
2 changes: 1 addition & 1 deletion src/main/java/com/ohlottery/entity/Lottery720Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Lottery720Entity {

private LocalDate drawDate;// 추첨 날짜

private byte rankWinNum;// 등수
private byte rankClass;// 조 번호
private int rankNo;// 당첨 번호
private int bonusNo;// 보너스 번호
}
Loading

0 comments on commit 0d47b2a

Please sign in to comment.