complete task INDX-0001. sites list output to stdout

This commit is contained in:
Eduard Kuksa 2025-03-02 21:40:25 +07:00
parent 443ea20d55
commit 1209b34ceb
3 changed files with 18 additions and 4 deletions

View File

@ -4,8 +4,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import searchengine.config.SitesList;
import searchengine.dto.statistics.StatisticsResponse; import searchengine.dto.statistics.StatisticsResponse;
import searchengine.services.IndexingService;
import searchengine.services.StatisticsService; import searchengine.services.StatisticsService;
@RestController @RestController
@ -13,9 +13,11 @@ import searchengine.services.StatisticsService;
public class ApiController { public class ApiController {
private final StatisticsService statisticsService; private final StatisticsService statisticsService;
private final IndexingService indexingService;
public ApiController(StatisticsService statisticsService) { public ApiController(StatisticsService statisticsService, IndexingService indexingService) {
this.statisticsService = statisticsService; this.statisticsService = statisticsService;
this.indexingService = indexingService;
} }
@GetMapping("/statistics") @GetMapping("/statistics")
@ -25,7 +27,7 @@ public class ApiController {
@GetMapping("/startIndexing") @GetMapping("/startIndexing")
public ResponseEntity<StatisticsResponse> startIndexing() { public ResponseEntity<StatisticsResponse> startIndexing() {
System.out.println(new SitesList().getSites()); indexingService.startIndexing();
return ResponseEntity.ok(statisticsService.getStatistics()); return ResponseEntity.ok(statisticsService.getStatistics());
} }
} }

View File

@ -1,4 +1,5 @@
package searchengine.services; package searchengine.services;
public interface IndexingService { public interface IndexingService {
void startIndexing();
} }

View File

@ -1,14 +1,25 @@
package searchengine.services; package searchengine.services;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import searchengine.config.SitesList;
@Service
@RequiredArgsConstructor
public class IndexingServiceImpl implements IndexingService { public class IndexingServiceImpl implements IndexingService {
boolean indexingIsRunning = false; boolean indexingIsRunning = false;
private final SitesList sitesList;
@Override
public void startIndexing() { public void startIndexing() {
if (indexingIsRunning) { if (indexingIsRunning) {
System.out.println("Индексация уже запущена"); System.out.println("Индексация уже запущена");
return; return;
} }
// Логика для запуска индексации или перенидексации сайтов
System.out.println("Список сайтов для индексации:");
sitesList.getSites().forEach(site -> System.out.println("URL: " + site.getUrl() + ", Название: " + site.getName()));
System.out.println("Запуск индексации"); System.out.println("Запуск индексации");
indexingIsRunning = true; indexingIsRunning = true;
System.out.println("Индексация запущена"); System.out.println("Индексация запущена");